Commit 57fea768f13d
Changed files (1)
tools
claude-hooks
cmd
validate-git-push
tools/claude-hooks/cmd/validate-git-push/main.go
@@ -27,9 +27,15 @@ func hasExplicitRefspec(command string) bool {
return refspecPattern.MatchString(command)
}
-// Check if this is a git push command
+// Check if this is a git push command (not just the string "git push" inside arguments)
func isGitPush(command string) bool {
- return strings.Contains(command, "git push") || strings.Contains(command, "git push")
+ // Match git push only when it appears as an actual command:
+ // - At the start of the command
+ // - After command separators: && || ; |
+ // - After $( for command substitution
+ // This avoids false positives on "git push" inside heredocs, strings, or commit messages
+ gitPushPattern := regexp.MustCompile(`(^|&&|\|\||;|\||\$\()\s*git\s+push(\s|$)`)
+ return gitPushPattern.MatchString(command)
}
// Check if pushing to a protected branch without explicit refspec