History

Git 2.28 no longer permits diff with ... on unrelated branches (#12364)

* Git 2.28 no longer permits diff with ... on unrelated branches Signed-off-by: Andrew Thornton <art27@cantab.net> * need to check stderr

zeripath committed 6 years ago

Commit 2f6aadf1 parent f2a6cd65 files · +68 −12Browse files

Showing the changes to services/gitdiff/gitdiff.go (1 of 5 files). Show all

Unified · Split

services/gitdiff/gitdiff.go+6−0
@@ -752,6 +752,12 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID · 751 unmodified lines
752752 shortstatArgs = []string{git.EmptyTreeSHA, afterCommitID}
753753 }
754754 diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStat(repoPath, shortstatArgs...)
755+ if err != nil && strings.Contains(err.Error(), "no merge base") {
756+ // git >= 2.28 now returns an error if base and head have become unrelated.
757+ // previously it would return the results of git diff --shortstat base head so let's try that...
758+ shortstatArgs = []string{beforeCommitID, afterCommitID}
759+ diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStat(repoPath, shortstatArgs...)
760+ }
755761 if err != nil {
756762 return nil, err
757763 }