fix(status): detect and report uncommitted changes in repository status, fixes #5

This commit is contained in:
Yar Kravtsov
2025-05-25 07:35:16 +03:00
parent d02f112200
commit 84c507828d
5 changed files with 157 additions and 29 deletions

View File

@@ -305,6 +305,7 @@ type StatusInfo struct {
Ahead int
Behind int
Remote string
Dirty bool
}
// GetStatus returns the repository status relative to remote
@@ -315,6 +316,12 @@ func (g *Git) GetStatus() (*StatusInfo, error) {
return nil, err
}
// Check for uncommitted changes
dirty, err := g.HasChanges()
if err != nil {
return nil, fmt.Errorf("failed to check for uncommitted changes: %w", err)
}
// Get the remote tracking branch
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}")
cmd.Dir = g.repoPath
@@ -327,6 +334,7 @@ func (g *Git) GetStatus() (*StatusInfo, error) {
Ahead: g.getAheadCount(remoteBranch),
Behind: 0, // Can't be behind if no upstream
Remote: remoteBranch,
Dirty: dirty,
}, nil
}
@@ -336,6 +344,7 @@ func (g *Git) GetStatus() (*StatusInfo, error) {
Ahead: g.getAheadCount(remoteBranch),
Behind: g.getBehindCount(remoteBranch),
Remote: remoteBranch,
Dirty: dirty,
}, nil
}