···
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
···
func (g *GitRepo) applyPatch(tmpDir, patchFile string, checkOnly bool, opts *MergeOptions) error {
cmd = exec.Command("git", "-C", tmpDir, "apply", "--check", "-v", patchFile)
-
exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run()
applyCmd := exec.Command("git", "-C", tmpDir, "apply", patchFile)
applyCmd.Stderr = &stderr
···
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
+
"tangled.sh/tangled.sh/core/patchutil"
···
func (g *GitRepo) applyPatch(tmpDir, patchFile string, checkOnly bool, opts *MergeOptions) error {
+
var formatPatch = false
+
if patchutil.IsFormatPatch(patchFile) {
cmd = exec.Command("git", "-C", tmpDir, "apply", "--check", "-v", patchFile)
+
// if patch is a format-patch, apply using 'git am'
+
amCmd := exec.Command("git", "-C", tmpDir, "am", patchFile)
+
if err := amCmd.Run(); err != nil {
+
return fmt.Errorf("patch application failed: %s", stderr.String())
+
// else, apply using 'git apply' and commit it manually
+
exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run()
applyCmd := exec.Command("git", "-C", tmpDir, "apply", patchFile)
applyCmd.Stderr = &stderr