MCPcopy Create free account
hub / github.com/bluekeyes/patch2pr / Commit

Method Commit

applier.go:237–276  ·  view source on GitHub ↗

Commit commits the latest tree, optionally using the details in tmpl and header. If there are pending tree entries, it calls CreateTree before creating the commit. It returns an error if there are no pending trees or tree entries. If tmpl is not nil, Commit uses it as a template for the new commit,

(ctx context.Context, tmpl *github.Commit, header *gitdiff.PatchHeader)

Source from the content-addressed store, hash-verified

235// message, the current time, and the authenticated user as needed for the
236// commit details.
237func (a *Applier) Commit(ctx context.Context, tmpl *github.Commit, header *gitdiff.PatchHeader) (*github.Commit, error) {
238 if !a.uncommitted && len(a.entries) == 0 {
239 return nil, errors.New("no pending tree or tree entries")
240 }
241 if len(a.entries) > 0 {
242 if _, err := a.CreateTree(ctx); err != nil {
243 return nil, fmt.Errorf("create tree failed: %w", err)
244 }
245 }
246
247 var c github.Commit
248 if tmpl != nil {
249 c = *tmpl
250 }
251
252 c.Tree = &github.Tree{
253 SHA: github.Ptr(a.tree),
254 }
255 c.Parents = []*github.Commit{
256 a.commit,
257 }
258
259 if header != nil {
260 c.Message = github.Ptr(header.Message())
261 c.Author = makeCommitAuthor(header.Author, header.AuthorDate)
262 c.Committer = makeCommitAuthor(header.Committer, header.CommitterDate)
263 }
264 if c.Message == nil || *c.Message == "" {
265 c.Message = github.Ptr("Apply patch with patch2pr")
266 }
267
268 commit, _, err := a.client.Git.CreateCommit(ctx, a.owner, a.repo, c, nil)
269 if err != nil {
270 return nil, err
271 }
272
273 a.commit = commit
274 a.uncommitted = false
275 return commit, nil
276}
277
278// Reset resets the applier so that future Apply calls start from commit c. It
279// removes pending tree entries and clears the latest tree. Reset does not

Callers 2

runPatchTestFunction · 0.95
executeFunction · 0.95

Calls 2

CreateTreeMethod · 0.95
makeCommitAuthorFunction · 0.85

Tested by 1

runPatchTestFunction · 0.76