knotserver: git/merge: remove GitRepo.Merge #528

merged
opened by boltless.me targeting master from boltless.me/core: push-skprtmnmwuqn
Changed files
+14 -28
knotserver
+7 -20
knotserver/git/merge.go
···
return nil
}
-
func (g *GitRepo) applyPatch(tmpDir, patchFile string, opts *MergeOptions) error {
+
func (g *GitRepo) applyPatch(tmpDir, patchFile string, opts MergeOptions) error {
var stderr bytes.Buffer
var cmd *exec.Cmd
+
exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run()
+
// if patch is a format-patch, apply using 'git am'
if opts.FormatPatch {
-
amCmd := exec.Command("git", "-C", tmpDir, "am", patchFile)
-
amCmd.Stderr = &stderr
-
if err := amCmd.Run(); err != nil {
-
return fmt.Errorf("patch application failed: %s", stderr.String())
-
}
-
return nil
-
}
-
-
// else, apply using 'git apply' and commit it manually
-
exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run()
-
if opts != nil {
+
cmd = exec.Command("git", "-C", tmpDir, "am", patchFile)
+
} else {
+
// else, apply using 'git apply' and commit it manually
applyCmd := exec.Command("git", "-C", tmpDir, "apply", patchFile)
applyCmd.Stderr = &stderr
if err := applyCmd.Run(); err != nil {
···
}
cmd = exec.Command("git", commitArgs...)
-
} else {
-
// If no commit message specified, use git-am which automatically creates a commit
-
cmd = exec.Command("git", "-C", tmpDir, "am", patchFile)
}
cmd.Stderr = &stderr
···
return result
}
-
func (g *GitRepo) Merge(patchData []byte, targetBranch string) error {
-
return g.MergeWithOptions(patchData, targetBranch, nil)
-
}
-
-
func (g *GitRepo) MergeWithOptions(patchData []byte, targetBranch string, opts *MergeOptions) error {
+
func (g *GitRepo) MergeWithOptions(patchData []byte, targetBranch string, opts MergeOptions) error {
patchFile, err := g.createTempFileWithPatch(patchData)
if err != nil {
return &ErrMerge{
+7 -8
knotserver/routes.go
···
return
}
-
mo := &git.MergeOptions{
-
AuthorName: data.AuthorName,
-
AuthorEmail: data.AuthorEmail,
-
CommitBody: data.CommitBody,
-
CommitMessage: data.CommitMessage,
-
}
-
patch := data.Patch
branch := data.Branch
gr, err := git.Open(path, branch)
···
return
}
-
mo.FormatPatch = patchutil.IsFormatPatch(patch)
+
mo := git.MergeOptions{
+
AuthorName: data.AuthorName,
+
AuthorEmail: data.AuthorEmail,
+
CommitBody: data.CommitBody,
+
CommitMessage: data.CommitMessage,
+
FormatPatch: patchutil.IsFormatPatch(patch),
+
}
if err := gr.MergeWithOptions([]byte(patch), branch, mo); err != nil {
var mergeErr *git.ErrMerge