From 321cc2a3d0f267f8b0f5bb4365572636f1ce0443 Mon Sep 17 00:00:00 2001 From: Bwko Date: Sun, 25 Mar 2018 15:00:07 +0200 Subject: [PATCH] Set default branchname on first push (#3715) --- models/action.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/models/action.go b/models/action.go index b551d79bb8c..4f357cb2c59 100644 --- a/models/action.go +++ b/models/action.go @@ -523,6 +523,11 @@ func CommitRepoAction(opts CommitRepoActionOptions) error { return fmt.Errorf("GetRepositoryByName [owner_id: %d, name: %s]: %v", opts.RepoOwnerID, opts.RepoName, err) } + refName := git.RefEndName(opts.RefFullName) + if repo.IsBare && refName != repo.DefaultBranch { + repo.DefaultBranch = refName + } + // Change repository bare status and update last updated time. repo.IsBare = repo.IsBare && opts.Commits.Len <= 0 if err = UpdateRepository(repo, false); err != nil { @@ -563,7 +568,6 @@ func CommitRepoAction(opts CommitRepoActionOptions) error { return fmt.Errorf("Marshal: %v", err) } - refName := git.RefEndName(opts.RefFullName) if err = NotifyWatchers(&Action{ ActUserID: pusher.ID, ActUser: pusher,