Debian Codegraph @

tests/test-git-interop.t

raw
1 #require pygit2 no-windows missing-correct-output
2
3 Setup:
4 $ GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
5 > GIT_AUTHOR_EMAIL='[email protected]'; export GIT_AUTHOR_EMAIL
6 > GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE
7 > GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME
8 > GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
9 > GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE
10 > HGUSER="test <[email protected]>"; export HGUSER
11 > count=10
12 > gitcommit() {
13 > GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000";
14 > GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
15 > git commit "$@" >/dev/null 2>/dev/null || echo "git commit error"
16 > count=`expr $count + 1`
17 > }
18 $ git config --global init.defaultBranch master
19
20
21 $ hg version -v --config extensions.git= | grep '^[E ]'
22 Enabled extensions:
23 git internal (pygit2 *) (glob)
24
25 Test auto-loading extension works:
26 $ mkdir nogit
27 $ cd nogit
28 $ mkdir .hg
29 $ echo git >> .hg/requires
30 $ hg status
31 abort: repository specified git format in .hg/requires but has no .git directory
32 [255]
33 $ git config --global init.defaultBranch master
34 $ git init
35 Initialized empty Git repository in $TESTTMP/nogit/.git/
36 This status invocation shows some hg gunk because we didn't use
37 `hg init --git`, which fixes up .git/info/exclude for us.
38 $ hg status
39 ? .hg/cache/git-commits.sqlite
40 ? .hg/cache/git-commits.sqlite-shm
41 ? .hg/cache/git-commits.sqlite-wal
42 ? .hg/requires
43 $ cd ..
44
45 Now globally enable extension for the rest of the test:
46 $ cat <<EOF >> $HGRCPATH
47 > [extensions]
48 > git=
49 > [git]
50 > log-index-cache-miss = yes
51 > EOF
52
53 Test some edge cases around a commitless repo first
54 $ mkdir empty
55 $ cd empty
56 $ git init
57 Initialized empty Git repository in $TESTTMP/empty/.git/
58 $ hg init --git
59 $ hg heads
60 [1]
61 $ hg tip
62 changeset: -1:000000000000
63 tag: tip
64 user:
65 date: Thu Jan 01 00:00:00 1970 +0000
66
67 $ cd ..
68
69 Make a new repo with git:
70 $ mkdir foo
71 $ cd foo
72 $ git init
73 Initialized empty Git repository in $TESTTMP/foo/.git/
74 Ignore the .hg directory within git:
75 $ echo .hg >> .git/info/exclude
76 $ echo alpha > alpha
77 $ git add alpha
78 $ gitcommit -am 'Add alpha'
79 $ echo beta > beta
80 $ git add beta
81 $ gitcommit -am 'Add beta'
82 $ echo gamma > gamma
83 $ git status
84 On branch master
85 Untracked files:
86 (use "git add <file>..." to include in what will be committed)
87 (?)
88 gamma
89
90 nothing added to commit but untracked files present (use "git add" to track)
91
92 Without creating the .hg, hg status fails:
93 $ hg status
94 abort: no repository found in '$TESTTMP/foo' (.hg not found)
95 [10]
96 But if you run hg init --git, it works:
97 $ hg init --git
98 $ hg id --traceback
99 heads mismatch, rebuilding dagcache
100 3d9be8deba43 tip master
101 $ hg status
102 ? gamma
103 Log works too:
104 $ hg log
105 changeset: 1:3d9be8deba43
106 bookmark: master
107 tag: tip
108 user: test <[email protected]>
109 date: Mon Jan 01 00:00:11 2007 +0000
110 summary: Add beta
111
112 changeset: 0:c5864c9d16fb
113 user: test <[email protected]>
114 date: Mon Jan 01 00:00:10 2007 +0000
115 summary: Add alpha
116
117
118
119 and bookmarks:
120 $ hg bookmarks
121 * master 1:3d9be8deba43
122 $ hg up master
123 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
124 $ hg bookmarks
125 * master 1:3d9be8deba43
126
127 diff even works transparently in both systems:
128 $ echo blah >> alpha
129 $ git diff
130 diff --git a/alpha b/alpha
131 index 4a58007..faed1b7 100644
132 --- a/alpha
133 +++ b/alpha
134 @@ -1* +1,2 @@ (glob)
135 alpha
136 +blah
137 $ hg diff --git
138 diff --git a/alpha b/alpha
139 --- a/alpha
140 +++ b/alpha
141 @@ -1,1 +1,2 @@
142 alpha
143 +blah
144
145 status --all shows all files, including clean:
146 $ hg status --all
147 M alpha
148 ? gamma
149 C beta
150
151 Remove a file, it shows as such:
152 $ rm alpha
153 $ hg status
154 ! alpha
155 ? gamma
156
157 Revert works:
158 $ hg revert alpha --traceback
159 $ hg status
160 ? gamma
161 $ git status
162 On branch master
163 Untracked files:
164 (use "git add <file>..." to include in what will be committed)
165 (?)
166 gamma
167
168 nothing added to commit but untracked files present (use "git add" to track)
169
170 Add shows sanely in both:
171 $ hg add gamma
172 $ hg status
173 A gamma
174 $ hg files
175 alpha
176 beta
177 gamma
178 $ git ls-files
179 alpha
180 beta
181 gamma
182 $ git status
183 On branch master
184 Changes to be committed:
185 (use "git restore --staged <file>..." to unstage) (?)
186 (use "git reset HEAD <file>..." to unstage) (?)
187 (?)
188 new file: gamma
189
190
191 forget does what it should as well:
192 $ hg forget gamma
193 $ hg status
194 ? gamma
195 $ git status
196 On branch master
197 Untracked files:
198 (use "git add <file>..." to include in what will be committed)
199 (?)
200 gamma
201
202 nothing added to commit but untracked files present (use "git add" to track)
203
204 clean up untracked file
205 $ rm gamma
206
207 hg log FILE
208
209 $ echo a >> alpha
210 $ hg ci -m 'more alpha' --traceback --date '1583558723 18000'
211 $ echo b >> beta
212 $ hg ci -m 'more beta'
213 heads mismatch, rebuilding dagcache
214 $ echo a >> alpha
215 $ hg ci -m 'even more alpha'
216 heads mismatch, rebuilding dagcache
217 $ hg log -G alpha
218 heads mismatch, rebuilding dagcache
219 @ changeset: 4:cf6ddf5d9b8a
220 : bookmark: master
221 : tag: tip
222 : user: test <[email protected]>
223 : date: Thu Jan 01 00:00:00 1970 +0000
224 : summary: even more alpha
225 :
226 o changeset: 2:5b2c80b027ce
227 : user: test <[email protected]>
228 : date: Sat Mar 07 00:25:23 2020 -0500
229 : summary: more alpha
230 :
231 o changeset: 0:c5864c9d16fb
232 user: test <[email protected]>
233 date: Mon Jan 01 00:00:10 2007 +0000
234 summary: Add alpha
235
236 $ hg log -G beta
237 o changeset: 3:980d4f79a9c6
238 : user: test <[email protected]>
239 : date: Thu Jan 01 00:00:00 1970 +0000
240 : summary: more beta
241 :
242 o changeset: 1:3d9be8deba43
243 | user: test <[email protected]>
244 ~ date: Mon Jan 01 00:00:11 2007 +0000
245 summary: Add beta
246
247
248 $ hg log -r "children(3d9be8deba43)" -T"{node|short} {children}\n"
249 5b2c80b027ce 3:980d4f79a9c6
250
251 hg annotate
252
253 $ hg annotate alpha
254 0: alpha
255 2: a
256 4: a
257 $ hg annotate beta
258 1: beta
259 3: b
260
261
262 Files in subdirectories. TODO: case-folding support, make this `A`
263 instead of `a`.
264
265 $ mkdir a
266 $ echo "This is file mu." > a/mu
267 $ hg ci -A -m 'Introduce file a/mu'
268 adding a/mu
269
270 Both hg and git agree a/mu is part of the repo
271
272 $ git ls-files
273 a/mu
274 alpha
275 beta
276 $ hg files
277 a/mu
278 alpha
279 beta
280
281 hg and git status both clean
282
283 $ git status
284 On branch master
285 nothing to commit, working tree clean
286 $ hg status
287 heads mismatch, rebuilding dagcache
288
289
290 node|shortest works correctly
291 $ hg log -T '{node}\n' | sort
292 3d9be8deba43482be2c81a4cb4be1f10d85fa8bc
293 5b2c80b027ce4250f88957326c199a2dc48dad60
294 980d4f79a9c617d60d0fe1fb383753c4a61bea8e
295 c1a41c49866ecc9c5411be932653e5b430961dd5
296 c5864c9d16fb3431fe2c175ff84dc6accdbb2c18
297 cf6ddf5d9b8a120bf90020342bcf7a96d0167279
298 $ hg log -r c1a41c49866ecc9c5411be932653e5b430961dd5 --template "{shortest(node,1)}\n"
299 c1
300
301 This covers gitlog._partialmatch()
302 $ hg log -r c
303 abort: ambiguous revision identifier: c
304 [10]
305 $ hg log -r c1
306 changeset: 5:c1a41c49866e
307 bookmark: master
308 tag: tip
309 user: test <[email protected]>
310 date: Thu Jan 01 00:00:00 1970 +0000
311 summary: Introduce file a/mu
312
313 $ hg log -r dead
314 abort: unknown revision 'dead'
315 [10]
316
317 This coveres changelog.findmissing()
318 $ hg merge --preview 3d9be8deba43
319
320 This covers manifest.diff()
321 $ hg diff -c 3d9be8deba43
322 diff -r c5864c9d16fb -r 3d9be8deba43 beta
323 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
324 +++ b/beta Mon Jan 01 00:00:11 2007 +0000
325 @@ -0,0 +1,1 @@
326 +beta
327
328
329 Interactive commit should work as expected
330
331 $ echo bar >> alpha
332 $ echo bar >> beta
333 $ hg commit -m "test interactive commit" -i --config ui.interactive=true --config ui.interface=text << EOF
334 > y
335 > y
336 > n
337 > EOF
338 diff --git a/alpha b/alpha
339 1 hunks, 1 lines changed
340 examine changes to 'alpha'?
341 (enter ? for help) [Ynesfdaq?] y
342
343 @@ -1,3 +1,4 @@
344 alpha
345 a
346 a
347 +bar
348 record change 1/2 to 'alpha'?
349 (enter ? for help) [Ynesfdaq?] y
350
351 diff --git a/beta b/beta
352 1 hunks, 1 lines changed
353 examine changes to 'beta'?
354 (enter ? for help) [Ynesfdaq?] n
355
356 Status should be consistent for both systems
357
358 $ hg status
359 heads mismatch, rebuilding dagcache
360 M beta
361 $ git status | grep -E -v '^$|^ \(use '
362 On branch master
363 Changes not staged for commit:
364 modified: beta
365 no changes added to commit (use "git add" and/or "git commit -a")
366
367 Contents of each commit should be the same
368
369 $ hg ex -r .
370 # HG changeset patch
371 # User test <[email protected]>
372 # Date 0 0
373 # Thu Jan 01 00:00:00 1970 +0000
374 # Node ID 6024eda7986da123aa6797dd4603bd399d49bf5c
375 # Parent c1a41c49866ecc9c5411be932653e5b430961dd5
376 test interactive commit
377
378 diff -r c1a41c49866e -r 6024eda7986d alpha
379 --- a/alpha Thu Jan 01 00:00:00 1970 +0000
380 +++ b/alpha Thu Jan 01 00:00:00 1970 +0000
381 @@ -1,3 +1,4 @@
382 alpha
383 a
384 a
385 +bar
386 $ git show
387 commit 6024eda7986da123aa6797dd4603bd399d49bf5c
388 Author: test <[email protected]>
389 Date: Thu Jan 1 00:00:00 1970 +0000
390
391 test interactive commit
392
393 diff --git a/alpha b/alpha
394 index d112a75..d2a2e9a 100644
395 --- a/alpha
396 +++ b/alpha
397 @@ -1,3 +1,4 @@
398 alpha
399 a
400 a
401 +bar
402
403 Deleting files should also work (this was issue6398)
404 $ hg revert -r . --all
405 reverting beta
406 $ hg rm beta
407 $ hg ci -m 'remove beta'
408
409 This covers changelog.tiprev() (issue6510)
410 $ hg log -r '(.^^):'
411 heads mismatch, rebuilding dagcache
412 changeset: 5:c1a41c49866e
413 user: test <[email protected]>
414 date: Thu Jan 01 00:00:00 1970 +0000
415 summary: Introduce file a/mu
416
417 changeset: 6:6024eda7986d
418 user: test <[email protected]>
419 date: Thu Jan 01 00:00:00 1970 +0000
420 summary: test interactive commit
421
422 changeset: 7:1a0fee76bfc4
423 bookmark: master
424 tag: tip
425 user: test <[email protected]>
426 date: Thu Jan 01 00:00:00 1970 +0000
427 summary: remove beta
428
429 This covers changelog.headrevs() with a non-None arg
430 $ hg log -r 'heads(.)' -Tcompact
431 7[tip][master] 1a0fee76bfc4 1970-01-01 00:00 +0000 test
432 remove beta
433
434 This covers revlog.findmissingrevs() (issue6472)
435 $ hg log -r 'last(only(master))' -Tcompact
436 7[tip][master] 1a0fee76bfc4 1970-01-01 00:00 +0000 test
437 remove beta
438