diff options
Diffstat (limited to 'services')
-rw-r--r-- | services/gitdiff/gitdiff.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index af88ed4d40..02aef70882 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -664,7 +664,7 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID ctx, cancel := context.WithCancel(git.DefaultContext) defer cancel() var cmd *exec.Cmd - if len(beforeCommitID) == 0 && commit.ParentCount() == 0 { + if (len(beforeCommitID) == 0 || beforeCommitID == git.EmptySHA) && commit.ParentCount() == 0 { cmd = exec.CommandContext(ctx, git.GitExecutable, "show", afterCommitID) } else { actualBeforeCommitID := beforeCommitID @@ -711,7 +711,11 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID return nil, fmt.Errorf("Wait: %v", err) } - diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStat(repoPath, beforeCommitID+"..."+afterCommitID) + shortstatArgs := []string{beforeCommitID + "..." + afterCommitID} + if len(beforeCommitID) == 0 || beforeCommitID == git.EmptySHA { + shortstatArgs = []string{git.EmptyTreeSHA, afterCommitID} + } + diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStat(repoPath, shortstatArgs...) if err != nil { return nil, err } |