repos / git-pr

a self-hosted git collaboration server
git clone https://github.com/picosh/git-pr.git

commit
8460ee0
parent
e65031f
author
Eric Bower
date
2024-07-14 06:44:20 -0400 EDT
fix: for content sha ignore diff file with base-commit

Our content sha computation is wrong when one contrib provides a
base-commit and the other does not.

Unfortunately this is dependent on the client and whether or not they
provide the base commit `git format-patch --base` so we have to hack
around it to keep commit sha identical.
1 files changed,  +18, -2
M util.go
+18, -2
 1@@ -17,6 +17,7 @@ import (
 2 	"github.com/charmbracelet/ssh"
 3 )
 4 
 5+var baseCommitRe = regexp.MustCompile(`base-commit: (.+)\s*`)
 6 var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
 7 var startOfPatch = "From "
 8 
 9@@ -118,8 +119,7 @@ func splitPatchSet(patchset string) []string {
10 }
11 
12 func findBaseCommit(patch string) string {
13-	re := regexp.MustCompile(`base-commit: (.+)\s*`)
14-	strs := re.FindStringSubmatch(patch)
15+	strs := baseCommitRe.FindStringSubmatch(patch)
16 	baseCommit := ""
17 	if len(strs) > 1 {
18 		baseCommit = strs[1]
19@@ -202,6 +202,22 @@ func calcContentSha(diffFiles []*gitdiff.File, header *gitdiff.PatchHeader) stri
20 		header.AuthorDate,
21 	)
22 	for _, diff := range diffFiles {
23+		// we need to ignore diffs with base commit because that depends
24+		// on the client that is exporting the patch
25+		foundBase := false
26+		for _, text := range diff.TextFragments {
27+			for _, line := range text.Lines {
28+				base := findBaseCommit(line.Line)
29+				if base != "" {
30+					foundBase = true
31+				}
32+			}
33+		}
34+
35+		if foundBase {
36+			continue
37+		}
38+
39 		dff := fmt.Sprintf(
40 			"%s->%s %s..%s %s->%s\n",
41 			diff.OldName, diff.NewName,