remote-hg: always point HEAD to master
[git/gitweb.git] / contrib / remote-helpers / test-hg.sh
blob4d5aba20a090209a6678e1f69f9bf8ad26a03143
1 #!/bin/sh
3 # Copyright (c) 2012 Felipe Contreras
5 # Base commands from hg-git tests:
6 # https://bitbucket.org/durin42/hg-git/src
9 test_description='Test remote-hg'
11 . ./test-lib.sh
13 if ! test_have_prereq PYTHON; then
14 skip_all='skipping remote-hg tests; python not available'
15 test_done
18 if ! python -c 'import mercurial'; then
19 skip_all='skipping remote-hg tests; mercurial not available'
20 test_done
23 check () {
24 echo $3 > expected &&
25 git --git-dir=$1/.git log --format='%s' -1 $2 > actual
26 test_cmp expected actual
29 setup () {
31 echo "[ui]"
32 echo "username = H G Wells <wells@example.com>"
33 echo "[extensions]"
34 echo "mq ="
35 ) >> "$HOME"/.hgrc
38 setup
40 test_expect_success 'cloning' '
41 test_when_finished "rm -rf gitrepo*" &&
44 hg init hgrepo &&
45 cd hgrepo &&
46 echo zero > content &&
47 hg add content &&
48 hg commit -m zero
49 ) &&
51 git clone "hg::hgrepo" gitrepo &&
52 check gitrepo HEAD zero
55 test_expect_success 'cloning with branches' '
56 test_when_finished "rm -rf gitrepo*" &&
59 cd hgrepo &&
60 hg branch next &&
61 echo next > content &&
62 hg commit -m next
63 ) &&
65 git clone "hg::hgrepo" gitrepo &&
66 check gitrepo origin/branches/next next
69 test_expect_success 'cloning with bookmarks' '
70 test_when_finished "rm -rf gitrepo*" &&
73 cd hgrepo &&
74 hg checkout default &&
75 hg bookmark feature-a &&
76 echo feature-a > content &&
77 hg commit -m feature-a
78 ) &&
80 git clone "hg::hgrepo" gitrepo &&
81 check gitrepo origin/feature-a feature-a
84 test_expect_success 'update bookmark' '
85 test_when_finished "rm -rf gitrepo*" &&
88 cd hgrepo &&
89 hg bookmark devel
90 ) &&
93 git clone "hg::hgrepo" gitrepo &&
94 cd gitrepo &&
95 git checkout --quiet devel &&
96 echo devel > content &&
97 git commit -a -m devel &&
98 git push --quiet
99 ) &&
101 hg -R hgrepo bookmarks | egrep "devel[ ]+3:"
104 # cleanup previous stuff
105 rm -rf hgrepo
107 author_test () {
108 echo $1 >> content &&
109 hg commit -u "$2" -m "add $1" &&
110 echo "$3" >> ../expected
113 test_expect_success 'authors' '
114 test_when_finished "rm -rf hgrepo gitrepo" &&
117 hg init hgrepo &&
118 cd hgrepo &&
120 touch content &&
121 hg add content &&
123 > ../expected &&
124 author_test alpha "" "H G Wells <wells@example.com>" &&
125 author_test beta "test" "test <unknown>" &&
126 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
127 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
128 author_test delta "name<test@example.com>" "name <test@example.com>" &&
129 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
130 author_test zeta " test " "test <unknown>" &&
131 author_test eta "test < test@example.com >" "test <test@example.com>" &&
132 author_test theta "test >test@example.com>" "test <test@example.com>" &&
133 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
134 author_test kappa "test@example.com" "Unknown <test@example.com>"
135 ) &&
137 git clone "hg::hgrepo" gitrepo &&
138 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
140 test_cmp expected actual
143 test_expect_success 'strip' '
144 test_when_finished "rm -rf hgrepo gitrepo" &&
147 hg init hgrepo &&
148 cd hgrepo &&
150 echo one >> content &&
151 hg add content &&
152 hg commit -m one &&
154 echo two >> content &&
155 hg commit -m two
156 ) &&
158 git clone "hg::hgrepo" gitrepo &&
161 cd hgrepo &&
162 hg strip 1 &&
164 echo three >> content &&
165 hg commit -m three &&
167 echo four >> content &&
168 hg commit -m four
169 ) &&
172 cd gitrepo &&
173 git fetch &&
174 git log --format="%s" origin/master > ../actual
175 ) &&
177 hg -R hgrepo log --template "{desc}\n" > expected &&
178 test_cmp actual expected
181 test_done