From caaa9de9175b73e9de30af3f4fb67f89ddfbd557 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/routes.go | 15 +++++++-------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/knotserver/git/merge.go b/knotserver/git/merge.go index 9ab0867..69d3fb2 100644 --- a/knotserver/git/merge.go +++ b/knotserver/git/merge.go @@ -161,23 +161,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 { @@ -214,9 +208,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 @@ -256,11 +247,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/routes.go b/knotserver/routes.go index d116b90..e2ddeb4 100644 --- a/knotserver/routes.go +++ b/knotserver/routes.go @@ -977,13 +977,6 @@ func (h *Handle) Merge(w http.ResponseWriter, r *http.Request) { 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) @@ -992,7 +985,13 @@ func (h *Handle) Merge(w http.ResponseWriter, r *http.Request) { 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 -- 2.43.0