1#!/bin/sh
2#
3# Copyright (c) 2012 Felipe Contreras
4#
5# Base commands from hg-git tests:
6# https://bitbucket.org/durin42/hg-git/src
7#
8
9test_description='Test remote-hg'
10
11. ./test-lib.sh
12
13if ! test_have_prereq PYTHON; then
14 skip_all='skipping remote-hg tests; python not available'
15 test_done
16fi
17
18if ! "$PYTHON_PATH" -c 'import mercurial'; then
19 skip_all='skipping remote-hg tests; mercurial not available'
20 test_done
21fi
22
23check () {
24 (cd $1 &&
25 git log --format='%s' -1 &&
26 git symbolic-ref HEAD) > actual &&
27 (echo $2 &&
28 echo "refs/heads/$3") > expected &&
29 test_cmp expected actual
30}
31
32test_expect_success 'cloning' '
33 test_when_finished "rm -rf gitrepo*" &&
34
35 (
36 hg init hgrepo &&
37 cd hgrepo &&
38 echo zero > content &&
39 hg add content &&
40 hg commit -m zero
41 ) &&
42
43 git clone "hg::$PWD/hgrepo" gitrepo &&
44 check gitrepo zero master
45'
46
47test_expect_success 'cloning with branches' '
48 test_when_finished "rm -rf gitrepo*" &&
49
50 (
51 cd hgrepo &&
52 hg branch next &&
53 echo next > content &&
54 hg commit -m next
55 ) &&
56
57 git clone "hg::$PWD/hgrepo" gitrepo &&
58 check gitrepo next next &&
59
60 (cd hgrepo && hg checkout default) &&
61
62 git clone "hg::$PWD/hgrepo" gitrepo2 &&
63 check gitrepo2 zero master
64'
65
66test_expect_success 'cloning with bookmarks' '
67 test_when_finished "rm -rf gitrepo*" &&
68
69 (
70 cd hgrepo &&
71 hg bookmark feature-a &&
72 echo feature-a > content &&
73 hg commit -m feature-a
74 ) &&
75
76 git clone "hg::$PWD/hgrepo" gitrepo &&
77 check gitrepo feature-a feature-a
78'
79
80test_expect_success 'cloning with detached head' '
81 test_when_finished "rm -rf gitrepo*" &&
82
83 (
84 cd hgrepo &&
85 hg update -r 0
86 ) &&
87
88 git clone "hg::$PWD/hgrepo" gitrepo &&
89 check gitrepo zero master
90'
91
92test_expect_success 'update bookmark' '
93 test_when_finished "rm -rf gitrepo*" &&
94
95 (
96 cd hgrepo &&
97 hg bookmark devel
98 ) &&
99
100 (
101 git clone "hg::$PWD/hgrepo" gitrepo &&
102 cd gitrepo &&
103 git checkout devel &&
104 echo devel > content &&
105 git commit -a -m devel &&
106 git push
107 ) &&
108
109 hg -R hgrepo bookmarks | grep "devel\s\+3:"
110'
111
112test_done