MCPcopy Index your code
hub / github.com/gogs/gogs / PushUpdate

Function PushUpdate

internal/database/update.go:49–140  ·  view source on GitHub ↗

PushUpdate must be called for any push actions in order to generate necessary push action history feeds.

(opts PushUpdateOptions)

Source from the content-addressed store, hash-verified

47// PushUpdate must be called for any push actions in order to generate necessary
48// push action history feeds.
49func 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)

Callers 1

runHookPostReceiveFunction · 0.92

Calls 10

RepoPathFunction · 0.85
GetRepositoryByNameFunction · 0.85
appendFunction · 0.85
CommitsToPushCommitsFunction · 0.85
GetByUsernameMethod · 0.80
UsersMethod · 0.80
UpdateSizeMethod · 0.80
PushTagMethod · 0.80
ActionsMethod · 0.80
CommitRepoMethod · 0.80

Tested by

no test coverage detected