Skip to content

Commit c13f626

Browse files
committed
bug: fix the wrong different view for first commit
After check, I think ``git.GetDiffShortStat`` is not necessary to be called, because it hase maken right message in ``ParsePatch``. and ``git.GetDiffShortStat`` can't get right message if beforeCommitID is empty, which is the reason for #11650 fix #11650 Signed-off-by: a1012112796 <[email protected]>
1 parent ab73b56 commit c13f626

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

services/gitdiff/gitdiff.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ func GetDiffRange(repoPath, beforeCommitID, afterCommitID string, maxLines, maxL
646646
}
647647

648648
// GetDiffRangeWithWhitespaceBehavior builds a Diff between two commits of a repository.
649+
// if beforeCommitID is empty, get afterCommit diff by 'git show afterCommitID'
649650
// Passing the empty string as beforeCommitID returns a diff from the parent commit.
650651
// The whitespaceBehavior is either an empty string or a git flag
651652
func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID string, maxLines, maxLineCharacters, maxFiles int, whitespaceBehavior string) (*Diff, error) {
@@ -664,7 +665,7 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID
664665
ctx, cancel := context.WithCancel(git.DefaultContext)
665666
defer cancel()
666667
var cmd *exec.Cmd
667-
if len(beforeCommitID) == 0 && commit.ParentCount() == 0 {
668+
if (beforeCommitID == "" || beforeCommitID == git.EmptySHA) && commit.ParentCount() == 0 {
668669
cmd = exec.CommandContext(ctx, git.GitExecutable, "show", afterCommitID)
669670
} else {
670671
actualBeforeCommitID := beforeCommitID
@@ -711,11 +712,6 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID
711712
return nil, fmt.Errorf("Wait: %v", err)
712713
}
713714

714-
diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStat(repoPath, beforeCommitID+"..."+afterCommitID)
715-
if err != nil {
716-
return nil, err
717-
}
718-
719715
return diff, nil
720716
}
721717

0 commit comments

Comments
 (0)