Skip to content

Commit bf1970d

Browse files
lunnylafriks
andauthoredFeb 2, 2020
Improve push update options (#10105)
* Improve push update options * fix test * More refactor and fix lint * fix lint * Fix lint Co-authored-by: Lauris BH <[email protected]>
1 parent 70aa629 commit bf1970d

File tree

5 files changed

+192
-152
lines changed

5 files changed

+192
-152
lines changed
 

‎.golangci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,6 @@ issues:
9595
- linters:
9696
- misspell
9797
text: '`Unknwon` is a misspelling of `Unknown`'
98+
- path: models/update.go
99+
linters:
100+
- unused

‎modules/repofiles/action.go

+8-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/json"
99
"fmt"
1010
"html"
11-
"strings"
1211

1312
"code.gitea.io/gitea/models"
1413
"code.gitea.io/gitea/modules/git"
@@ -151,12 +150,9 @@ func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*r
151150

152151
// CommitRepoActionOptions represent options of a new commit action.
153152
type CommitRepoActionOptions struct {
154-
PusherName string
153+
PushUpdateOptions
154+
155155
RepoOwnerID int64
156-
RepoName string
157-
RefFullName string
158-
OldCommitID string
159-
NewCommitID string
160156
Commits *repository.PushCommits
161157
}
162158

@@ -192,7 +188,7 @@ func CommitRepoAction(optsList ...*CommitRepoActionOptions) error {
192188
refName := git.RefEndName(opts.RefFullName)
193189

194190
// Change default branch and empty status only if pushed ref is non-empty branch.
195-
if repo.IsEmpty && opts.NewCommitID != git.EmptySHA && strings.HasPrefix(opts.RefFullName, git.BranchPrefix) {
191+
if repo.IsEmpty && opts.IsBranch() && !opts.IsDelRef() {
196192
repo.DefaultBranch = refName
197193
repo.IsEmpty = false
198194
if refName != "master" {
@@ -210,24 +206,21 @@ func CommitRepoAction(optsList ...*CommitRepoActionOptions) error {
210206
}
211207
}
212208

213-
isNewBranch := false
214209
opType := models.ActionCommitRepo
215210

216211
// Check it's tag push or branch.
217-
if strings.HasPrefix(opts.RefFullName, git.TagPrefix) {
212+
if opts.IsTag() {
218213
opType = models.ActionPushTag
219-
if opts.NewCommitID == git.EmptySHA {
214+
if opts.IsDelRef() {
220215
opType = models.ActionDeleteTag
221216
}
222217
opts.Commits = &repository.PushCommits{}
223-
} else if opts.NewCommitID == git.EmptySHA {
218+
} else if opts.IsDelRef() {
224219
opType = models.ActionDeleteBranch
225220
opts.Commits = &repository.PushCommits{}
226221
} else {
227222
// if not the first commit, set the compare URL.
228-
if opts.OldCommitID == git.EmptySHA {
229-
isNewBranch = true
230-
} else {
223+
if !opts.IsNewRef() {
231224
opts.Commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID)
232225
}
233226

@@ -259,7 +252,7 @@ func CommitRepoAction(optsList ...*CommitRepoActionOptions) error {
259252
var isHookEventPush = true
260253
switch opType {
261254
case models.ActionCommitRepo: // Push
262-
if isNewBranch {
255+
if opts.IsNewBranch() {
263256
notification.NotifyCreateRef(pusher, repo, "branch", opts.RefFullName)
264257
}
265258
case models.ActionDeleteBranch: // Delete Branch

‎modules/repofiles/action_test.go

+23-15
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ func TestCommitRepoAction(t *testing.T) {
3232
userID: 2,
3333
repositoryID: 16,
3434
commitRepoActionOptions: CommitRepoActionOptions{
35-
RefFullName: "refName",
36-
OldCommitID: "oldCommitID",
37-
NewCommitID: "newCommitID",
35+
PushUpdateOptions: PushUpdateOptions{
36+
RefFullName: "refName",
37+
OldCommitID: "oldCommitID",
38+
NewCommitID: "newCommitID",
39+
},
3840
Commits: &repository.PushCommits{
3941
Commits: []*repository.PushCommit{
4042
{
@@ -66,10 +68,12 @@ func TestCommitRepoAction(t *testing.T) {
6668
userID: 2,
6769
repositoryID: 1,
6870
commitRepoActionOptions: CommitRepoActionOptions{
69-
RefFullName: git.TagPrefix + "v1.1",
70-
OldCommitID: git.EmptySHA,
71-
NewCommitID: "newCommitID",
72-
Commits: &repository.PushCommits{},
71+
PushUpdateOptions: PushUpdateOptions{
72+
RefFullName: git.TagPrefix + "v1.1",
73+
OldCommitID: git.EmptySHA,
74+
NewCommitID: "newCommitID",
75+
},
76+
Commits: &repository.PushCommits{},
7377
},
7478
action: models.Action{
7579
OpType: models.ActionPushTag,
@@ -80,10 +84,12 @@ func TestCommitRepoAction(t *testing.T) {
8084
userID: 2,
8185
repositoryID: 1,
8286
commitRepoActionOptions: CommitRepoActionOptions{
83-
RefFullName: git.TagPrefix + "v1.1",
84-
OldCommitID: "oldCommitID",
85-
NewCommitID: git.EmptySHA,
86-
Commits: &repository.PushCommits{},
87+
PushUpdateOptions: PushUpdateOptions{
88+
RefFullName: git.TagPrefix + "v1.1",
89+
OldCommitID: "oldCommitID",
90+
NewCommitID: git.EmptySHA,
91+
},
92+
Commits: &repository.PushCommits{},
8793
},
8894
action: models.Action{
8995
OpType: models.ActionDeleteTag,
@@ -94,10 +100,12 @@ func TestCommitRepoAction(t *testing.T) {
94100
userID: 2,
95101
repositoryID: 1,
96102
commitRepoActionOptions: CommitRepoActionOptions{
97-
RefFullName: git.BranchPrefix + "feature/1",
98-
OldCommitID: "oldCommitID",
99-
NewCommitID: git.EmptySHA,
100-
Commits: &repository.PushCommits{},
103+
PushUpdateOptions: PushUpdateOptions{
104+
RefFullName: git.BranchPrefix + "feature/1",
105+
OldCommitID: "oldCommitID",
106+
NewCommitID: git.EmptySHA,
107+
},
108+
Commits: &repository.PushCommits{},
101109
},
102110
action: models.Action{
103111
OpType: models.ActionDeleteBranch,

‎modules/repofiles/update.go

+156-113
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,77 @@ type PushUpdateOptions struct {
452452
RefFullName string
453453
OldCommitID string
454454
NewCommitID string
455-
Branch string
455+
}
456+
457+
// IsNewRef return true if it's a first-time push to a branch, tag or etc.
458+
func (opts PushUpdateOptions) IsNewRef() bool {
459+
return opts.OldCommitID == git.EmptySHA
460+
}
461+
462+
// IsDelRef return true if it's a deletion to a branch or tag
463+
func (opts PushUpdateOptions) IsDelRef() bool {
464+
return opts.NewCommitID == git.EmptySHA
465+
}
466+
467+
// IsUpdateRef return true if it's an update operation
468+
func (opts PushUpdateOptions) IsUpdateRef() bool {
469+
return !opts.IsNewRef() && !opts.IsDelRef()
470+
}
471+
472+
// IsTag return true if it's an operation to a tag
473+
func (opts PushUpdateOptions) IsTag() bool {
474+
return strings.HasPrefix(opts.RefFullName, git.TagPrefix)
475+
}
476+
477+
// IsNewTag return true if it's a creation to a tag
478+
func (opts PushUpdateOptions) IsNewTag() bool {
479+
return opts.IsTag() && opts.IsNewRef()
480+
}
481+
482+
// IsDelTag return true if it's a deletion to a tag
483+
func (opts PushUpdateOptions) IsDelTag() bool {
484+
return opts.IsTag() && opts.IsDelRef()
485+
}
486+
487+
// IsBranch return true if it's a push to branch
488+
func (opts PushUpdateOptions) IsBranch() bool {
489+
return strings.HasPrefix(opts.RefFullName, git.BranchPrefix)
490+
}
491+
492+
// IsNewBranch return true if it's the first-time push to a branch
493+
func (opts PushUpdateOptions) IsNewBranch() bool {
494+
return opts.IsBranch() && opts.IsNewRef()
495+
}
496+
497+
// IsUpdateBranch return true if it's not the first push to a branch
498+
func (opts PushUpdateOptions) IsUpdateBranch() bool {
499+
return opts.IsBranch() && opts.IsUpdateRef()
500+
}
501+
502+
// IsDelBranch return true if it's a deletion to a branch
503+
func (opts PushUpdateOptions) IsDelBranch() bool {
504+
return opts.IsBranch() && opts.IsDelRef()
505+
}
506+
507+
// TagName returns simple tag name if it's an operation to a tag
508+
func (opts PushUpdateOptions) TagName() string {
509+
return opts.RefFullName[len(git.TagPrefix):]
510+
}
511+
512+
// BranchName returns simple branch name if it's an operation to branch
513+
func (opts PushUpdateOptions) BranchName() string {
514+
return opts.RefFullName[len(git.BranchPrefix):]
515+
}
516+
517+
// RepoFullName returns repo full name
518+
func (opts PushUpdateOptions) RepoFullName() string {
519+
return opts.RepoUserName + "/" + opts.RepoName
456520
}
457521

458522
// PushUpdate must be called for any push actions in order to
459523
// generates necessary push action history feeds and other operations
460524
func PushUpdate(repo *models.Repository, branch string, opts PushUpdateOptions) error {
461-
isNewRef := opts.OldCommitID == git.EmptySHA
462-
isDelRef := opts.NewCommitID == git.EmptySHA
463-
if isNewRef && isDelRef {
525+
if opts.IsNewRef() && opts.IsDelRef() {
464526
return fmt.Errorf("Old and new revisions are both %s", git.EmptySHA)
465527
}
466528

@@ -481,35 +543,75 @@ func PushUpdate(repo *models.Repository, branch string, opts PushUpdateOptions)
481543
log.Error("Failed to update size for repository: %v", err)
482544
}
483545

484-
commitRepoActionOptions, err := createCommitRepoActionOption(repo, gitRepo, &opts)
485-
if err != nil {
486-
return err
487-
}
546+
var commits = &repo_module.PushCommits{}
488547

489-
if err := CommitRepoAction(commitRepoActionOptions); err != nil {
490-
return fmt.Errorf("CommitRepoAction: %v", err)
491-
}
548+
if opts.IsTag() { // If is tag reference
549+
tagName := opts.TagName()
550+
if opts.IsDelRef() {
551+
if err := models.PushUpdateDeleteTag(repo, tagName); err != nil {
552+
return fmt.Errorf("PushUpdateDeleteTag: %v", err)
553+
}
554+
} else {
555+
// Clear cache for tag commit count
556+
cache.Remove(repo.GetCommitsCountCacheKey(tagName, true))
557+
if err := repo_module.PushUpdateAddTag(repo, gitRepo, tagName); err != nil {
558+
return fmt.Errorf("PushUpdateAddTag: %v", err)
559+
}
560+
}
561+
} else if opts.IsBranch() { // If is branch reference
562+
pusher, err := models.GetUserByID(opts.PusherID)
563+
if err != nil {
564+
return err
565+
}
492566

493-
pusher, err := models.GetUserByID(opts.PusherID)
494-
if err != nil {
495-
return err
496-
}
567+
if !opts.IsDelRef() {
568+
// Clear cache for branch commit count
569+
cache.Remove(repo.GetCommitsCountCacheKey(opts.BranchName(), true))
497570

498-
if !isDelRef {
499-
if err = models.RemoveDeletedBranch(repo.ID, opts.Branch); err != nil {
500-
log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, opts.Branch, err)
501-
}
571+
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
572+
if err != nil {
573+
return fmt.Errorf("gitRepo.GetCommit: %v", err)
574+
}
502575

503-
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
576+
// Push new branch.
577+
var l *list.List
578+
if opts.IsNewRef() {
579+
l, err = newCommit.CommitsBeforeLimit(10)
580+
if err != nil {
581+
return fmt.Errorf("newCommit.CommitsBeforeLimit: %v", err)
582+
}
583+
} else {
584+
l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID)
585+
if err != nil {
586+
return fmt.Errorf("newCommit.CommitsBeforeUntil: %v", err)
587+
}
588+
}
589+
590+
commits = repo_module.ListToPushCommits(l)
591+
592+
if err = models.RemoveDeletedBranch(repo.ID, opts.BranchName()); err != nil {
593+
log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, opts.BranchName(), err)
594+
}
504595

505-
go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true, opts.OldCommitID, opts.NewCommitID)
506-
// close all related pulls
507-
} else if err = pull_service.CloseBranchPulls(pusher, repo.ID, branch); err != nil {
508-
log.Error("close related pull request failed: %v", err)
596+
if err = models.WatchIfAuto(opts.PusherID, repo.ID, true); err != nil {
597+
log.Warn("Fail to perform auto watch on user %v for repo %v: %v", opts.PusherID, repo.ID, err)
598+
}
599+
600+
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
601+
602+
go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true, opts.OldCommitID, opts.NewCommitID)
603+
} else if err = pull_service.CloseBranchPulls(pusher, repo.ID, branch); err != nil {
604+
// close all related pulls
605+
log.Error("close related pull request failed: %v", err)
606+
}
509607
}
510608

511-
if err = models.WatchIfAuto(opts.PusherID, repo.ID, true); err != nil {
512-
log.Warn("Fail to perform auto watch on user %v for repo %v: %v", opts.PusherID, repo.ID, err)
609+
if err := CommitRepoAction(&CommitRepoActionOptions{
610+
PushUpdateOptions: opts,
611+
RepoOwnerID: repo.OwnerID,
612+
Commits: commits,
613+
}); err != nil {
614+
return fmt.Errorf("CommitRepoAction: %v", err)
513615
}
514616

515617
return nil
@@ -526,6 +628,8 @@ func PushUpdates(repo *models.Repository, optsList []*PushUpdateOptions) error {
526628
if err != nil {
527629
return fmt.Errorf("OpenRepository: %v", err)
528630
}
631+
defer gitRepo.Close()
632+
529633
if err = repo.UpdateSize(models.DefaultDBContext()); err != nil {
530634
log.Error("Failed to update size for repository: %v", err)
531635
}
@@ -541,6 +645,12 @@ func PushUpdates(repo *models.Repository, optsList []*PushUpdateOptions) error {
541645
var pusher *models.User
542646

543647
for _, opts := range optsList {
648+
if !opts.IsBranch() {
649+
continue
650+
}
651+
652+
branch := opts.BranchName()
653+
544654
if pusher == nil || pusher.ID != opts.PusherID {
545655
var err error
546656
pusher, err = models.GetUserByID(opts.PusherID)
@@ -549,22 +659,22 @@ func PushUpdates(repo *models.Repository, optsList []*PushUpdateOptions) error {
549659
}
550660
}
551661

552-
if opts.NewCommitID != git.EmptySHA {
553-
if err = models.RemoveDeletedBranch(repo.ID, opts.Branch); err != nil {
554-
log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, opts.Branch, err)
662+
if !opts.IsDelRef() {
663+
if err = models.RemoveDeletedBranch(repo.ID, branch); err != nil {
664+
log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, branch, err)
665+
}
666+
667+
if err = models.WatchIfAuto(opts.PusherID, repo.ID, true); err != nil {
668+
log.Warn("Fail to perform auto watch on user %v for repo %v: %v", opts.PusherID, repo.ID, err)
555669
}
556670

557-
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, opts.Branch, pusher.Name)
671+
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
558672

559-
go pull_service.AddTestPullRequestTask(pusher, repo.ID, opts.Branch, true, opts.OldCommitID, opts.NewCommitID)
673+
go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true, opts.OldCommitID, opts.NewCommitID)
560674
// close all related pulls
561-
} else if err = pull_service.CloseBranchPulls(pusher, repo.ID, opts.Branch); err != nil {
675+
} else if err = pull_service.CloseBranchPulls(pusher, repo.ID, branch); err != nil {
562676
log.Error("close related pull request failed: %v", err)
563677
}
564-
565-
if err = models.WatchIfAuto(opts.PusherID, repo.ID, true); err != nil {
566-
log.Warn("Fail to perform auto watch on user %v for repo %v: %v", opts.PusherID, repo.ID, err)
567-
}
568678
}
569679

570680
return nil
@@ -576,26 +686,24 @@ func createCommitRepoActions(repo *models.Repository, gitRepo *git.Repository, o
576686
actions := make([]*CommitRepoActionOptions, 0, len(optsList))
577687

578688
for _, opts := range optsList {
579-
isNewRef := opts.OldCommitID == git.EmptySHA
580-
isDelRef := opts.NewCommitID == git.EmptySHA
581-
if isNewRef && isDelRef {
689+
if opts.IsNewRef() && opts.IsDelRef() {
582690
return nil, fmt.Errorf("Old and new revisions are both %s", git.EmptySHA)
583691
}
584692
var commits = &repo_module.PushCommits{}
585-
if strings.HasPrefix(opts.RefFullName, git.TagPrefix) {
693+
if opts.IsNewTag() {
586694
// If is tag reference
587-
tagName := opts.RefFullName[len(git.TagPrefix):]
588-
if isDelRef {
695+
tagName := opts.TagName()
696+
if opts.IsDelRef() {
589697
delTags = append(delTags, tagName)
590698
} else {
591699
cache.Remove(repo.GetCommitsCountCacheKey(tagName, true))
592700
addTags = append(addTags, tagName)
593701
}
594-
} else if !isDelRef {
702+
} else if !opts.IsDelRef() {
595703
// If is branch reference
596704

597705
// Clear cache for branch commit count
598-
cache.Remove(repo.GetCommitsCountCacheKey(opts.RefFullName[len(git.BranchPrefix):], true))
706+
cache.Remove(repo.GetCommitsCountCacheKey(opts.BranchName(), true))
599707

600708
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
601709
if err != nil {
@@ -604,7 +712,7 @@ func createCommitRepoActions(repo *models.Repository, gitRepo *git.Repository, o
604712

605713
// Push new branch.
606714
var l *list.List
607-
if isNewRef {
715+
if opts.IsNewRef() {
608716
l, err = newCommit.CommitsBeforeLimit(10)
609717
if err != nil {
610718
return nil, fmt.Errorf("newCommit.CommitsBeforeLimit: %v", err)
@@ -619,78 +727,13 @@ func createCommitRepoActions(repo *models.Repository, gitRepo *git.Repository, o
619727
commits = repo_module.ListToPushCommits(l)
620728
}
621729
actions = append(actions, &CommitRepoActionOptions{
622-
PusherName: opts.PusherName,
623-
RepoOwnerID: repo.OwnerID,
624-
RepoName: repo.Name,
625-
RefFullName: opts.RefFullName,
626-
OldCommitID: opts.OldCommitID,
627-
NewCommitID: opts.NewCommitID,
628-
Commits: commits,
730+
PushUpdateOptions: *opts,
731+
RepoOwnerID: repo.OwnerID,
732+
Commits: commits,
629733
})
630734
}
631735
if err := models.PushUpdateAddDeleteTags(repo, gitRepo, addTags, delTags); err != nil {
632736
return nil, fmt.Errorf("PushUpdateAddDeleteTags: %v", err)
633737
}
634738
return actions, nil
635739
}
636-
637-
func createCommitRepoActionOption(repo *models.Repository, gitRepo *git.Repository, opts *PushUpdateOptions) (*CommitRepoActionOptions, error) {
638-
isNewRef := opts.OldCommitID == git.EmptySHA
639-
isDelRef := opts.NewCommitID == git.EmptySHA
640-
if isNewRef && isDelRef {
641-
return nil, fmt.Errorf("Old and new revisions are both %s", git.EmptySHA)
642-
}
643-
644-
var commits = &repo_module.PushCommits{}
645-
if strings.HasPrefix(opts.RefFullName, git.TagPrefix) {
646-
// If is tag reference
647-
tagName := opts.RefFullName[len(git.TagPrefix):]
648-
if isDelRef {
649-
if err := models.PushUpdateDeleteTag(repo, tagName); err != nil {
650-
return nil, fmt.Errorf("PushUpdateDeleteTag: %v", err)
651-
}
652-
} else {
653-
// Clear cache for tag commit count
654-
cache.Remove(repo.GetCommitsCountCacheKey(tagName, true))
655-
if err := repo_module.PushUpdateAddTag(repo, gitRepo, tagName); err != nil {
656-
return nil, fmt.Errorf("PushUpdateAddTag: %v", err)
657-
}
658-
}
659-
} else if !isDelRef {
660-
// If is branch reference
661-
662-
// Clear cache for branch commit count
663-
cache.Remove(repo.GetCommitsCountCacheKey(opts.RefFullName[len(git.BranchPrefix):], true))
664-
665-
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
666-
if err != nil {
667-
return nil, fmt.Errorf("gitRepo.GetCommit: %v", err)
668-
}
669-
670-
// Push new branch.
671-
var l *list.List
672-
if isNewRef {
673-
l, err = newCommit.CommitsBeforeLimit(10)
674-
if err != nil {
675-
return nil, fmt.Errorf("newCommit.CommitsBeforeLimit: %v", err)
676-
}
677-
} else {
678-
l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID)
679-
if err != nil {
680-
return nil, fmt.Errorf("newCommit.CommitsBeforeUntil: %v", err)
681-
}
682-
}
683-
684-
commits = repo_module.ListToPushCommits(l)
685-
}
686-
687-
return &CommitRepoActionOptions{
688-
PusherName: opts.PusherName,
689-
RepoOwnerID: repo.OwnerID,
690-
RepoName: repo.Name,
691-
RefFullName: opts.RefFullName,
692-
OldCommitID: opts.OldCommitID,
693-
NewCommitID: opts.NewCommitID,
694-
Commits: commits,
695-
}, nil
696-
}

‎routers/private/hook.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,6 @@ func HookPostReceive(ctx *macaron.Context, opts private.HookOptions) {
304304

305305
for i := range opts.OldCommitIDs {
306306
refFullName := opts.RefFullNames[i]
307-
branch := opts.RefFullNames[i]
308-
if strings.HasPrefix(branch, git.BranchPrefix) {
309-
branch = strings.TrimPrefix(branch, git.BranchPrefix)
310-
} else {
311-
branch = strings.TrimPrefix(branch, git.TagPrefix)
312-
}
313307

314308
// Only trigger activity updates for changes to branches or
315309
// tags. Updates to other refs (eg, refs/notes, refs/changes,
@@ -336,14 +330,13 @@ func HookPostReceive(ctx *macaron.Context, opts private.HookOptions) {
336330
RefFullName: refFullName,
337331
OldCommitID: opts.OldCommitIDs[i],
338332
NewCommitID: opts.NewCommitIDs[i],
339-
Branch: branch,
340333
PusherID: opts.UserID,
341334
PusherName: opts.UserName,
342335
RepoUserName: ownerName,
343336
RepoName: repoName,
344337
}
345338
updates = append(updates, &option)
346-
if repo.IsEmpty && branch == "master" && strings.HasPrefix(refFullName, git.BranchPrefix) {
339+
if repo.IsEmpty && option.IsBranch() && option.BranchName() == "master" {
347340
// put the master branch first
348341
copy(updates[1:], updates)
349342
updates[0] = &option
@@ -355,7 +348,7 @@ func HookPostReceive(ctx *macaron.Context, opts private.HookOptions) {
355348
if err := repofiles.PushUpdates(repo, updates); err != nil {
356349
log.Error("Failed to Update: %s/%s Total Updates: %d", ownerName, repoName, len(updates))
357350
for i, update := range updates {
358-
log.Error("Failed to Update: %s/%s Update: %d/%d: Branch: %s", ownerName, repoName, i, len(updates), update.Branch)
351+
log.Error("Failed to Update: %s/%s Update: %d/%d: Branch: %s", ownerName, repoName, i, len(updates), update.BranchName())
359352
}
360353
log.Error("Failed to Update: %s/%s Error: %v", ownerName, repoName, err)
361354

0 commit comments

Comments
 (0)
Please sign in to comment.