fix(doctor): recognize lowercase 's' skip-worktree flag (#931)

* fix(doctor): handle 's' status in combined git flags

Problem:
- Git status detection failed when 's' was combined with other flags
- Branch synchronization checks produced incorrect results due to missing flag parsing

Solution:
- Update detection logic to correctly identify the 's' status within combined flag strings

Impact:
- Ensures branch synchronization state is accurately reported during doctor checks

* test(doctor): add unit tests for git flag parsing

- Extract git flag parsing logic into parseGitLsFilesFlag helper
- Add unit tests for git flag parsing logic

Coverage: Git flag parsing in sync_branch.go
This commit is contained in:
Peter Chanthamynavong
2026-01-06 19:22:51 -08:00
committed by GitHub
parent 65f484d809
commit 12858f5146
2 changed files with 65 additions and 7 deletions

View File

@@ -0,0 +1,46 @@
package fix
import "testing"
func TestParseGitLsFilesFlag(t *testing.T) {
tests := map[string]struct {
flag byte
wantHasAnyFlag bool
wantHasSkipWorktree bool
}{
"normal tracked file (H)": {
flag: 'H',
wantHasAnyFlag: false,
wantHasSkipWorktree: false,
},
"assume-unchanged only (h)": {
flag: 'h',
wantHasAnyFlag: true,
wantHasSkipWorktree: false,
},
"skip-worktree only (S)": {
flag: 'S',
wantHasAnyFlag: true,
wantHasSkipWorktree: true,
},
"both flags set (s)": {
flag: 's',
wantHasAnyFlag: true,
wantHasSkipWorktree: true,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
gotHasAnyFlag, gotHasSkipWorktree := parseGitLsFilesFlag(tt.flag)
if gotHasAnyFlag != tt.wantHasAnyFlag {
t.Errorf("hasAnyFlag = %v, want %v", gotHasAnyFlag, tt.wantHasAnyFlag)
}
if gotHasSkipWorktree != tt.wantHasSkipWorktree {
t.Errorf("hasSkipWorktree = %v, want %v", gotHasSkipWorktree, tt.wantHasSkipWorktree)
}
})
}
}