MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / MergeBranch

Function MergeBranch

internal/git/worktree.go:220–237  ·  view source on GitHub ↗

MergeBranch merges a branch into the current branch, returning conflicting file list on failure.

(repoDir, branch string)

Source from the content-addressed store, hash-verified

218
219// MergeBranch merges a branch into the current branch, returning conflicting file list on failure.
220func MergeBranch(repoDir, branch string) ([]string, error) {
221 cmd := exec.Command("git", "merge", branch)
222 cmd.Dir = repoDir
223 out, err := cmd.CombinedOutput()
224 if err != nil {
225 // Parse conflicting files from merge output
226 conflicts := parseConflicts(repoDir)
227 if len(conflicts) > 0 {
228 // Abort the merge to leave a clean state
229 abortCmd := exec.Command("git", "merge", "--abort")
230 abortCmd.Dir = repoDir
231 _ = abortCmd.Run()
232 return conflicts, fmt.Errorf("merge conflict: %s", strings.TrimSpace(string(out)))
233 }
234 return nil, fmt.Errorf("merge failed: %s", strings.TrimSpace(string(out)))
235 }
236 return nil, nil
237}
238
239// parseConflicts uses `git diff --name-only --diff-filter=U` to find conflicting files.
240func parseConflicts(repoDir string) []string {

Callers 3

handleCompletionKeysMethod · 0.92
handlePickerKeysMethod · 0.92
TestMergeBranchFunction · 0.85

Calls 2

parseConflictsFunction · 0.85
RunMethod · 0.80

Tested by 1

TestMergeBranchFunction · 0.68