Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mercurial-devel
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
mercurial
mercurial-devel
Commits
d90fc91c
Commit
d90fc91c
authored
14 years ago
by
Eric Eisner
Browse files
Options
Downloads
Patches
Plain Diff
subrepo: update and merge works with any git branch
parent
845c602b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mercurial/subrepo.py
+50
-5
50 additions, 5 deletions
mercurial/subrepo.py
tests/test-subrepo-git.t
+7
-3
7 additions, 3 deletions
tests/test-subrepo-git.t
with
57 additions
and
8 deletions
mercurial/subrepo.py
+
50
−
5
View file @
d90fc91c
...
...
@@ -634,6 +634,26 @@
out
,
code
=
self
.
_gitdir
([
'
cat-file
'
,
'
-e
'
,
revision
])
return
code
==
0
def
_gitbranchmap
(
self
):
'
returns the current branch and a map from git revision to branch[es]
'
bm
=
{}
redirects
=
{}
current
=
None
out
=
self
.
_gitcommand
([
'
branch
'
,
'
-a
'
,
'
--no-color
'
,
'
--verbose
'
,
'
--abbrev=40
'
])
for
line
in
out
.
split
(
'
\n
'
):
if
not
line
:
continue
if
line
[
2
:].
startswith
(
'
(no branch)
'
):
continue
branch
,
revision
=
line
[
2
:].
split
()[:
2
]
if
revision
==
'
->
'
:
continue
# ignore remote/HEAD redirects
if
line
[
0
]
==
'
*
'
:
current
=
branch
bm
.
setdefault
(
revision
,
[]).
append
(
branch
)
return
current
,
bm
def
_fetch
(
self
,
source
,
revision
):
if
not
os
.
path
.
exists
(
'
%s/.git
'
%
self
.
_path
):
self
.
_ui
.
status
(
_
(
'
cloning subrepo %s
\n
'
)
%
self
.
_relpath
)
...
...
@@ -658,9 +678,13 @@
def
get
(
self
,
state
):
source
,
revision
,
kind
=
state
self
.
_fetch
(
source
,
revision
)
if
self
.
_gitstate
()
!=
revision
:
if
self
.
_gitstate
()
==
revision
:
return
current
,
bm
=
self
.
_gitbranchmap
()
if
revision
not
in
bm
:
# no branch to checkout, check it out with no branch
self
.
_ui
.
warn
(
_
(
'
checking out detached HEAD in subrepo %s
\n
'
)
%
self
.
_relpath
)
self
.
_ui
.
warn
(
_
(
'
check out a git branch if you intend
'
'
to make changes
\n
'
))
self
.
_gitcommand
([
'
checkout
'
,
'
-q
'
,
revision
])
...
...
@@ -662,8 +686,24 @@
self
.
_ui
.
warn
(
_
(
'
checking out detached HEAD in subrepo %s
\n
'
)
%
self
.
_relpath
)
self
.
_ui
.
warn
(
_
(
'
check out a git branch if you intend
'
'
to make changes
\n
'
))
self
.
_gitcommand
([
'
checkout
'
,
'
-q
'
,
revision
])
return
branches
=
bm
[
revision
]
firstlocalbranch
=
None
for
b
in
branches
:
if
b
==
'
master
'
:
# master trumps all other branches
self
.
_gitcommand
([
'
checkout
'
,
'
master
'
])
return
if
not
firstlocalbranch
and
not
b
.
startswith
(
'
remotes/
'
):
firstlocalbranch
=
b
if
firstlocalbranch
:
self
.
_gitcommand
([
'
checkout
'
,
firstlocalbranch
])
else
:
remote
=
branches
[
0
]
local
=
remote
.
split
(
'
/
'
)[
-
1
]
self
.
_gitcommand
([
'
checkout
'
,
'
-b
'
,
local
,
remote
])
def
commit
(
self
,
text
,
user
,
date
):
cmd
=
[
'
commit
'
,
'
-a
'
,
'
-m
'
,
text
]
...
...
@@ -692,10 +732,15 @@
cmd
=
[
'
push
'
]
if
force
:
cmd
.
append
(
'
--force
'
)
# as subrepos have no notion of "where to push to" we
# assume origin master. This is git's default
self
.
_gitcommand
(
cmd
+
[
'
origin
'
,
'
master
'
,
'
-q
'
])
return
True
# push the currently checked out branch
current
,
bm
=
self
.
_gitbranchmap
()
if
current
:
self
.
_gitcommand
(
cmd
+
[
'
origin
'
,
current
,
'
-q
'
])
return
True
else
:
self
.
_ui
.
warn
(
_
(
'
no branch checked out in subrepo %s
\n
'
'
nothing to push
'
)
%
self
.
_relpath
)
return
False
types
=
{
'
hg
'
:
hgsubrepo
,
...
...
This diff is collapsed.
Click to expand it.
tests/test-subrepo-git.t
+
7
−
3
View file @
d90fc91c
...
...
@@ -40,6 +40,6 @@
source ../gitroot
revision da5f5b1d8ffcf62fb8327bcd3c89a4367a6018e7
record a new commit from ups
tream
record a new commit from ups
tream
from
a
different
branch
$
cd
../
gitroot
...
...
@@ -44,7 +44,9 @@
$
cd
../
gitroot
$
git
checkout
-
b
testing
Switched
to
a
new
branch
'
testing
'
$
echo
gg
>>
g
$
git
commit
-
q -a
-
m gg
$
cd
..
/t/s
$
git
pull
-
q
...
...
@@ -46,8 +48,11 @@
$
echo
gg
>>
g
$
git
commit
-
q -a
-
m gg
$
cd
..
/t/s
$
git
pull
-
q
$ git checkout -b testing origin/testing
Switched
to
a
new
branch
'
testing
'
Branch
testing
set
up
to
track
remote
branch
testing
from
origin
.
$
cd
..
$
hg
commit
-
m 'update git subrepo'
...
...
@@ -72,8 +77,7 @@
update
to
previous
substate
$
hg
update
1
checking
out
detached
HEAD
in
subrepo
s
check out a git branc
h
if
you
intend
to
make
changes
Switched
to
a
new
branch
'
master
'
1
files
updated
,
0
files
merged
,
0
files
removed
,
0
files
unresolved
$
cat
s/g
g
...
...
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