Improve git operations: use --ff-only for pull, make commit idempotent

This commit is contained in:
Steve Yegge
2025-11-01 23:00:25 -07:00
parent 2615c72fc9
commit 88fd7b2bc2
2 changed files with 11 additions and 25 deletions

View File

@@ -89,6 +89,10 @@ func gitCommit(ctx context.Context, filePath string, message string) error {
commitCmd := exec.CommandContext(ctx, "git", "commit", "-m", message)
output, err := commitCmd.CombinedOutput()
if err != nil {
// Treat "nothing to commit" as success (idempotent)
if strings.Contains(strings.ToLower(string(output)), "nothing to commit") {
return nil
}
return fmt.Errorf("git commit failed: %w\n%s", err, output)
}
@@ -97,25 +101,7 @@ func gitCommit(ctx context.Context, filePath string, message string) error {
// gitPull pulls from the current branch's upstream
func gitPull(ctx context.Context) error {
// Get current branch name
branchCmd := exec.CommandContext(ctx, "git", "rev-parse", "--abbrev-ref", "HEAD")
branchOutput, err := branchCmd.Output()
if err != nil {
return fmt.Errorf("failed to get current branch: %w", err)
}
branch := strings.TrimSpace(string(branchOutput))
// Get remote name for current branch (usually "origin")
remoteCmd := exec.CommandContext(ctx, "git", "config", "--get", fmt.Sprintf("branch.%s.remote", branch))
remoteOutput, err := remoteCmd.Output()
if err != nil {
// If no remote configured, default to "origin"
remoteOutput = []byte("origin\n")
}
remote := strings.TrimSpace(string(remoteOutput))
// Pull with explicit remote and branch
cmd := exec.CommandContext(ctx, "git", "pull", remote, branch)
cmd := exec.CommandContext(ctx, "git", "pull", "--ff-only")
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("git pull failed: %w\n%s", err, output)