aboutsummaryrefslogtreecommitdiff
path: root/models/update.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-02-24 15:35:20 -0500
committerUnknwon <u@gogs.io>2017-02-27 22:47:21 -0500
commitf0086e66aef31573c7f00e0c3cd7725fb6d65f5c (patch)
tree865fd5787c6f714add7be9da1e8cf19d4bc887cc /models/update.go
parent7fe13e72d8f8c0e61abbc4068ecb965347fe0331 (diff)
webhook: able to detect delete branch or tag (#2315)
Diffstat (limited to 'models/update.go')
-rw-r--r--models/update.go45
1 files changed, 22 insertions, 23 deletions
diff --git a/models/update.go b/models/update.go
index 507150be..77336ac9 100644
--- a/models/update.go
+++ b/models/update.go
@@ -10,8 +10,6 @@ import (
"os/exec"
"strings"
- log "gopkg.in/clog.v1"
-
git "github.com/gogits/git-module"
)
@@ -29,6 +27,10 @@ func CommitToPushCommit(commit *git.Commit) *PushCommit {
}
func ListToPushCommits(l *list.List) *PushCommits {
+ if l == nil {
+ return &PushCommits{}
+ }
+
commits := make([]*PushCommit, 0)
var actEmail string
for e := l.Front(); e != nil; e = e.Next() {
@@ -68,12 +70,6 @@ func PushUpdate(opts PushUpdateOptions) (err error) {
return fmt.Errorf("Fail to call 'git update-server-info': %v", err)
}
- if isDelRef {
- log.Trace("Reference '%s' has been deleted from '%s/%s' by %s",
- opts.RefFullName, opts.RepoUserName, opts.RepoName, opts.PusherName)
- return nil
- }
-
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
return fmt.Errorf("OpenRepository: %v", err)
@@ -100,27 +96,30 @@ func PushUpdate(opts PushUpdateOptions) (err error) {
NewCommitID: opts.NewCommitID,
Commits: &PushCommits{},
}); err != nil {
- return fmt.Errorf("CommitRepoAction (tag): %v", err)
+ return fmt.Errorf("CommitRepoAction.(tag): %v", err)
}
return nil
}
- newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
- if err != nil {
- return fmt.Errorf("gitRepo.GetCommit: %v", err)
- }
-
- // Push new branch.
var l *list.List
- if isNewRef {
- l, err = newCommit.CommitsBeforeLimit(10)
+ // Skip read parent commits when delete branch
+ if !isDelRef {
+ // Push new branch.
+ newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
if err != nil {
- return fmt.Errorf("newCommit.CommitsBeforeLimit: %v", err)
+ return fmt.Errorf("GetCommit [commit_id: %s]: %v", opts.NewCommitID, err)
}
- } else {
- l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID)
- if err != nil {
- return fmt.Errorf("newCommit.CommitsBeforeUntil: %v", err)
+
+ if isNewRef {
+ l, err = newCommit.CommitsBeforeLimit(10)
+ if err != nil {
+ return fmt.Errorf("CommitsBeforeLimit [commit_id: %s]: %v", newCommit.ID, err)
+ }
+ } else {
+ l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID)
+ if err != nil {
+ return fmt.Errorf("CommitsBeforeUntil [commit_id: %s]: %v", opts.OldCommitID, err)
+ }
}
}
@@ -133,7 +132,7 @@ func PushUpdate(opts PushUpdateOptions) (err error) {
NewCommitID: opts.NewCommitID,
Commits: ListToPushCommits(l),
}); err != nil {
- return fmt.Errorf("CommitRepoAction (branch): %v", err)
+ return fmt.Errorf("CommitRepoAction.(branch): %v", err)
}
return nil
}