PushUpdate must be called for any push actions in order to generate necessary push action history feeds.
(opts PushUpdateOptions)
| 47 | // PushUpdate must be called for any push actions in order to generate necessary |
| 48 | // push action history feeds. |
| 49 | func PushUpdate(opts PushUpdateOptions) (err error) { |
| 50 | ctx := context.TODO() |
| 51 | |
| 52 | isNewRef := strings.HasPrefix(opts.OldCommitID, git.EmptyID) |
| 53 | isDelRef := strings.HasPrefix(opts.NewCommitID, git.EmptyID) |
| 54 | if isNewRef && isDelRef { |
| 55 | return errors.Newf("both old and new revisions are %q", git.EmptyID) |
| 56 | } |
| 57 | |
| 58 | repoPath := RepoPath(opts.RepoUserName, opts.RepoName) |
| 59 | |
| 60 | gitUpdate := exec.Command("git", "update-server-info") |
| 61 | gitUpdate.Dir = repoPath |
| 62 | if err = gitUpdate.Run(); err != nil { |
| 63 | return errors.Newf("run 'git update-server-info': %v", err) |
| 64 | } |
| 65 | |
| 66 | gitRepo, err := git.Open(repoPath) |
| 67 | if err != nil { |
| 68 | return errors.Newf("open repository: %v", err) |
| 69 | } |
| 70 | |
| 71 | owner, err := Handle.Users().GetByUsername(ctx, opts.RepoUserName) |
| 72 | if err != nil { |
| 73 | return errors.Newf("GetUserByName: %v", err) |
| 74 | } |
| 75 | |
| 76 | repo, err := GetRepositoryByName(owner.ID, opts.RepoName) |
| 77 | if err != nil { |
| 78 | return errors.Newf("GetRepositoryByName: %v", err) |
| 79 | } |
| 80 | |
| 81 | if err = repo.UpdateSize(); err != nil { |
| 82 | return errors.Newf("UpdateSize: %v", err) |
| 83 | } |
| 84 | |
| 85 | // Push tags |
| 86 | if strings.HasPrefix(opts.FullRefspec, git.RefsTags) { |
| 87 | err := Handle.Actions().PushTag(ctx, |
| 88 | PushTagOptions{ |
| 89 | Owner: owner, |
| 90 | Repo: repo, |
| 91 | PusherName: opts.PusherName, |
| 92 | RefFullName: opts.FullRefspec, |
| 93 | NewCommitID: opts.NewCommitID, |
| 94 | }, |
| 95 | ) |
| 96 | if err != nil { |
| 97 | return errors.Wrap(err, "create action for push tag") |
| 98 | } |
| 99 | return nil |
| 100 | } |
| 101 | |
| 102 | var commits []*git.Commit |
| 103 | // Skip read parent commits when delete branch |
| 104 | if !isDelRef { |
| 105 | // Push new branch |
| 106 | newCommit, err := gitRepo.CatFileCommit(opts.NewCommitID) |
no test coverage detected