test(sync): add unit tests for gitHasUncommittedBeadsChanges (bd-p7i2)
Extract parseGitStatusForBeadsChanges helper function from gitHasUncommittedBeadsChanges to enable unit testing without git setup. Add 14 test cases covering: - Empty/no changes - Modified files (staged, unstaged, both) - Added files (staged, with modifications) - Untracked files (should return false) - Deleted files (should return false) - Renamed/copied files - Edge cases (short status line) Part of GH#885 follow-up. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -466,12 +466,18 @@ func gitHasUncommittedBeadsChanges(ctx context.Context) (bool, error) {
|
||||
return false, fmt.Errorf("git status failed: %w", err)
|
||||
}
|
||||
|
||||
// Parse status output - look for modified/added files
|
||||
// Format: XY filename where X=staged, Y=unstaged
|
||||
// M = modified, A = added, ? = untracked
|
||||
statusLine := strings.TrimSpace(string(output))
|
||||
return parseGitStatusForBeadsChanges(string(output)), nil
|
||||
}
|
||||
|
||||
// parseGitStatusForBeadsChanges parses git status --porcelain output and returns
|
||||
// true if the status indicates uncommitted changes (modified or added).
|
||||
// Format: XY filename where X=staged, Y=unstaged
|
||||
// M = modified, A = added, ? = untracked, D = deleted
|
||||
// Only M and A in either position indicate changes we care about.
|
||||
func parseGitStatusForBeadsChanges(statusOutput string) bool {
|
||||
statusLine := strings.TrimSpace(statusOutput)
|
||||
if statusLine == "" {
|
||||
return false, nil // No changes
|
||||
return false // No changes
|
||||
}
|
||||
|
||||
// Any status (M, A, MM, AM, etc.) indicates uncommitted changes
|
||||
@@ -479,11 +485,11 @@ func gitHasUncommittedBeadsChanges(ctx context.Context) (bool, error) {
|
||||
x, y := statusLine[0], statusLine[1]
|
||||
// Check for modifications (staged or unstaged)
|
||||
if x == 'M' || x == 'A' || y == 'M' || y == 'A' {
|
||||
return true, nil
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false, nil
|
||||
return false
|
||||
}
|
||||
|
||||
// getDefaultBranch returns the default branch name (main or master) for origin remote
|
||||
|
||||
Reference in New Issue
Block a user