Skip to content
Snippets Groups Projects
Commit a8addf5e authored by Sushil Khanchi's avatar Sushil Khanchi :koala:
Browse files

heptapod: add command `hpd-ensure-gitlab-default-branch`

parent d7c53051
Branches
Tags
1 merge request!62heptapod: add command `hpd-ensure-gitlab-default-branch`
......@@ -170,6 +170,19 @@
return git.HeptapodGitHandler(repo, ui).ensure_gitlab_branches()
@command(b'hpd-ensure-gitlab-default-branch')
def ensure_gitlab_default_branch(ui, repo):
"""Ensure that GitLab default branch file is present.
If present, nothing happens.
If not, it is initialized from the auxiliary Git repository.
:returns: ``None` if the file was already present. Otherwise,
new Gitlab default branch :class:`bytes`.
"""
return git.HeptapodGitHandler(repo, ui).ensure_gitlab_default_branch()
@command(b'hpd-ensure-gitlab-tags')
def ensure_gitlab_tags(ui, repo):
"""Ensure that GitLab tags state file is present.
......
......@@ -26,6 +26,7 @@
from .branch import (
GITLAB_TYPED_REFS_MISSING,
get_default_gitlab_branch,
set_default_gitlab_branch,
gitlab_branches,
gitlab_tags,
......@@ -70,6 +71,27 @@
self._default_git_ref = res
return res
def ensure_gitlab_default_branch(self):
"""Init GitLab default branch file from Git repository if needed.
Nothing happens if the file is already present.
:returns: ``None` if the file was already present. Otherwise,
new GitLab default branch :class:`bytes`.
"""
repo = self.repo
gl_branch = get_default_gitlab_branch(repo)
if gl_branch is not None:
return
self.ui.note(b"Initializing GitLab default branch file "
b"for repo at '%s'" % repo.root)
gl_branch_ref = self.get_default_gitlab_ref()
gl_branch = git_branch_from_ref(gl_branch_ref)
set_default_gitlab_branch(repo, gl_branch)
return gl_branch
def set_default_gitlab_ref(self, new_default_ref):
new_gl_branch = git_branch_from_ref(new_default_ref)
self.repo.ui.note(
......
......@@ -77,6 +77,18 @@
assert hpd_branch.read_gitlab_branches(wrapper.repo) == {}
def test_hpd_ensure_gitlab_default_branch(tmpdir):
wrapper = RepoWrapper.init(tmpdir / 'repo', config=common_config())
# initially we don't have any default_gitlab_branch file
assert not hpd_branch.get_default_gitlab_branch(wrapper.repo)
# run command to create the file
wrapper.command('hpd-ensure-gitlab-default-branch')
assert hpd_branch.get_default_gitlab_branch(wrapper.repo) == b'master'
# if already exists, running again shouldn't make any difference
wrapper.command('hpd-ensure-gitlab-default-branch')
assert hpd_branch.get_default_gitlab_branch(wrapper.repo) == b'master'
def test_hpd_ensure_gitlab_tags(tmpdir):
# test almost trivial because all the logic is in HeptapodGitHandler
wrapper = RepoWrapper.init(tmpdir / 'repo', config=common_config())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment