Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
py-heptapod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
heptapod
py-heptapod
Commits
a8addf5e
Commit
a8addf5e
authored
3 years ago
by
Sushil Khanchi
Browse files
Options
Downloads
Patches
Plain Diff
heptapod: add command `hpd-ensure-gitlab-default-branch`
parent
d7c53051
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!62
heptapod: add command `hpd-ensure-gitlab-default-branch`
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hgext3rd/heptapod/__init__.py
+13
-0
13 additions, 0 deletions
hgext3rd/heptapod/__init__.py
hgext3rd/heptapod/git.py
+22
-0
22 additions, 0 deletions
hgext3rd/heptapod/git.py
hgext3rd/heptapod/tests/test_commands_misc.py
+12
-0
12 additions, 0 deletions
hgext3rd/heptapod/tests/test_commands_misc.py
with
47 additions
and
0 deletions
hgext3rd/heptapod/__init__.py
+
13
−
0
View file @
a8addf5e
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
hgext3rd/heptapod/git.py
+
22
−
0
View file @
a8addf5e
...
...
@@ -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
(
...
...
This diff is collapsed.
Click to expand it.
hgext3rd/heptapod/tests/test_commands_misc.py
+
12
−
0
View file @
a8addf5e
...
...
@@ -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
())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment