Merge pull request !2849 from rhodecode-enterprise-ce feature/git-default-branch
Setting for default branch and creating new repo+commits on empty repo
This commit is contained in:
commit
126269feef
9 changed files with 210 additions and 15 deletions
|
|
@ -452,6 +452,15 @@ class _BaseVcsSettingsForm(formencode.Schema):
|
|||
|
||||
# git
|
||||
vcs_git_lfs_enabled = v.StringBoolean(if_missing=False)
|
||||
vcs_git_default_branch = v.Regex(
|
||||
r"^(?!\.)(?!.*\.\.)(?!.*[~^:?*\[\\\s])(?!.*//)(?!.*/$)(?!.*\.lock$).+$",
|
||||
not_empty=False,
|
||||
if_missing="master",
|
||||
messages={
|
||||
"invalid": "Invalid branch name. Branch names cannot: start with '.', contain '..', "
|
||||
"contain special characters (~^:?*[\\), end with '/', contain '//', or end with '.lock'."
|
||||
},
|
||||
)
|
||||
rhodecode_git_use_rebase_for_merging = v.StringBoolean(if_missing=False)
|
||||
rhodecode_git_close_branch_before_merging = v.StringBoolean(if_missing=False)
|
||||
rhodecode_git_merge_strategy_selector = v.StringBoolean(if_missing=False)
|
||||
|
|
|
|||
|
|
@ -562,8 +562,19 @@ class RepoModel(BaseModel):
|
|||
owner = self._get_user(owner)
|
||||
fork_of = self._get_repo(fork_of)
|
||||
repo_group = self._get_repo_group(safe_int(repo_group))
|
||||
default_landing_ref, _lbl = ScmModel.backend_landing_ref(repo_type)
|
||||
landing_rev = landing_rev or default_landing_ref
|
||||
if repo_type == "git" and not landing_rev:
|
||||
# Get default branch from global Git settings
|
||||
from rhodecode.model.settings import VcsSettingsModel
|
||||
|
||||
settings_model = VcsSettingsModel()
|
||||
global_settings = settings_model.get_global_settings()
|
||||
|
||||
default_branch = global_settings.get("vcs_git_default_branch", "master")
|
||||
landing_rev = f"branch:{default_branch}"
|
||||
else:
|
||||
# Other VCS types or explicit landing_rev provided
|
||||
default_landing_ref, _lbl = ScmModel.backend_landing_ref(repo_type)
|
||||
landing_rev = landing_rev or default_landing_ref
|
||||
|
||||
try:
|
||||
repo_name = safe_str(repo_name)
|
||||
|
|
|
|||
|
|
@ -479,7 +479,10 @@ class VcsSettingsModel(object):
|
|||
("experimental", "evolution"),
|
||||
("experimental", "evolution.exchange"),
|
||||
)
|
||||
GIT_SETTINGS = (("vcs_git_lfs", "enabled"),)
|
||||
GIT_SETTINGS = (
|
||||
("vcs_git_lfs", "enabled"),
|
||||
("vcs_git", "default_branch"),
|
||||
)
|
||||
GLOBAL_HG_SETTINGS = (
|
||||
("extensions", "largefiles"),
|
||||
("phases", "publish"),
|
||||
|
|
@ -489,7 +492,10 @@ class VcsSettingsModel(object):
|
|||
("experimental", "evolution.exchange"),
|
||||
)
|
||||
|
||||
GLOBAL_GIT_SETTINGS = (("vcs_git_lfs", "enabled"),)
|
||||
GLOBAL_GIT_SETTINGS = (
|
||||
("vcs_git_lfs", "enabled"),
|
||||
("vcs_git", "default_branch"),
|
||||
)
|
||||
|
||||
SVN_BRANCH_SECTION = "vcs_svn_branch"
|
||||
SVN_TAG_SECTION = "vcs_svn_tag"
|
||||
|
|
@ -638,22 +644,42 @@ class VcsSettingsModel(object):
|
|||
|
||||
def create_or_update_repo_git_settings(self, data):
|
||||
# NOTE(marcink): # comma makes unpack work properly
|
||||
(lfs_enabled,) = self.GIT_SETTINGS
|
||||
|
||||
(lfs_enabled_key,) = self._get_settings_keys(self.GIT_SETTINGS, data)
|
||||
(
|
||||
lfs_enabled,
|
||||
default_branch,
|
||||
) = self.GIT_SETTINGS
|
||||
(
|
||||
lfs_enabled_key,
|
||||
default_branch_key,
|
||||
) = self._get_settings_keys(self.GIT_SETTINGS, data)
|
||||
|
||||
self._create_or_update_ui(
|
||||
self.repo_settings, *lfs_enabled, value=data[lfs_enabled_key], active=data[lfs_enabled_key]
|
||||
)
|
||||
|
||||
self._create_or_update_ui(
|
||||
self.repo_settings, *default_branch, value=data[default_branch_key] or "master", active=True
|
||||
)
|
||||
|
||||
def create_or_update_global_git_settings(self, data):
|
||||
lfs_enabled = self.GLOBAL_GIT_SETTINGS[0]
|
||||
lfs_enabled_key = self._get_settings_keys(self.GLOBAL_GIT_SETTINGS, data)[0]
|
||||
# NOTE(marcink): # comma makes unpack work properly
|
||||
(
|
||||
lfs_enabled,
|
||||
default_branch,
|
||||
) = self.GLOBAL_GIT_SETTINGS
|
||||
(
|
||||
lfs_enabled_key,
|
||||
default_branch_key,
|
||||
) = self._get_settings_keys(self.GLOBAL_GIT_SETTINGS, data)
|
||||
|
||||
self._create_or_update_ui(
|
||||
self.global_settings, *lfs_enabled, value=data[lfs_enabled_key], active=data[lfs_enabled_key]
|
||||
)
|
||||
|
||||
self._create_or_update_ui(
|
||||
self.global_settings, *default_branch, value=data[default_branch_key] or "master", active=True
|
||||
)
|
||||
|
||||
def create_or_update_global_svn_settings(self, data):
|
||||
# branch/tags patterns
|
||||
self._create_svn_settings(self.global_settings, data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue