Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Shawn Webb
Git Lab
Commits
43db74f7
Unverified
Commit
43db74f7
authored
May 27, 2021
by
Jonah Brüchert
Browse files
Fix checkout command if the default branch is not "master"
parent
0cb2e8b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
lab/mergerequestcheckout.py
View file @
43db74f7
...
...
@@ -13,6 +13,7 @@ from gitlab.v4.objects import ProjectMergeRequest
from
lab.repositoryconnection
import
RepositoryConnection
from
lab.utils
import
Utils
from
lab.utils
import
LogType
def
parser
(
...
...
@@ -79,7 +80,22 @@ class MergeRequestCheckout(RepositoryConnection):
print
(
"Aborting"
)
sys
.
exit
(
1
)
self
.
_local_repo
.
refs
.
master
.
checkout
()
# If the branch that we want to overwrite is currently checked out,
# that will of course not work, so try to switch to another branch in the meantime.
if
self
.
__mr
.
source_branch
==
self
.
_local_repo
.
head
.
reference
.
name
:
if
"main"
in
self
.
_local_repo
.
refs
:
self
.
_local_repo
.
refs
.
main
.
checkout
()
elif
"master"
in
self
.
_local_repo
.
refs
:
self
.
_local_repo
.
refs
.
master
.
checkout
()
else
:
Utils
.
log
(
LogType
.
ERROR
,
"The branch that you want to overwrite is currently checked out
\
and no other branch to temporarily switch to could be found. Please check out
\
a different branch and try again."
,
)
sys
.
exit
(
1
)
self
.
_local_repo
.
delete_head
(
self
.
__mr
.
source_branch
,
"-f"
)
head
=
self
.
_local_repo
.
create_head
(
self
.
__mr
.
source_branch
,
fetch_info
.
ref
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment