Check for 'main' as potential default branch name (#14193)
parent
c074e46292
commit
632800eda7
|
@ -243,6 +243,7 @@ func adoptRepository(ctx models.DBContext, repoPath string, u *models.User, repo
|
||||||
found := false
|
found := false
|
||||||
hasDefault := false
|
hasDefault := false
|
||||||
hasMaster := false
|
hasMaster := false
|
||||||
|
hasMain := false
|
||||||
for _, branch := range branches {
|
for _, branch := range branches {
|
||||||
if branch == repo.DefaultBranch {
|
if branch == repo.DefaultBranch {
|
||||||
found = true
|
found = true
|
||||||
|
@ -251,6 +252,8 @@ func adoptRepository(ctx models.DBContext, repoPath string, u *models.User, repo
|
||||||
hasDefault = true
|
hasDefault = true
|
||||||
} else if branch == "master" {
|
} else if branch == "master" {
|
||||||
hasMaster = true
|
hasMaster = true
|
||||||
|
} else if branch == "main" {
|
||||||
|
hasMain = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
|
@ -258,6 +261,8 @@ func adoptRepository(ctx models.DBContext, repoPath string, u *models.User, repo
|
||||||
repo.DefaultBranch = setting.Repository.DefaultBranch
|
repo.DefaultBranch = setting.Repository.DefaultBranch
|
||||||
} else if hasMaster {
|
} else if hasMaster {
|
||||||
repo.DefaultBranch = "master"
|
repo.DefaultBranch = "master"
|
||||||
|
} else if hasMain {
|
||||||
|
repo.DefaultBranch = "main"
|
||||||
} else if len(branches) > 0 {
|
} else if len(branches) > 0 {
|
||||||
repo.DefaultBranch = branches[0]
|
repo.DefaultBranch = branches[0]
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -412,8 +412,8 @@ func HookPostReceive(ctx *macaron.Context, opts private.HookOptions) {
|
||||||
RepoName: repoName,
|
RepoName: repoName,
|
||||||
}
|
}
|
||||||
updates = append(updates, &option)
|
updates = append(updates, &option)
|
||||||
if repo.IsEmpty && option.IsBranch() && option.BranchName() == "master" {
|
if repo.IsEmpty && option.IsBranch() && (option.BranchName() == "master" || option.BranchName() == "main") {
|
||||||
// put the master branch first
|
// put the master/main branch first
|
||||||
copy(updates[1:], updates)
|
copy(updates[1:], updates)
|
||||||
updates[0] = &option
|
updates[0] = &option
|
||||||
}
|
}
|
||||||
|
|
|
@ -521,6 +521,7 @@ func checkAndUpdateEmptyRepository(m *models.Mirror, gitRepo *git.Repository, re
|
||||||
|
|
||||||
hasDefault := false
|
hasDefault := false
|
||||||
hasMaster := false
|
hasMaster := false
|
||||||
|
hasMain := false
|
||||||
defaultBranchName := m.Repo.DefaultBranch
|
defaultBranchName := m.Repo.DefaultBranch
|
||||||
if len(defaultBranchName) == 0 {
|
if len(defaultBranchName) == 0 {
|
||||||
defaultBranchName = setting.Repository.DefaultBranch
|
defaultBranchName = setting.Repository.DefaultBranch
|
||||||
|
@ -540,6 +541,7 @@ func checkAndUpdateEmptyRepository(m *models.Mirror, gitRepo *git.Repository, re
|
||||||
|
|
||||||
hasDefault = hasDefault || name == defaultBranchName
|
hasDefault = hasDefault || name == defaultBranchName
|
||||||
hasMaster = hasMaster || name == "master"
|
hasMaster = hasMaster || name == "master"
|
||||||
|
hasMain = hasMain || name == "main"
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(firstName) > 0 {
|
if len(firstName) > 0 {
|
||||||
|
@ -547,6 +549,8 @@ func checkAndUpdateEmptyRepository(m *models.Mirror, gitRepo *git.Repository, re
|
||||||
m.Repo.DefaultBranch = defaultBranchName
|
m.Repo.DefaultBranch = defaultBranchName
|
||||||
} else if hasMaster {
|
} else if hasMaster {
|
||||||
m.Repo.DefaultBranch = "master"
|
m.Repo.DefaultBranch = "master"
|
||||||
|
} else if hasMain {
|
||||||
|
m.Repo.DefaultBranch = "main"
|
||||||
} else {
|
} else {
|
||||||
m.Repo.DefaultBranch = firstName
|
m.Repo.DefaultBranch = firstName
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue