Skip to content

Commit 4d643a5

Browse files
zeripathlunny
authored andcommitted
SetDefaultBranch on pushing to empty repository (#7610)
1 parent a957d4e commit 4d643a5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

models/action.go

+11
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,17 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
685685
if repo.IsEmpty && opts.NewCommitID != git.EmptySHA && strings.HasPrefix(opts.RefFullName, git.BranchPrefix) {
686686
repo.DefaultBranch = refName
687687
repo.IsEmpty = false
688+
if refName != "master" {
689+
gitRepo, err := git.OpenRepository(repo.RepoPath())
690+
if err != nil {
691+
return err
692+
}
693+
if err := gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
694+
if !git.IsErrUnsupportedVersion(err) {
695+
return err
696+
}
697+
}
698+
}
688699
}
689700

690701
// Change repository empty status and update last updated time.

0 commit comments

Comments
 (0)