+6
-7
knotserver/git/merge.go
+6
-7
knotserver/git/merge.go
···
31
31
CommitBody string
32
32
AuthorName string
33
33
AuthorEmail string
34
+
FormatPatch bool
34
35
}
35
36
36
37
func (e ErrMerge) Error() string {
···
86
87
func (g *GitRepo) applyPatch(tmpDir, patchFile string, checkOnly bool, opts *MergeOptions) error {
87
88
var stderr bytes.Buffer
88
89
var cmd *exec.Cmd
89
-
var formatPatch = false
90
-
91
-
if patchutil.IsFormatPatch(patchFile) {
92
-
formatPatch = true
93
-
}
94
90
95
91
if checkOnly {
96
92
cmd = exec.Command("git", "-C", tmpDir, "apply", "--check", "-v", patchFile)
97
93
} else {
98
94
// if patch is a format-patch, apply using 'git am'
99
-
if formatPatch {
95
+
if opts.FormatPatch {
100
96
amCmd := exec.Command("git", "-C", tmpDir, "am", patchFile)
101
97
amCmd.Stderr = &stderr
102
98
if err := amCmd.Run(); err != nil {
···
169
165
}
170
166
171
167
func (g *GitRepo) MergeCheck(patchData []byte, targetBranch string) error {
168
+
var opts MergeOptions
169
+
opts.FormatPatch = patchutil.IsFormatPatch(string(patchData))
170
+
172
171
patchFile, err := g.createTempFileWithPatch(patchData)
173
172
if err != nil {
174
173
return &ErrMerge{
···
187
186
}
188
187
defer os.RemoveAll(tmpDir)
189
188
190
-
return g.applyPatch(tmpDir, patchFile, true, nil)
189
+
return g.applyPatch(tmpDir, patchFile, true, &opts)
191
190
}
192
191
193
192
func (g *GitRepo) Merge(patchData []byte, targetBranch string) error {
+4
knotserver/routes.go
+4
knotserver/routes.go
···
24
24
"github.com/go-git/go-git/v5/plumbing/object"
25
25
"tangled.sh/tangled.sh/core/knotserver/db"
26
26
"tangled.sh/tangled.sh/core/knotserver/git"
27
+
"tangled.sh/tangled.sh/core/patchutil"
27
28
"tangled.sh/tangled.sh/core/types"
28
29
)
29
30
···
687
688
notFound(w)
688
689
return
689
690
}
691
+
692
+
mo.FormatPatch = patchutil.IsFormatPatch(patch)
693
+
690
694
if err := gr.MergeWithOptions([]byte(patch), branch, mo); err != nil {
691
695
var mergeErr *git.ErrMerge
692
696
if errors.As(err, &mergeErr) {