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: merge using git-am if format-patch is detected

authored by

Anirudh Oppiliappan and committed by
Akshay
01c324e2 c8b4100f

+10 -7
+6 -7
knotserver/git/merge.go
··· 31 31 CommitBody string 32 32 AuthorName string 33 33 AuthorEmail string 34 + FormatPatch bool 34 35 } 35 36 36 37 func (e ErrMerge) Error() string { ··· 87 86 func (g *GitRepo) applyPatch(tmpDir, patchFile string, checkOnly bool, opts *MergeOptions) error { 88 87 var stderr bytes.Buffer 89 88 var cmd *exec.Cmd 90 - var formatPatch = false 91 - 92 - if patchutil.IsFormatPatch(patchFile) { 93 - formatPatch = true 94 - } 95 89 96 90 if checkOnly { 97 91 cmd = exec.Command("git", "-C", tmpDir, "apply", "--check", "-v", patchFile) 98 92 } else { 99 93 // if patch is a format-patch, apply using 'git am' 100 - if formatPatch { 94 + if opts.FormatPatch { 101 95 amCmd := exec.Command("git", "-C", tmpDir, "am", patchFile) 102 96 amCmd.Stderr = &stderr 103 97 if err := amCmd.Run(); err != nil { ··· 165 169 } 166 170 167 171 func (g *GitRepo) MergeCheck(patchData []byte, targetBranch string) error { 172 + var opts MergeOptions 173 + opts.FormatPatch = patchutil.IsFormatPatch(string(patchData)) 174 + 168 175 patchFile, err := g.createTempFileWithPatch(patchData) 169 176 if err != nil { 170 177 return &ErrMerge{ ··· 186 187 } 187 188 defer os.RemoveAll(tmpDir) 188 189 189 - return g.applyPatch(tmpDir, patchFile, true, nil) 190 + return g.applyPatch(tmpDir, patchFile, true, &opts) 190 191 } 191 192 192 193 func (g *GitRepo) Merge(patchData []byte, targetBranch string) error {
+4
knotserver/routes.go
··· 24 24 "github.com/go-git/go-git/v5/plumbing/object" 25 25 "tangled.sh/tangled.sh/core/knotserver/db" 26 26 "tangled.sh/tangled.sh/core/knotserver/git" 27 + "tangled.sh/tangled.sh/core/patchutil" 27 28 "tangled.sh/tangled.sh/core/types" 28 29 ) 29 30 ··· 688 687 notFound(w) 689 688 return 690 689 } 690 + 691 + mo.FormatPatch = patchutil.IsFormatPatch(patch) 692 + 691 693 if err := gr.MergeWithOptions([]byte(patch), branch, mo); err != nil { 692 694 var mergeErr *git.ErrMerge 693 695 if errors.As(err, &mergeErr) {