From 038050ea832e84f850e5a8d6255bc0ea54c9c2b7 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Sun, 24 Aug 2025 22:08:00 +0900 Subject: [PATCH] knotserver: git/merge: remove `GitRepo.Merge` Change-Id: xxskysxoklvorpmluuvrvwozymproyrq this method is not used now and should be replaced with `MergeWithOptions` Signed-off-by: Seongmin Lee --- knotserver/git/merge.go | 27 +++++++-------------------- knotserver/xrpc/merge.go | 2 +- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/knotserver/git/merge.go b/knotserver/git/merge.go index f88fcc4..3c9d182 100644 --- a/knotserver/git/merge.go +++ b/knotserver/git/merge.go @@ -160,23 +160,17 @@ func (g *GitRepo) checkPatch(tmpDir, patchFile string) error { 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 { @@ -213,9 +207,6 @@ func (g *GitRepo) applyPatch(tmpDir, patchFile string, opts *MergeOptions) error } 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 @@ -255,11 +246,7 @@ func (g *GitRepo) MergeCheck(patchData []byte, targetBranch string) error { 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{ diff --git a/knotserver/xrpc/merge.go b/knotserver/xrpc/merge.go index 554c0e1..4ba756f 100644 --- a/knotserver/xrpc/merge.go +++ b/knotserver/xrpc/merge.go @@ -67,7 +67,7 @@ func (x *Xrpc) Merge(w http.ResponseWriter, r *http.Request) { return } - mo := &git.MergeOptions{} + mo := git.MergeOptions{} if data.AuthorName != nil { mo.AuthorName = *data.AuthorName } -- 2.43.0