##// END OF EJS Templates
git: add test showing `hg commit -i` working on a git repo...
Connor Sheehan -
r46152:f9a3edf2 default
parent child Browse files
Show More
@@ -1,277 +1,358
1 #require pygit2
1 #require pygit2
2
2
3 Setup:
3 Setup:
4 $ GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
4 $ GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
5 > GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL
5 > GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL
6 > GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE
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
7 > GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME
8 > GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
8 > GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
9 > GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE
9 > GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE
10 > count=10
10 > count=10
11 > gitcommit() {
11 > gitcommit() {
12 > GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000";
12 > GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000";
13 > GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
13 > GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
14 > git commit "$@" >/dev/null 2>/dev/null || echo "git commit error"
14 > git commit "$@" >/dev/null 2>/dev/null || echo "git commit error"
15 > count=`expr $count + 1`
15 > count=`expr $count + 1`
16 > }
16 > }
17
17
18
18
19 Test auto-loading extension works:
19 Test auto-loading extension works:
20 $ mkdir nogit
20 $ mkdir nogit
21 $ cd nogit
21 $ cd nogit
22 $ mkdir .hg
22 $ mkdir .hg
23 $ echo git >> .hg/requires
23 $ echo git >> .hg/requires
24 $ hg status
24 $ hg status
25 abort: repository specified git format in .hg/requires but has no .git directory
25 abort: repository specified git format in .hg/requires but has no .git directory
26 [255]
26 [255]
27 $ git init
27 $ git init
28 Initialized empty Git repository in $TESTTMP/nogit/.git/
28 Initialized empty Git repository in $TESTTMP/nogit/.git/
29 This status invocation shows some hg gunk because we didn't use
29 This status invocation shows some hg gunk because we didn't use
30 `hg init --git`, which fixes up .git/info/exclude for us.
30 `hg init --git`, which fixes up .git/info/exclude for us.
31 $ hg status
31 $ hg status
32 ? .hg/cache/git-commits.sqlite
32 ? .hg/cache/git-commits.sqlite
33 ? .hg/cache/git-commits.sqlite-shm
33 ? .hg/cache/git-commits.sqlite-shm
34 ? .hg/cache/git-commits.sqlite-wal
34 ? .hg/cache/git-commits.sqlite-wal
35 ? .hg/requires
35 ? .hg/requires
36 $ cd ..
36 $ cd ..
37
37
38 Now globally enable extension for the rest of the test:
38 Now globally enable extension for the rest of the test:
39 $ cat <<EOF >> $HGRCPATH
39 $ cat <<EOF >> $HGRCPATH
40 > [extensions]
40 > [extensions]
41 > git=
41 > git=
42 > [git]
42 > [git]
43 > log-index-cache-miss = yes
43 > log-index-cache-miss = yes
44 > EOF
44 > EOF
45
45
46 Make a new repo with git:
46 Make a new repo with git:
47 $ mkdir foo
47 $ mkdir foo
48 $ cd foo
48 $ cd foo
49 $ git init
49 $ git init
50 Initialized empty Git repository in $TESTTMP/foo/.git/
50 Initialized empty Git repository in $TESTTMP/foo/.git/
51 Ignore the .hg directory within git:
51 Ignore the .hg directory within git:
52 $ echo .hg >> .git/info/exclude
52 $ echo .hg >> .git/info/exclude
53 $ echo alpha > alpha
53 $ echo alpha > alpha
54 $ git add alpha
54 $ git add alpha
55 $ gitcommit -am 'Add alpha'
55 $ gitcommit -am 'Add alpha'
56 $ echo beta > beta
56 $ echo beta > beta
57 $ git add beta
57 $ git add beta
58 $ gitcommit -am 'Add beta'
58 $ gitcommit -am 'Add beta'
59 $ echo gamma > gamma
59 $ echo gamma > gamma
60 $ git status
60 $ git status
61 On branch master
61 On branch master
62 Untracked files:
62 Untracked files:
63 (use "git add <file>..." to include in what will be committed)
63 (use "git add <file>..." to include in what will be committed)
64 gamma
64 gamma
65
65
66 nothing added to commit but untracked files present (use "git add" to track)
66 nothing added to commit but untracked files present (use "git add" to track)
67
67
68 Without creating the .hg, hg status fails:
68 Without creating the .hg, hg status fails:
69 $ hg status
69 $ hg status
70 abort: no repository found in '$TESTTMP/foo' (.hg not found)!
70 abort: no repository found in '$TESTTMP/foo' (.hg not found)!
71 [255]
71 [255]
72 But if you run hg init --git, it works:
72 But if you run hg init --git, it works:
73 $ hg init --git
73 $ hg init --git
74 $ hg id --traceback
74 $ hg id --traceback
75 heads mismatch, rebuilding dagcache
75 heads mismatch, rebuilding dagcache
76 3d9be8deba43 tip master
76 3d9be8deba43 tip master
77 $ hg status
77 $ hg status
78 ? gamma
78 ? gamma
79 Log works too:
79 Log works too:
80 $ hg log
80 $ hg log
81 changeset: 1:3d9be8deba43
81 changeset: 1:3d9be8deba43
82 bookmark: master
82 bookmark: master
83 tag: tip
83 tag: tip
84 user: test <test@example.org>
84 user: test <test@example.org>
85 date: Mon Jan 01 00:00:11 2007 +0000
85 date: Mon Jan 01 00:00:11 2007 +0000
86 summary: Add beta
86 summary: Add beta
87
87
88 changeset: 0:c5864c9d16fb
88 changeset: 0:c5864c9d16fb
89 user: test <test@example.org>
89 user: test <test@example.org>
90 date: Mon Jan 01 00:00:10 2007 +0000
90 date: Mon Jan 01 00:00:10 2007 +0000
91 summary: Add alpha
91 summary: Add alpha
92
92
93
93
94
94
95 and bookmarks:
95 and bookmarks:
96 $ hg bookmarks
96 $ hg bookmarks
97 * master 1:3d9be8deba43
97 * master 1:3d9be8deba43
98
98
99 diff even works transparently in both systems:
99 diff even works transparently in both systems:
100 $ echo blah >> alpha
100 $ echo blah >> alpha
101 $ git diff
101 $ git diff
102 diff --git a/alpha b/alpha
102 diff --git a/alpha b/alpha
103 index 4a58007..faed1b7 100644
103 index 4a58007..faed1b7 100644
104 --- a/alpha
104 --- a/alpha
105 +++ b/alpha
105 +++ b/alpha
106 @@ -1* +1,2 @@ (glob)
106 @@ -1* +1,2 @@ (glob)
107 alpha
107 alpha
108 +blah
108 +blah
109 $ hg diff --git
109 $ hg diff --git
110 diff --git a/alpha b/alpha
110 diff --git a/alpha b/alpha
111 --- a/alpha
111 --- a/alpha
112 +++ b/alpha
112 +++ b/alpha
113 @@ -1,1 +1,2 @@
113 @@ -1,1 +1,2 @@
114 alpha
114 alpha
115 +blah
115 +blah
116
116
117 Remove a file, it shows as such:
117 Remove a file, it shows as such:
118 $ rm alpha
118 $ rm alpha
119 $ hg status
119 $ hg status
120 ! alpha
120 ! alpha
121 ? gamma
121 ? gamma
122
122
123 Revert works:
123 Revert works:
124 $ hg revert alpha --traceback
124 $ hg revert alpha --traceback
125 $ hg status
125 $ hg status
126 ? gamma
126 ? gamma
127 $ git status
127 $ git status
128 On branch master
128 On branch master
129 Untracked files:
129 Untracked files:
130 (use "git add <file>..." to include in what will be committed)
130 (use "git add <file>..." to include in what will be committed)
131 gamma
131 gamma
132
132
133 nothing added to commit but untracked files present (use "git add" to track)
133 nothing added to commit but untracked files present (use "git add" to track)
134
134
135 Add shows sanely in both:
135 Add shows sanely in both:
136 $ hg add gamma
136 $ hg add gamma
137 $ hg status
137 $ hg status
138 A gamma
138 A gamma
139 $ hg files
139 $ hg files
140 alpha
140 alpha
141 beta
141 beta
142 gamma
142 gamma
143 $ git ls-files
143 $ git ls-files
144 alpha
144 alpha
145 beta
145 beta
146 gamma
146 gamma
147 $ git status
147 $ git status
148 On branch master
148 On branch master
149 Changes to be committed:
149 Changes to be committed:
150 (use "git restore --staged <file>..." to unstage)
150 (use "git restore --staged <file>..." to unstage)
151 new file: gamma
151 new file: gamma
152
152
153
153
154 forget does what it should as well:
154 forget does what it should as well:
155 $ hg forget gamma
155 $ hg forget gamma
156 $ hg status
156 $ hg status
157 ? gamma
157 ? gamma
158 $ git status
158 $ git status
159 On branch master
159 On branch master
160 Untracked files:
160 Untracked files:
161 (use "git add <file>..." to include in what will be committed)
161 (use "git add <file>..." to include in what will be committed)
162 gamma
162 gamma
163
163
164 nothing added to commit but untracked files present (use "git add" to track)
164 nothing added to commit but untracked files present (use "git add" to track)
165
165
166 clean up untracked file
166 clean up untracked file
167 $ rm gamma
167 $ rm gamma
168
168
169 hg log FILE
169 hg log FILE
170
170
171 $ echo a >> alpha
171 $ echo a >> alpha
172 $ hg ci -m 'more alpha' --traceback --date '1583522787 18000'
172 $ hg ci -m 'more alpha' --traceback --date '1583522787 18000'
173 $ echo b >> beta
173 $ echo b >> beta
174 $ hg ci -m 'more beta'
174 $ hg ci -m 'more beta'
175 heads mismatch, rebuilding dagcache
175 heads mismatch, rebuilding dagcache
176 $ echo a >> alpha
176 $ echo a >> alpha
177 $ hg ci -m 'even more alpha'
177 $ hg ci -m 'even more alpha'
178 heads mismatch, rebuilding dagcache
178 heads mismatch, rebuilding dagcache
179 $ hg log -G alpha
179 $ hg log -G alpha
180 heads mismatch, rebuilding dagcache
180 heads mismatch, rebuilding dagcache
181 @ changeset: 4:6626247b7dc8
181 @ changeset: 4:6626247b7dc8
182 : bookmark: master
182 : bookmark: master
183 : tag: tip
183 : tag: tip
184 : user: test <test>
184 : user: test <test>
185 : date: Thu Jan 01 00:00:00 1970 +0000
185 : date: Thu Jan 01 00:00:00 1970 +0000
186 : summary: even more alpha
186 : summary: even more alpha
187 :
187 :
188 o changeset: 2:a1983dd7fb19
188 o changeset: 2:a1983dd7fb19
189 : user: test <test>
189 : user: test <test>
190 : date: Fri Mar 06 14:26:27 2020 -0500
190 : date: Fri Mar 06 14:26:27 2020 -0500
191 : summary: more alpha
191 : summary: more alpha
192 :
192 :
193 o changeset: 0:c5864c9d16fb
193 o changeset: 0:c5864c9d16fb
194 user: test <test@example.org>
194 user: test <test@example.org>
195 date: Mon Jan 01 00:00:10 2007 +0000
195 date: Mon Jan 01 00:00:10 2007 +0000
196 summary: Add alpha
196 summary: Add alpha
197
197
198 $ hg log -G beta
198 $ hg log -G beta
199 o changeset: 3:d8ee22687733
199 o changeset: 3:d8ee22687733
200 : user: test <test>
200 : user: test <test>
201 : date: Thu Jan 01 00:00:00 1970 +0000
201 : date: Thu Jan 01 00:00:00 1970 +0000
202 : summary: more beta
202 : summary: more beta
203 :
203 :
204 o changeset: 1:3d9be8deba43
204 o changeset: 1:3d9be8deba43
205 | user: test <test@example.org>
205 | user: test <test@example.org>
206 ~ date: Mon Jan 01 00:00:11 2007 +0000
206 ~ date: Mon Jan 01 00:00:11 2007 +0000
207 summary: Add beta
207 summary: Add beta
208
208
209
209
210 $ hg log -r "children(3d9be8deba43)" -T"{node|short} {children}\n"
210 $ hg log -r "children(3d9be8deba43)" -T"{node|short} {children}\n"
211 a1983dd7fb19 3:d8ee22687733
211 a1983dd7fb19 3:d8ee22687733
212
212
213 hg annotate
213 hg annotate
214
214
215 $ hg annotate alpha
215 $ hg annotate alpha
216 0: alpha
216 0: alpha
217 2: a
217 2: a
218 4: a
218 4: a
219 $ hg annotate beta
219 $ hg annotate beta
220 1: beta
220 1: beta
221 3: b
221 3: b
222
222
223
223
224 Files in subdirectories. TODO: case-folding support, make this `A`
224 Files in subdirectories. TODO: case-folding support, make this `A`
225 instead of `a`.
225 instead of `a`.
226
226
227 $ mkdir a
227 $ mkdir a
228 $ echo "This is file mu." > a/mu
228 $ echo "This is file mu." > a/mu
229 $ hg ci -A -m 'Introduce file a/mu'
229 $ hg ci -A -m 'Introduce file a/mu'
230 adding a/mu
230 adding a/mu
231
231
232 Both hg and git agree a/mu is part of the repo
232 Both hg and git agree a/mu is part of the repo
233
233
234 $ git ls-files
234 $ git ls-files
235 a/mu
235 a/mu
236 alpha
236 alpha
237 beta
237 beta
238 $ hg files
238 $ hg files
239 a/mu
239 a/mu
240 alpha
240 alpha
241 beta
241 beta
242
242
243 hg and git status both clean
243 hg and git status both clean
244
244
245 $ git status
245 $ git status
246 On branch master
246 On branch master
247 nothing to commit, working tree clean
247 nothing to commit, working tree clean
248 $ hg status
248 $ hg status
249 heads mismatch, rebuilding dagcache
249 heads mismatch, rebuilding dagcache
250
250
251
251
252 node|shortest works correctly
252 node|shortest works correctly
253 $ hg log -T '{node}\n' | sort
253 $ hg log -T '{node}\n' | sort
254 3d9be8deba43482be2c81a4cb4be1f10d85fa8bc
254 3d9be8deba43482be2c81a4cb4be1f10d85fa8bc
255 6626247b7dc8f231b183b8a4761c89139baca2ad
255 6626247b7dc8f231b183b8a4761c89139baca2ad
256 a1983dd7fb19cbd83ad5a1c2fc8bf3d775dea12f
256 a1983dd7fb19cbd83ad5a1c2fc8bf3d775dea12f
257 ae1ab744f95bfd5b07cf573baef98a778058537b
257 ae1ab744f95bfd5b07cf573baef98a778058537b
258 c5864c9d16fb3431fe2c175ff84dc6accdbb2c18
258 c5864c9d16fb3431fe2c175ff84dc6accdbb2c18
259 d8ee22687733a1991813560b15128cd9734f4b48
259 d8ee22687733a1991813560b15128cd9734f4b48
260 $ hg log -r ae1ab744f95bfd5b07cf573baef98a778058537b --template "{shortest(node,1)}\n"
260 $ hg log -r ae1ab744f95bfd5b07cf573baef98a778058537b --template "{shortest(node,1)}\n"
261 ae
261 ae
262
262
263 This coveres changelog.findmissing()
263 This coveres changelog.findmissing()
264 $ hg merge --preview 3d9be8deba43
264 $ hg merge --preview 3d9be8deba43
265
265
266 This covers manifest.diff()
266 This covers manifest.diff()
267 $ hg diff -c 3d9be8deba43
267 $ hg diff -c 3d9be8deba43
268 diff -r c5864c9d16fb -r 3d9be8deba43 beta
268 diff -r c5864c9d16fb -r 3d9be8deba43 beta
269 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
269 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
270 +++ b/beta Mon Jan 01 00:00:11 2007 +0000
270 +++ b/beta Mon Jan 01 00:00:11 2007 +0000
271 @@ -0,0 +1,1 @@
271 @@ -0,0 +1,1 @@
272 +beta
272 +beta
273
273
274
274
275 Interactive commit should work as expected
276
277 $ echo bar >> alpha
278 $ echo bar >> beta
279 $ hg commit -m "test interactive commit" -i --config ui.interactive=true --config ui.interface=text << EOF
280 > y
281 > y
282 > n
283 > EOF
284 diff --git a/alpha b/alpha
285 1 hunks, 1 lines changed
286 examine changes to 'alpha'?
287 (enter ? for help) [Ynesfdaq?] y
288
289 @@ -1,3 +1,4 @@
290 alpha
291 a
292 a
293 +bar
294 record change 1/2 to 'alpha'?
295 (enter ? for help) [Ynesfdaq?] y
296
297 diff --git a/beta b/beta
298 1 hunks, 1 lines changed
299 examine changes to 'beta'?
300 (enter ? for help) [Ynesfdaq?] n
301
302 Status should be consistent for both systems
303
304 $ hg status
305 heads mismatch, rebuilding dagcache
306 M beta
307 $ git status
308 On branch master
309 Changes not staged for commit:
310 (use "git add <file>..." to update what will be committed)
311 (use "git checkout -- <file>..." to discard changes in working directory)
312
313 modified: beta
314
315 no changes added to commit (use "git add" and/or "git commit -a")
316
317 Contents of each commit should be the same
318
319 $ hg ex -r .
320 # HG changeset patch
321 # User test <test>
322 # Date 0 0
323 # Thu Jan 01 00:00:00 1970 +0000
324 # Node ID 80adc61cf57e99f6a412d83fee6239d1556cefcf
325 # Parent ae1ab744f95bfd5b07cf573baef98a778058537b
326 test interactive commit
327
328 diff -r ae1ab744f95b -r 80adc61cf57e alpha
329 --- a/alpha Thu Jan 01 00:00:00 1970 +0000
330 +++ b/alpha Thu Jan 01 00:00:00 1970 +0000
331 @@ -1,3 +1,4 @@
332 alpha
333 a
334 a
335 +bar
336 $ git show
337 commit 80adc61cf57e99f6a412d83fee6239d1556cefcf
338 Author: test <test>
339 Date: Thu Jan 1 00:00:00 1970 +0000
340
341 test interactive commit
342
343 diff --git a/alpha b/alpha
344 index d112a75..d2a2e9a 100644
345 --- a/alpha
346 +++ b/alpha
347 @@ -1,3 +1,4 @@
348 alpha
349 a
350 a
351 +bar
352
275 Deleting files should also work (this was issue6398)
353 Deleting files should also work (this was issue6398)
354 $ hg revert -r . --all
355 reverting beta
276 $ hg rm beta
356 $ hg rm beta
277 $ hg ci -m 'remove beta'
357 $ hg ci -m 'remove beta'
358
General Comments 0
You need to be logged in to leave comments. Login now