forked from tangled.org/core
this repo has no description

knotserver: merge using git-am if format-patch is detected

Changed files
+10 -7
knotserver
+6 -7
knotserver/git/merge.go
···
CommitBody string
AuthorName string
AuthorEmail string
+
FormatPatch bool
}
func (e ErrMerge) Error() string {
···
func (g *GitRepo) applyPatch(tmpDir, patchFile string, checkOnly bool, opts *MergeOptions) error {
var stderr bytes.Buffer
var cmd *exec.Cmd
-
var formatPatch = false
-
-
if patchutil.IsFormatPatch(patchFile) {
-
formatPatch = true
-
}
if checkOnly {
cmd = exec.Command("git", "-C", tmpDir, "apply", "--check", "-v", patchFile)
} else {
// if patch is a format-patch, apply using 'git am'
-
if formatPatch {
+
if opts.FormatPatch {
amCmd := exec.Command("git", "-C", tmpDir, "am", patchFile)
amCmd.Stderr = &stderr
if err := amCmd.Run(); err != nil {
···
}
func (g *GitRepo) MergeCheck(patchData []byte, targetBranch string) error {
+
var opts MergeOptions
+
opts.FormatPatch = patchutil.IsFormatPatch(string(patchData))
+
patchFile, err := g.createTempFileWithPatch(patchData)
if err != nil {
return &ErrMerge{
···
}
defer os.RemoveAll(tmpDir)
-
return g.applyPatch(tmpDir, patchFile, true, nil)
+
return g.applyPatch(tmpDir, patchFile, true, &opts)
}
func (g *GitRepo) Merge(patchData []byte, targetBranch string) error {
+4
knotserver/routes.go
···
"github.com/go-git/go-git/v5/plumbing/object"
"tangled.sh/tangled.sh/core/knotserver/db"
"tangled.sh/tangled.sh/core/knotserver/git"
+
"tangled.sh/tangled.sh/core/patchutil"
"tangled.sh/tangled.sh/core/types"
)
···
notFound(w)
return
}
+
+
mo.FormatPatch = patchutil.IsFormatPatch(patch)
+
if err := gr.MergeWithOptions([]byte(patch), branch, mo); err != nil {
var mergeErr *git.ErrMerge
if errors.As(err, &mergeErr) {