Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

knotserver: git: support format-patch

authored by

Anirudh Oppiliappan and committed by
Akshay
c8b4100f b229a0ea

+17 -1
+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 { ··· 86 85 func (g *GitRepo) applyPatch(tmpDir, patchFile string, checkOnly bool, opts *MergeOptions) error { 87 86 var stderr bytes.Buffer 88 87 var cmd *exec.Cmd 88 + var formatPatch = false 89 + 90 + if patchutil.IsFormatPatch(patchFile) { 91 + formatPatch = true 92 + } 89 93 90 94 if checkOnly { 91 95 cmd = exec.Command("git", "-C", tmpDir, "apply", "--check", "-v", patchFile) 92 96 } else { 93 - exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run() 97 + // if patch is a format-patch, apply using 'git am' 98 + if formatPatch { 99 + amCmd := exec.Command("git", "-C", tmpDir, "am", patchFile) 100 + amCmd.Stderr = &stderr 101 + if err := amCmd.Run(); err != nil { 102 + return fmt.Errorf("patch application failed: %s", stderr.String()) 103 + } 104 + return nil 105 + } 94 106 107 + // else, apply using 'git apply' and commit it manually 108 + exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run() 95 109 if opts != nil { 96 110 applyCmd := exec.Command("git", "-C", tmpDir, "apply", patchFile) 97 111 applyCmd.Stderr = &stderr