+17
-1
knotserver/git/merge.go
+17
-1
knotserver/git/merge.go
···
10
11
"github.com/go-git/go-git/v5"
12
"github.com/go-git/go-git/v5/plumbing"
13
)
14
15
type ErrMerge struct {
···
85
func (g *GitRepo) applyPatch(tmpDir, patchFile string, checkOnly bool, opts *MergeOptions) error {
86
var stderr bytes.Buffer
87
var cmd *exec.Cmd
88
89
if checkOnly {
90
cmd = exec.Command("git", "-C", tmpDir, "apply", "--check", "-v", patchFile)
91
} else {
92
-
exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run()
93
94
if opts != nil {
95
applyCmd := exec.Command("git", "-C", tmpDir, "apply", patchFile)
96
applyCmd.Stderr = &stderr
···
10
11
"github.com/go-git/go-git/v5"
12
"github.com/go-git/go-git/v5/plumbing"
13
+
"tangled.sh/tangled.sh/core/patchutil"
14
)
15
16
type ErrMerge struct {
···
86
func (g *GitRepo) applyPatch(tmpDir, patchFile string, checkOnly bool, opts *MergeOptions) error {
87
var stderr bytes.Buffer
88
var cmd *exec.Cmd
89
+
var formatPatch = false
90
+
91
+
if patchutil.IsFormatPatch(patchFile) {
92
+
formatPatch = true
93
+
}
94
95
if checkOnly {
96
cmd = exec.Command("git", "-C", tmpDir, "apply", "--check", "-v", patchFile)
97
} else {
98
+
// if patch is a format-patch, apply using 'git am'
99
+
if formatPatch {
100
+
amCmd := exec.Command("git", "-C", tmpDir, "am", patchFile)
101
+
amCmd.Stderr = &stderr
102
+
if err := amCmd.Run(); err != nil {
103
+
return fmt.Errorf("patch application failed: %s", stderr.String())
104
+
}
105
+
return nil
106
+
}
107
108
+
// else, apply using 'git apply' and commit it manually
109
+
exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run()
110
if opts != nil {
111
applyCmd := exec.Command("git", "-C", tmpDir, "apply", patchFile)
112
applyCmd.Stderr = &stderr