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

knotserver: git: support format-patch

authored by anirudh.fi and committed by oppi.li c8b4100f b229a0ea

Changed files
+17 -1
knotserver
git
+17 -1
knotserver/git/merge.go
··· 10 10 11 11 "github.com/go-git/go-git/v5" 12 12 "github.com/go-git/go-git/v5/plumbing" 13 + "tangled.sh/tangled.sh/core/patchutil" 13 14 ) 14 15 15 16 type ErrMerge struct { ··· 85 86 func (g *GitRepo) applyPatch(tmpDir, patchFile string, checkOnly bool, opts *MergeOptions) error { 86 87 var stderr bytes.Buffer 87 88 var cmd *exec.Cmd 89 + var formatPatch = false 90 + 91 + if patchutil.IsFormatPatch(patchFile) { 92 + formatPatch = true 93 + } 88 94 89 95 if checkOnly { 90 96 cmd = exec.Command("git", "-C", tmpDir, "apply", "--check", "-v", patchFile) 91 97 } else { 92 - exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run() 98 + // if patch is a format-patch, apply using 'git am' 99 + if formatPatch { 100 + amCmd := exec.Command("git", "-C", tmpDir, "am", patchFile) 101 + amCmd.Stderr = &stderr 102 + if err := amCmd.Run(); err != nil { 103 + return fmt.Errorf("patch application failed: %s", stderr.String()) 104 + } 105 + return nil 106 + } 93 107 108 + // else, apply using 'git apply' and commit it manually 109 + exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run() 94 110 if opts != nil { 95 111 applyCmd := exec.Command("git", "-C", tmpDir, "apply", patchFile) 96 112 applyCmd.Stderr = &stderr