remote-hg: always point HEAD to master
Mercurial always checks out the 'default' branch, so there's no point in complicating our lives trying to do something fancier, which causes different behavior depending on whether the repository is local or remote. So let's always use 'default' (which we translate to 'master'), unless we are in hg-git mode, which expects us to use the 'master' bookmark instead. Also, update the tests that used to check for different checkout behaviors to simply check that the refs are there, remove unnecessary ones, and fix the ones that expect something different. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
May 24, 2013 at 21:29 UTC
91347ea3e17b853155f9cab31f0c2a28143284ed
4 files changed
+26
-52
contrib/remote-helpers/git-remote-hg
+13
-17
@@ -560,22 +560,16 @@ def get_branch_tip(repo, branch):
560
return heads[0]
561
562
def list_head(repo, cur):
563
- global g_head, bmarks
563
+ global g_head, bmarks, fake_bmark
564
565
- head = bookmarks.readcurrent(repo)
566
- if head:
567
- node = repo[head]
568
- else:
569
- # fake bookmark from current branch
570
- head = cur
571
- node = repo['.']
572
- if not node:
573
- node = repo['tip']
574
- if not node:
575
- return
576
- if head == 'default':
577
- head = 'master'
578
- bmarks[head] = node
565
+ if 'default' not in repo:
566
+ # empty repo
567
+ return
568
+
569
+ node = repo['default']
570
+ head = 'master' if not 'master' in bmarks else 'default'
571
+ fake_bmark = head
572
+ bmarks[head] = node
573
574
head = gitref(head)
575
print "@refs/heads/%s HEAD" % head
@@ -910,8 +904,8 @@ def do_export(parser):
904
if old == new:
905
continue
906
913
- if bmark == 'master' and 'master' not in parser.repo._bookmarks:
914
- # fake bookmark
907
+ if bmark == fake_bmark or \
908
+ bmark == 'master' and 'master' not in parser.repo._bookmarks:
909
print "ok %s" % ref
910
continue
911
elif bookmarks.pushbookmark(parser.repo, bmark, old, new):
@@ -946,6 +940,7 @@ def main(args):
940
global track_branches, force_push, is_tmp
941
global parsed_tags
942
global filenodes
943
+ global fake_bmark
944
945
alias = args[1]
946
url = args[2]
@@ -979,6 +974,7 @@ def main(args):
974
marks = None
975
parsed_tags = {}
976
filenodes = {}
977
+ fake_bmark = None
978
979
repo = get_repo(url, alias)
980
prefix = 'refs/hg/%s' % alias
contrib/remote-helpers/test-hg-bidi.sh
+4
-5
@@ -29,7 +29,6 @@ git_clone () {
29
hg_clone () {
30
(
31
hg init $2 &&
32
- hg -R $2 bookmark -i master &&
32
cd $1 &&
33
git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
34
) &&
@@ -49,8 +48,7 @@ hg_push () {
48
}
49
50
hg_log () {
52
- hg -R $1 log --graph --debug >log &&
53
- grep -v 'tag: *default/' log
51
+ hg -R $1 log --graph --debug
52
}
53
54
setup () {
@@ -66,6 +64,7 @@ setup () {
64
echo "graphlog ="
65
) >> "$HOME"/.hgrc &&
66
git config --global remote-hg.hg-git-compat true
67
+ git config --global remote-hg.track-branches true
68
69
HGEDITOR=/usr/bin/true
70
GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
@@ -189,7 +188,7 @@ test_expect_success 'hg branch' '
188
hg_clone gitrepo hgrepo &&
189
190
cd hgrepo &&
192
- hg -q co master &&
191
+ hg -q co default &&
192
hg mv alpha beta &&
193
hg -q commit -m "rename alpha to beta" &&
194
hg branch gamma | grep -v "permanent and global" &&
@@ -225,7 +224,7 @@ test_expect_success 'hg tags' '
224
hg_clone gitrepo hgrepo &&
225
226
cd hgrepo &&
228
- hg co master &&
227
+ hg co default &&
228
hg tag alpha
229
) &&
230
contrib/remote-helpers/test-hg-hg-git.sh
+3
-1
@@ -27,7 +27,8 @@ fi
27
28
# clone to a git repo with git
29
git_clone_git () {
30
- git clone -q "hg::$1" $2
30
+ git clone -q "hg::$1" $2 &&
31
+ (cd $2 && git checkout master && git branch -D default)
32
}
33
34
# clone to an hg repo with git
@@ -63,6 +64,7 @@ hg_push_git () {
64
cd $2
65
git checkout -q -b tmp &&
66
git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
67
+ git branch -D default &&
68
git checkout -q @{-1} &&
69
git branch -q -D tmp 2> /dev/null || true
70
)
contrib/remote-helpers/test-hg.sh
+6
-29
@@ -21,15 +21,8 @@ if ! python -c 'import mercurial'; then
21
fi
22
23
check () {
24
- (
25
- cd $1 &&
26
- git log --format='%s' -1 &&
27
- git symbolic-ref HEAD
28
- ) > actual &&
29
- (
30
- echo $2 &&
31
- echo "refs/heads/$3"
32
- ) > expected &&
24
+ echo $3 > expected &&
25
+ git --git-dir=$1/.git log --format='%s' -1 $2 > actual
26
test_cmp expected actual
27
}
28
@@ -56,7 +49,7 @@ test_expect_success 'cloning' '
49
) &&
50
51
git clone "hg::hgrepo" gitrepo &&
59
- check gitrepo zero master
52
+ check gitrepo HEAD zero
53
'
54
55
test_expect_success 'cloning with branches' '
@@ -70,12 +63,7 @@ test_expect_success 'cloning with branches' '
63
) &&
64
65
git clone "hg::hgrepo" gitrepo &&
73
- check gitrepo next next &&
74
-
75
- (cd hgrepo && hg checkout default) &&
76
-
77
- git clone "hg::hgrepo" gitrepo2 &&
78
- check gitrepo2 zero master
66
+ check gitrepo origin/branches/next next
67
'
68
69
test_expect_success 'cloning with bookmarks' '
@@ -83,25 +71,14 @@ test_expect_success 'cloning with bookmarks' '
71
72
(
73
cd hgrepo &&
74
+ hg checkout default &&
75
hg bookmark feature-a &&
76
echo feature-a > content &&
77
hg commit -m feature-a
78
) &&
79
80
git clone "hg::hgrepo" gitrepo &&
92
- check gitrepo feature-a feature-a
93
-'
94
-
95
-test_expect_success 'cloning with detached head' '
96
- test_when_finished "rm -rf gitrepo*" &&
97
-
98
- (
99
- cd hgrepo &&
100
- hg update -r 0
101
- ) &&
102
-
103
- git clone "hg::hgrepo" gitrepo &&
104
- check gitrepo zero master
81
+ check gitrepo origin/feature-a feature-a
82
'
83
84
test_expect_success 'update bookmark' '