Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
hggitforge
Commits
872c9738f6b9
Commit
18d1ac22
authored
Oct 13, 2020
by
Elouan Martinet
Browse files
Add upstream-fork support
parent
fb80150ec1a6
Changes
1
Hide whitespace changes
Inline
Side-by-side
hggithub.py
View file @
872c9738
...
...
@@ -27,7 +27,31 @@ def cmd(description, *args, **kwargs):
def
git_clone
(
path_url
,
destination
):
cmd
(
"Cloning Git repository"
,
[
"git"
,
"clone"
,
path_url
,
destination
,
"--bare"
])
cmd
(
"Cloning Git fork repository"
,
[
"git"
,
"clone"
,
path_url
,
destination
,
"--bare"
]
)
def
git_configure_upstream
(
git_repo
,
git_upstream_url
):
cmd
(
"Adding upstream remote"
,
[
"git"
,
"remote"
,
"add"
,
"upstream"
,
git_upstream_url
],
cwd
=
git_repo
,
)
git_pull_master
(
git_repo
)
def
git_pull_master
(
git_repo
):
cmd
(
"Fetching upstream remote"
,
[
"git"
,
"fetch"
,
"upstream"
,
"master:master"
],
cwd
=
git_repo
,
)
cmd
(
"Pushing master branch to Git fork repository"
,
[
"git"
,
"push"
,
"-f"
,
"origin"
,
"master"
],
cwd
=
git_repo
,
)
def
hg_clone
(
path
,
destination
):
...
...
@@ -52,7 +76,7 @@ gitrepo = .hg/git.git
)
def
_ghclone
(
path
_url
,
destination
):
def
_ghclone
(
git_fork_url
,
git_upstream
_url
,
destination
):
working_dir
,
project_name
=
osp
.
split
(
destination
)
git_repo
=
osp
.
abspath
(
osp
.
join
(
working_dir
,
".%s.git"
%
project_name
))
if
osp
.
isdir
(
destination
):
...
...
@@ -63,7 +87,8 @@ def _ghclone(path_url, destination):
)
else
:
os
.
mkdir
(
destination
)
git_clone
(
path_url
,
git_repo
)
git_clone
(
git_fork_url
,
git_repo
)
git_configure_upstream
(
git_repo
,
git_upstream_url
)
hg_clone
(
git_repo
,
destination
)
final_git_repo
=
osp
.
abspath
(
osp
.
join
(
destination
,
".hg"
,
"git.git"
))
move
(
git_repo
,
final_git_repo
)
...
...
@@ -74,12 +99,14 @@ def _ghpull(git_repo):
branches
=
check_output
(
[
"git"
,
"branch"
,
"--format=%(refname:lstrip=2)"
],
cwd
=
git_repo
)
git_pull_master
(
git_repo
)
for
branch
in
branches
.
splitlines
():
cmd
(
"Fetching branch %s from remote Git repository"
%
branch
,
[
"git"
,
"fetch"
,
"origin"
,
"%s:%s"
%
(
branch
,
branch
)],
cwd
=
git_repo
,
)
if
branch
!=
"master"
:
cmd
(
"Fetching branch %s from remote Git fork repository"
%
branch
,
[
"git"
,
"fetch"
,
"origin"
,
"%s:%s"
%
(
branch
,
branch
)],
cwd
=
git_repo
,
)
cmd
(
"Updating Mercurial repository"
,
...
...
@@ -89,23 +116,27 @@ def _ghpull(git_repo):
def
_ghpush
(
git_repo
,
bookmark
):
if
bookmark
==
"master"
:
raise
ValueError
(
"Cannot push master branch"
)
cmd
(
"Pushing bookmark to local Git repository"
,
[
"hg"
,
"push"
,
"-B"
,
bookmark
,
"-f"
],
)
# TODO use --force-with-lease if possible
cmd
(
"Pu
blish
Git branch to
remote Git
repository"
,
"Pu
shing
Git branch to
Git fork
repository"
,
[
"git"
,
"push"
,
"--set-upstream"
,
"origin"
,
bookmark
,
"-f"
],
cwd
=
git_repo
,
)
@
command
(
"ghclone"
,
[],
_
(
"git_path working_directory"
),
norepo
=
True
)
def
ghclone
(
ui
,
git_url
,
working_directory
,
**
opts
):
@
command
(
"ghclone"
,
[],
_
(
"git_fork_path git_upstream_path working_directory"
),
norepo
=
True
)
def
ghclone
(
ui
,
git_fork_url
,
git_upstream_url
,
working_directory
,
**
opts
):
"""Prepare working directory to work with github"""
try
:
_ghclone
(
git_url
,
working_directory
)
_ghclone
(
git_
fork_url
,
git_upstream_
url
,
working_directory
)
except
CalledProcessError
:
pass
except
ValueError
as
ex
:
...
...
@@ -130,3 +161,5 @@ def ghpush(ui, repo, bookmark, **opts):
_ghpush
(
git_repo
,
bookmark
)
except
CalledProcessError
:
pass
except
ValueError
as
ex
:
print
(
ex
)
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