aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-05-29 22:14:00 +0100
committerGitHub <noreply@github.com>2020-05-29 22:14:00 +0100
commit6e4480835f7688a089f6c018f97333138f64bd87 (patch)
tree57f1bd6d63b355c047558b480c34999c0ce3f53b /services
parent141d52cc0f356776bd6fa538dbda276c3ba44118 (diff)
downloadgitea-6e4480835f7688a089f6c018f97333138f64bd87.tar.gz
gitea-6e4480835f7688a089f6c018f97333138f64bd87.zip
Fix issue with DiffIndex on initial commit (#11677)
Unfortunately #11614 introduced a bug whereby the initial commit of a repository could not be seen due to there being no parent commit to create a clear diff from. Here we create a diffstat from the difference between the parentless SHA and the SHA of the empty tree - a constant known to git. (With thanks to @L0veSunshine for informing me of this SHA) Thanks to @a1012112796 for initial attempt to fix. Fix #11650 Closes #11674 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-Authored-By: L0veSunshine <xuan199651@gmail.com>
Diffstat (limited to 'services')
-rw-r--r--services/gitdiff/gitdiff.go8
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
}