knotserver: git/merge: remove GitRepo.Merge #528

merged
opened by boltless.me targeting master from boltless.me/core: push-skprtmnmwuqn
Changed files
+14 -28
knotserver
+7 -20
knotserver/git/merge.go
··· 161 161 return nil 162 162 } 163 163 164 - func (g *GitRepo) applyPatch(tmpDir, patchFile string, opts *MergeOptions) error { 164 + func (g *GitRepo) applyPatch(tmpDir, patchFile string, opts MergeOptions) error { 165 165 var stderr bytes.Buffer 166 166 var cmd *exec.Cmd 167 167 168 + exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run() 169 + 168 170 // if patch is a format-patch, apply using 'git am' 169 171 if opts.FormatPatch { 170 - amCmd := exec.Command("git", "-C", tmpDir, "am", patchFile) 171 - amCmd.Stderr = &stderr 172 - if err := amCmd.Run(); err != nil { 173 - return fmt.Errorf("patch application failed: %s", stderr.String()) 174 - } 175 - return nil 176 - } 177 - 178 - // else, apply using 'git apply' and commit it manually 179 - exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run() 180 - if opts != nil { 172 + cmd = exec.Command("git", "-C", tmpDir, "am", patchFile) 173 + } else { 174 + // else, apply using 'git apply' and commit it manually 181 175 applyCmd := exec.Command("git", "-C", tmpDir, "apply", patchFile) 182 176 applyCmd.Stderr = &stderr 183 177 if err := applyCmd.Run(); err != nil { ··· 214 208 } 215 209 216 210 cmd = exec.Command("git", commitArgs...) 217 - } else { 218 - // If no commit message specified, use git-am which automatically creates a commit 219 - cmd = exec.Command("git", "-C", tmpDir, "am", patchFile) 220 211 } 221 212 222 213 cmd.Stderr = &stderr ··· 256 247 return result 257 248 } 258 249 259 - func (g *GitRepo) Merge(patchData []byte, targetBranch string) error { 260 - return g.MergeWithOptions(patchData, targetBranch, nil) 261 - } 262 - 263 - func (g *GitRepo) MergeWithOptions(patchData []byte, targetBranch string, opts *MergeOptions) error { 250 + func (g *GitRepo) MergeWithOptions(patchData []byte, targetBranch string, opts MergeOptions) error { 264 251 patchFile, err := g.createTempFileWithPatch(patchData) 265 252 if err != nil { 266 253 return &ErrMerge{
+7 -8
knotserver/routes.go
··· 977 977 return 978 978 } 979 979 980 - mo := &git.MergeOptions{ 981 - AuthorName: data.AuthorName, 982 - AuthorEmail: data.AuthorEmail, 983 - CommitBody: data.CommitBody, 984 - CommitMessage: data.CommitMessage, 985 - } 986 - 987 980 patch := data.Patch 988 981 branch := data.Branch 989 982 gr, err := git.Open(path, branch) ··· 992 985 return 993 986 } 994 987 995 - mo.FormatPatch = patchutil.IsFormatPatch(patch) 988 + mo := git.MergeOptions{ 989 + AuthorName: data.AuthorName, 990 + AuthorEmail: data.AuthorEmail, 991 + CommitBody: data.CommitBody, 992 + CommitMessage: data.CommitMessage, 993 + FormatPatch: patchutil.IsFormatPatch(patch), 994 + } 996 995 997 996 if err := gr.MergeWithOptions([]byte(patch), branch, mo); err != nil { 998 997 var mergeErr *git.ErrMerge