##// END OF EJS Templates
tests: unify test-convert-git
Matt Mackall -
r12530:f11793a8 default
parent child Browse files
Show More
@@ -1,186 +1,292 b''
1 #!/bin/sh
2
3 "$TESTDIR/hghave" git || exit 80
4
5 echo "[extensions]" >> $HGRCPATH
6 echo "convert=" >> $HGRCPATH
7 echo 'hgext.graphlog =' >> $HGRCPATH
8
9 GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
10 GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL
11 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE
12 GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME
13 GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
14 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE
15 1
16 count=10
17 commit()
18 {
19 GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000"
20 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
21 git commit "$@" >/dev/null 2>/dev/null || echo "git commit error"
22 count=`expr $count + 1`
23 }
2 $ "$TESTDIR/hghave" git || exit 80
3 $ echo "[extensions]" >> $HGRCPATH
4 $ echo "convert=" >> $HGRCPATH
5 $ echo 'hgext.graphlog =' >> $HGRCPATH
6 $ GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
7 $ GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL
8 $ GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE
9 $ GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME
10 $ GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
11 $ GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE
12 $ count=10
13 $ commit()
14 > {
15 > GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000"
16 > GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
17 > git commit "$@" >/dev/null 2>/dev/null || echo "git commit error"
18 > count=`expr $count + 1`
19 > }
20 $ mkdir git-repo
21 $ cd git-repo
22 $ git init-db >/dev/null 2>/dev/null
23 $ echo a > a
24 $ mkdir d
25 $ echo b > d/b
26 $ git add a d
27 $ commit -a -m t1
24 28
25 mkdir git-repo
26 cd git-repo
27 git init-db >/dev/null 2>/dev/null
28 echo a > a
29 mkdir d
30 echo b > d/b
31 git add a d
32 commit -a -m t1
33
34 # Remove the directory, then try to replace it with a file
35 # (issue 754)
36 git rm -f d/b
37 commit -m t2
38 echo d > d
39 git add d
40 commit -m t3
41
42 echo b >> a
43 commit -a -m t4.1
29 Remove the directory, then try to replace it with a file
30 (issue 754)
44 31
45 git checkout -b other HEAD~ >/dev/null 2>/dev/null
46 echo c > a
47 echo a >> a
48 commit -a -m t4.2
49
50 git checkout master >/dev/null 2>/dev/null
51 git pull --no-commit . other > /dev/null 2>/dev/null
52 commit -m 'Merge branch other'
53 cd ..
32 $ git rm -f d/b
33 rm 'd/b'
34 $ commit -m t2
35 $ echo d > d
36 $ git add d
37 $ commit -m t3
38 $ echo b >> a
39 $ commit -a -m t4.1
40 $ git checkout -b other HEAD~ >/dev/null 2>/dev/null
41 $ echo c > a
42 $ echo a >> a
43 $ commit -a -m t4.2
44 $ git checkout master >/dev/null 2>/dev/null
45 $ git pull --no-commit . other > /dev/null 2>/dev/null
46 $ commit -m 'Merge branch other'
47 $ cd ..
48 $ hg convert --datesort git-repo
49 assuming destination git-repo-hg
50 initializing destination git-repo-hg repository
51 scanning source...
52 sorting...
53 converting...
54 5 t1
55 4 t2
56 3 t3
57 2 t4.1
58 1 t4.2
59 0 Merge branch other
60 $ hg up -q -R git-repo-hg
61 $ hg -R git-repo-hg tip -v
62 changeset: 5:c78094926be2
63 tag: tip
64 parent: 3:f5f5cb45432b
65 parent: 4:4e174f80c67c
66 user: test <test@example.org>
67 date: Mon Jan 01 00:00:15 2007 +0000
68 files: a
69 description:
70 Merge branch other
54 71
55 hg convert --datesort git-repo
56 hg up -q -R git-repo-hg
57 hg -R git-repo-hg tip -v
58
59 count=10
60 mkdir git-repo2
61 cd git-repo2
62 git init-db >/dev/null 2>/dev/null
63
64 echo foo > foo
65 git add foo
66 commit -a -m 'add foo'
67 72
68 echo >> foo
69 commit -a -m 'change foo'
70
71 git checkout -b Bar HEAD~ >/dev/null 2>/dev/null
72 echo quux >> quux
73 git add quux
74 commit -a -m 'add quux'
75
76 echo bar > bar
77 git add bar
78 commit -a -m 'add bar'
73 $ count=10
74 $ mkdir git-repo2
75 $ cd git-repo2
76 $ git init-db >/dev/null 2>/dev/null
77 $ echo foo > foo
78 $ git add foo
79 $ commit -a -m 'add foo'
80 $ echo >> foo
81 $ commit -a -m 'change foo'
82 $ git checkout -b Bar HEAD~ >/dev/null 2>/dev/null
83 $ echo quux >> quux
84 $ git add quux
85 $ commit -a -m 'add quux'
86 $ echo bar > bar
87 $ git add bar
88 $ commit -a -m 'add bar'
89 $ git checkout -b Baz HEAD~ >/dev/null 2>/dev/null
90 $ echo baz > baz
91 $ git add baz
92 $ commit -a -m 'add baz'
93 $ git checkout master >/dev/null 2>/dev/null
94 $ git pull --no-commit . Bar Baz > /dev/null 2>/dev/null
95 $ commit -m 'Octopus merge'
96 $ echo bar >> bar
97 $ commit -a -m 'change bar'
98 $ git checkout -b Foo HEAD~ >/dev/null 2>/dev/null
99 $ echo >> foo
100 $ commit -a -m 'change foo'
101 $ git checkout master >/dev/null 2>/dev/null
102 $ git pull --no-commit -s ours . Foo > /dev/null 2>/dev/null
103 $ commit -m 'Discard change to foo'
104 $ cd ..
105 $ glog()
106 > {
107 > hg glog --template '{rev} "{desc|firstline}" files: {files}\n' "$@"
108 > }
109 $ splitrepo()
110 > {
111 > msg="$1"
112 > files="$2"
113 > opts=$3
114 > echo "% $files: $msg"
115 > prefix=`echo "$files" | sed -e 's/ /-/g'`
116 > fmap="$prefix.fmap"
117 > repo="$prefix.repo"
118 > for i in $files; do
119 > echo "include $i" >> "$fmap"
120 > done
121 > hg -q convert $opts --filemap "$fmap" --datesort git-repo2 "$repo"
122 > hg up -q -R "$repo"
123 > glog -R "$repo"
124 > hg -R "$repo" manifest --debug
125 > }
79 126
80 git checkout -b Baz HEAD~ >/dev/null 2>/dev/null
81 echo baz > baz
82 git add baz
83 commit -a -m 'add baz'
84
85 git checkout master >/dev/null 2>/dev/null
86 git pull --no-commit . Bar Baz > /dev/null 2>/dev/null
87 commit -m 'Octopus merge'
88
89 echo bar >> bar
90 commit -a -m 'change bar'
127 full conversion
91 128
92 git checkout -b Foo HEAD~ >/dev/null 2>/dev/null
93 echo >> foo
94 commit -a -m 'change foo'
95
96 git checkout master >/dev/null 2>/dev/null
97 git pull --no-commit -s ours . Foo > /dev/null 2>/dev/null
98 commit -m 'Discard change to foo'
99
100 cd ..
101
102 glog()
103 {
104 hg glog --template '{rev} "{desc|firstline}" files: {files}\n' "$@"
105 }
129 $ hg -q convert --datesort git-repo2 fullrepo
130 $ hg up -q -R fullrepo
131 $ glog -R fullrepo
132 @ 9 "Discard change to foo" files: foo
133 |\
134 | o 8 "change foo" files: foo
135 | |
136 o | 7 "change bar" files: bar
137 |/
138 o 6 "(octopus merge fixup)" files:
139 |\
140 | o 5 "Octopus merge" files: baz
141 | |\
142 o | | 4 "add baz" files: baz
143 | | |
144 +---o 3 "add bar" files: bar
145 | |
146 o | 2 "add quux" files: quux
147 | |
148 | o 1 "change foo" files: foo
149 |/
150 o 0 "add foo" files: foo
106 151
107 splitrepo()
108 {
109 msg="$1"
110 files="$2"
111 opts=$3
112 echo "% $files: $msg"
113 prefix=`echo "$files" | sed -e 's/ /-/g'`
114 fmap="$prefix.fmap"
115 repo="$prefix.repo"
116 for i in $files; do
117 echo "include $i" >> "$fmap"
118 done
119 hg -q convert $opts --filemap "$fmap" --datesort git-repo2 "$repo"
120 hg up -q -R "$repo"
121 glog -R "$repo"
122 hg -R "$repo" manifest --debug
123 }
152 $ hg -R fullrepo manifest --debug
153 245a3b8bc653999c2b22cdabd517ccb47aecafdf 644 bar
154 354ae8da6e890359ef49ade27b68bbc361f3ca88 644 baz
155 9277c9cc8dd4576fc01a17939b4351e5ada93466 644 foo
156 88dfeab657e8cf2cef3dec67b914f49791ae76b1 644 quux
157 $ splitrepo 'octopus merge' 'foo bar baz'
158 % foo bar baz: octopus merge
159 @ 8 "Discard change to foo" files: foo
160 |\
161 | o 7 "change foo" files: foo
162 | |
163 o | 6 "change bar" files: bar
164 |/
165 o 5 "(octopus merge fixup)" files:
166 |\
167 | o 4 "Octopus merge" files: baz
168 | |\
169 o | | 3 "add baz" files: baz
170 | | |
171 +---o 2 "add bar" files: bar
172 | |
173 | o 1 "change foo" files: foo
174 |/
175 o 0 "add foo" files: foo
124 176
125 echo '% full conversion'
126 hg -q convert --datesort git-repo2 fullrepo
127 hg up -q -R fullrepo
128 glog -R fullrepo
129 hg -R fullrepo manifest --debug
177 245a3b8bc653999c2b22cdabd517ccb47aecafdf 644 bar
178 354ae8da6e890359ef49ade27b68bbc361f3ca88 644 baz
179 9277c9cc8dd4576fc01a17939b4351e5ada93466 644 foo
180 $ splitrepo 'only some parents of an octopus merge; "discard" a head' 'foo baz quux'
181 % foo baz quux: only some parents of an octopus merge; "discard" a head
182 @ 6 "Discard change to foo" files: foo
183 |
184 o 5 "change foo" files: foo
185 |
186 o 4 "Octopus merge" files:
187 |\
188 | o 3 "add baz" files: baz
189 | |
190 | o 2 "add quux" files: quux
191 | |
192 o | 1 "change foo" files: foo
193 |/
194 o 0 "add foo" files: foo
130 195
131 splitrepo 'octopus merge' 'foo bar baz'
196 354ae8da6e890359ef49ade27b68bbc361f3ca88 644 baz
197 9277c9cc8dd4576fc01a17939b4351e5ada93466 644 foo
198 88dfeab657e8cf2cef3dec67b914f49791ae76b1 644 quux
199 $ echo
132 200
133 splitrepo 'only some parents of an octopus merge; "discard" a head' 'foo baz quux'
201
202 test binary conversion (issue 1359)
134 203
135 echo
136 echo '% test binary conversion (issue 1359)'
137 mkdir git-repo3
138 cd git-repo3
139 git init-db >/dev/null 2>/dev/null
140 python -c 'file("b", "wb").write("".join([chr(i) for i in range(256)])*16)'
141 git add b
142 commit -a -m addbinary
143 cd ..
204 $ mkdir git-repo3
205 $ cd git-repo3
206 $ git init-db >/dev/null 2>/dev/null
207 $ python -c 'file("b", "wb").write("".join([chr(i) for i in range(256)])*16)'
208 $ git add b
209 $ commit -a -m addbinary
210 $ cd ..
211
212 convert binary file
144 213
145 echo '% convert binary file'
146 hg convert git-repo3 git-repo3-hg
214 $ hg convert git-repo3 git-repo3-hg
215 initializing destination git-repo3-hg repository
216 scanning source...
217 sorting...
218 converting...
219 0 addbinary
220 $ cd git-repo3-hg
221 $ hg up -C
222 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
223 $ python -c 'print len(file("b", "rb").read())'
224 4096
225 $ cd ..
226 $ echo
227
147 228
148 cd git-repo3-hg
149 hg up -C
150 python -c 'print len(file("b", "rb").read())'
151 cd ..
229 test author vs committer
230
231 $ mkdir git-repo4
232 $ cd git-repo4
233 $ git init-db >/dev/null 2>/dev/null
234 $ echo >> foo
235 $ git add foo
236 $ commit -a -m addfoo
237 $ echo >> foo
238 $ GIT_AUTHOR_NAME="nottest"
239 $ commit -a -m addfoo2
240 $ cd ..
241
242 convert author committer
152 243
153 echo
154 echo '% test author vs committer'
155 mkdir git-repo4
156 cd git-repo4
157 git init-db >/dev/null 2>/dev/null
158 echo >> foo
159 git add foo
160 commit -a -m addfoo
161 echo >> foo
162 GIT_AUTHOR_NAME="nottest"
163 commit -a -m addfoo2
164 cd ..
244 $ hg convert git-repo4 git-repo4-hg
245 initializing destination git-repo4-hg repository
246 scanning source...
247 sorting...
248 converting...
249 1 addfoo
250 0 addfoo2
251 $ hg -R git-repo4-hg log -v
252 changeset: 1:d63e967f93da
253 tag: tip
254 user: nottest <test@example.org>
255 date: Mon Jan 01 00:00:21 2007 +0000
256 files: foo
257 description:
258 addfoo2
165 259
166 echo '% convert author committer'
167 hg convert git-repo4 git-repo4-hg
168 hg -R git-repo4-hg log -v
260 committer: test <test@example.org>
261
169 262
170 echo '% --sourceorder should fail'
171 hg convert --sourcesort git-repo4 git-repo4-sourcesort-hg
263 changeset: 0:0735477b0224
264 user: test <test@example.org>
265 date: Mon Jan 01 00:00:20 2007 +0000
266 files: foo
267 description:
268 addfoo
269
270
271
272 --sourceorder should fail
172 273
173 echo '% damage git repository and convert again'
174 cat > damage.py <<EOF
175 import os
176 for root, dirs, files in os.walk('git-repo4/.git/objects'):
177 if files:
178 path = os.path.join(root, files[0])
179 os.remove(path)
180 break
181 EOF
182 python damage.py
183 hg convert git-repo4 git-repo4-broken-hg 2>&1 | \
184 grep 'abort:' | sed 's/abort:.*/abort:/g'
274 $ hg convert --sourcesort git-repo4 git-repo4-sourcesort-hg
275 initializing destination git-repo4-sourcesort-hg repository
276 abort: --sourcesort is not supported by this data source
277 [255]
278
279 damage git repository and convert again
185 280
186 true
281 $ cat > damage.py <<EOF
282 > import os
283 > for root, dirs, files in os.walk('git-repo4/.git/objects'):
284 > if files:
285 > path = os.path.join(root, files[0])
286 > os.remove(path)
287 > break
288 > EOF
289 $ python damage.py
290 $ hg convert git-repo4 git-repo4-broken-hg 2>&1 | \
291 > grep 'abort:' | sed 's/abort:.*/abort:/g'
292 abort:
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now