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
··· 160 160 return nil 161 161 } 162 162 163 - func (g *GitRepo) applyPatch(tmpDir, patchFile string, opts *MergeOptions) error { 163 + func (g *GitRepo) applyPatch(tmpDir, patchFile string, opts MergeOptions) error { 164 164 var stderr bytes.Buffer 165 165 var cmd *exec.Cmd 166 166 167 + exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run() 168 + 167 169 // if patch is a format-patch, apply using 'git am' 168 170 if opts.FormatPatch { 169 - amCmd := exec.Command("git", "-C", tmpDir, "am", patchFile) 170 - amCmd.Stderr = &stderr 171 - if err := amCmd.Run(); err != nil { 172 - return fmt.Errorf("patch application failed: %s", stderr.String()) 173 - } 174 - return nil 175 - } 176 - 177 - // else, apply using 'git apply' and commit it manually 178 - exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run() 179 - if opts != nil { 171 + cmd = exec.Command("git", "-C", tmpDir, "am", patchFile) 172 + } else { 173 + // else, apply using 'git apply' and commit it manually 180 174 applyCmd := exec.Command("git", "-C", tmpDir, "apply", patchFile) 181 175 applyCmd.Stderr = &stderr 182 176 if err := applyCmd.Run(); err != nil { ··· 213 207 } 214 208 215 209 cmd = exec.Command("git", commitArgs...) 216 - } else { 217 - // If no commit message specified, use git-am which automatically creates a commit 218 - cmd = exec.Command("git", "-C", tmpDir, "am", patchFile) 219 210 } 220 211 221 212 cmd.Stderr = &stderr ··· 255 246 return result 256 247 } 257 248 258 - func (g *GitRepo) Merge(patchData []byte, targetBranch string) error { 259 - return g.MergeWithOptions(patchData, targetBranch, nil) 260 - } 261 - 262 - func (g *GitRepo) MergeWithOptions(patchData []byte, targetBranch string, opts *MergeOptions) error { 249 + func (g *GitRepo) MergeWithOptions(patchData []byte, targetBranch string, opts MergeOptions) error { 263 250 patchFile, err := g.createTempFileWithPatch(patchData) 264 251 if err != nil { 265 252 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