Skip to content

Commit 321cc2a

Browse files
Bwkolunny
authored andcommitted
Set default branchname on first push (#3715)
1 parent cb87f29 commit 321cc2a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

models/action.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
523523
return fmt.Errorf("GetRepositoryByName [owner_id: %d, name: %s]: %v", opts.RepoOwnerID, opts.RepoName, err)
524524
}
525525

526+
refName := git.RefEndName(opts.RefFullName)
527+
if repo.IsBare && refName != repo.DefaultBranch {
528+
repo.DefaultBranch = refName
529+
}
530+
526531
// Change repository bare status and update last updated time.
527532
repo.IsBare = repo.IsBare && opts.Commits.Len <= 0
528533
if err = UpdateRepository(repo, false); err != nil {
@@ -563,7 +568,6 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
563568
return fmt.Errorf("Marshal: %v", err)
564569
}
565570

566-
refName := git.RefEndName(opts.RefFullName)
567571
if err = NotifyWatchers(&Action{
568572
ActUserID: pusher.ID,
569573
ActUser: pusher,

0 commit comments

Comments
 (0)