Skip to content

Commit cf74e99

Browse files
committed
feat: Enhanced Git Diff Functionality
⚡ Updated the getGitDiff() function in util.go to run 'git diff --staged' if no diff is detected from the 'git diff' command, thus taking into account both unstaged and staged changes. The code changes trim excessive white spaces from the output. These changes now allow better diff prints by including staged diffs in the output.
1 parent 1704273 commit cf74e99

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

util.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ const MaxDiffLength = 30000 // set to 30k since large model has maximum context
2020
func getGitDiff() (string, error) {
2121
cmd := exec.Command("git", "diff")
2222
output, err := cmd.Output()
23-
if err != nil {
24-
return "", fmt.Errorf("error running git diff: %v", err)
25-
}
26-
diff := string(output)
23+
diff := strings.TrimSpace(string(output))
24+
if diff == "" {
25+
cmd = exec.Command("git", "diff", "--staged")
26+
output, err = cmd.Output()
27+
if err != nil {
28+
return "", err
29+
}
30+
diff = strings.TrimSpace(string(output))
31+
}
2732
runes := []rune(diff)
2833
size := len(runes)
2934
if size > MaxDiffLength {

0 commit comments

Comments
 (0)