Debian Codegraph @

tests/test-journal.t

raw
1 Tests for the journal extension; records bookmark locations.
2
3 $ cat >> testmocks.py << EOF
4 > # mock out procutil.getuser() and util.makedate() to supply testable values
5 > import os
6 > from mercurial import pycompat, util
7 > from mercurial.utils import dateutil, procutil
8 > def mockgetuser():
9 > return b'foobar'
10 >
11 > def mockmakedate():
12 > filename = os.path.join(os.environ['TESTTMP'], 'testtime')
13 > try:
14 > with open(filename, 'rb') as timef:
15 > time = float(timef.read()) + 1
16 > except IOError:
17 > time = 0.0
18 > with open(filename, 'wb') as timef:
19 > timef.write(pycompat.bytestr(time))
20 > return (time, 0)
21 >
22 > procutil.getuser = mockgetuser
23 > dateutil.makedate = mockmakedate
24 > EOF
25
26 $ cat >> $HGRCPATH << EOF
27 > [extensions]
28 > journal=
29 > testmocks=`pwd`/testmocks.py
30 > EOF
31
32 Setup repo
33
34 $ hg init repo
35 $ cd repo
36
37 Test empty journal
38
39 $ hg journal
40 previous locations of '.':
41 no recorded locations
42 $ hg journal foo
43 previous locations of 'foo':
44 no recorded locations
45
46 Test that working copy changes are tracked
47
48 $ echo a > a
49 $ hg commit -Aqm a
50 $ hg journal
51 previous locations of '.':
52 cb9a9f314b8b commit -Aqm a
53 $ echo b > a
54 $ hg commit -Aqm b
55 $ hg journal
56 previous locations of '.':
57 1e6c11564562 commit -Aqm b
58 cb9a9f314b8b commit -Aqm a
59 $ hg up 0
60 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
61 $ hg journal
62 previous locations of '.':
63 cb9a9f314b8b up 0
64 1e6c11564562 commit -Aqm b
65 cb9a9f314b8b commit -Aqm a
66
67 Test that bookmarks are tracked
68
69 $ hg book -r tip bar
70 $ hg journal bar
71 previous locations of 'bar':
72 1e6c11564562 book -r tip bar
73 $ hg book -f bar
74 $ hg journal bar
75 previous locations of 'bar':
76 cb9a9f314b8b book -f bar
77 1e6c11564562 book -r tip bar
78 $ hg up
79 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
80 updating bookmark bar
81 $ hg journal bar
82 previous locations of 'bar':
83 1e6c11564562 up
84 cb9a9f314b8b book -f bar
85 1e6c11564562 book -r tip bar
86
87 Test that we tracks bookmark deletion
88
89 $ hg book -r . babar
90 $ hg book -f -r .~1 babar
91 $ hg book -d babar
92 $ hg journal babar
93 previous locations of 'babar':
94 000000000000 book -d babar
95 cb9a9f314b8b book -f -r ?.~1? babar (glob)
96 1e6c11564562 book -r . babar
97
98 Test that bookmarks and working copy tracking is not mixed
99
100 $ hg journal
101 previous locations of '.':
102 1e6c11564562 up
103 cb9a9f314b8b up 0
104 1e6c11564562 commit -Aqm b
105 cb9a9f314b8b commit -Aqm a
106
107 Test that you can list all entries as well as limit the list or filter on them
108
109 $ hg book -r tip baz
110 $ hg journal --all
111 previous locations of the working copy and bookmarks:
112 1e6c11564562 baz book -r tip baz
113 000000000000 babar book -d babar
114 cb9a9f314b8b babar book -f -r ?.~1? babar (glob)
115 1e6c11564562 babar book -r . babar
116 1e6c11564562 bar up
117 1e6c11564562 . up
118 cb9a9f314b8b bar book -f bar
119 1e6c11564562 bar book -r tip bar
120 cb9a9f314b8b . up 0
121 1e6c11564562 . commit -Aqm b
122 cb9a9f314b8b . commit -Aqm a
123 $ hg journal --limit 2
124 previous locations of '.':
125 1e6c11564562 up
126 cb9a9f314b8b up 0
127 $ hg journal bar
128 previous locations of 'bar':
129 1e6c11564562 up
130 cb9a9f314b8b book -f bar
131 1e6c11564562 book -r tip bar
132 $ hg journal foo
133 previous locations of 'foo':
134 no recorded locations
135 $ hg journal .
136 previous locations of '.':
137 1e6c11564562 up
138 cb9a9f314b8b up 0
139 1e6c11564562 commit -Aqm b
140 cb9a9f314b8b commit -Aqm a
141 $ hg journal "re:ba."
142 previous locations of 're:ba.':
143 1e6c11564562 baz book -r tip baz
144 000000000000 babar book -d babar
145 cb9a9f314b8b babar book -f -r ?.~1? babar (glob)
146 1e6c11564562 babar book -r . babar
147 1e6c11564562 bar up
148 cb9a9f314b8b bar book -f bar
149 1e6c11564562 bar book -r tip bar
150
151 Test that verbose, JSON, template and commit output work
152
153 $ hg journal --verbose --all
154 previous locations of the working copy and bookmarks:
155 000000000000 -> 1e6c11564562 foobar baz 1970-01-01 00:00 +0000 book -r tip baz
156 cb9a9f314b8b -> 000000000000 foobar babar 1970-01-01 00:00 +0000 book -d babar
157 1e6c11564562 -> cb9a9f314b8b foobar babar 1970-01-01 00:00 +0000 book -f -r ?.~1? babar (glob)
158 000000000000 -> 1e6c11564562 foobar babar 1970-01-01 00:00 +0000 book -r . babar
159 cb9a9f314b8b -> 1e6c11564562 foobar bar 1970-01-01 00:00 +0000 up
160 cb9a9f314b8b -> 1e6c11564562 foobar . 1970-01-01 00:00 +0000 up
161 1e6c11564562 -> cb9a9f314b8b foobar bar 1970-01-01 00:00 +0000 book -f bar
162 000000000000 -> 1e6c11564562 foobar bar 1970-01-01 00:00 +0000 book -r tip bar
163 1e6c11564562 -> cb9a9f314b8b foobar . 1970-01-01 00:00 +0000 up 0
164 cb9a9f314b8b -> 1e6c11564562 foobar . 1970-01-01 00:00 +0000 commit -Aqm b
165 000000000000 -> cb9a9f314b8b foobar . 1970-01-01 00:00 +0000 commit -Aqm a
166 $ hg journal --verbose -Tjson
167 [
168 {
169 "command": "up",
170 "date": [5, 0],
171 "name": ".",
172 "newnodes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
173 "oldnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
174 "user": "foobar"
175 },
176 {
177 "command": "up 0",
178 "date": [2, 0],
179 "name": ".",
180 "newnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
181 "oldnodes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
182 "user": "foobar"
183 },
184 {
185 "command": "commit -Aqm b",
186 "date": [1, 0],
187 "name": ".",
188 "newnodes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
189 "oldnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
190 "user": "foobar"
191 },
192 {
193 "command": "commit -Aqm a",
194 "date": [0, 0],
195 "name": ".",
196 "newnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
197 "oldnodes": ["0000000000000000000000000000000000000000"],
198 "user": "foobar"
199 }
200 ]
201
202 $ cat <<EOF >> $HGRCPATH
203 > [templates]
204 > j = "{oldnodes % '{node|upper}'} -> {newnodes % '{node|upper}'}
205 > - user: {user}
206 > - command: {command}
207 > - date: {date|rfc3339date}
208 > - newnodes: {newnodes}
209 > - oldnodes: {oldnodes}
210 > "
211 > EOF
212 $ hg journal -Tj -l1
213 previous locations of '.':
214 CB9A9F314B8B07BA71012FCDBC544B5A4D82FF5B -> 1E6C11564562B4ED919BACA798BC4338BD299D6A
215 - user: foobar
216 - command: up
217 - date: 1970-01-01T00:00:05+00:00
218 - newnodes: 1e6c11564562b4ed919baca798bc4338bd299d6a
219 - oldnodes: cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
220
221 $ hg journal --commit
222 previous locations of '.':
223 1e6c11564562 up
224 changeset: 1:1e6c11564562
225 bookmark: bar
226 bookmark: baz
227 tag: tip
228 user: test
229 date: Thu Jan 01 00:00:00 1970 +0000
230 summary: b
231
232 cb9a9f314b8b up 0
233 changeset: 0:cb9a9f314b8b
234 user: test
235 date: Thu Jan 01 00:00:00 1970 +0000
236 summary: a
237
238 1e6c11564562 commit -Aqm b
239 changeset: 1:1e6c11564562
240 bookmark: bar
241 bookmark: baz
242 tag: tip
243 user: test
244 date: Thu Jan 01 00:00:00 1970 +0000
245 summary: b
246
247 cb9a9f314b8b commit -Aqm a
248 changeset: 0:cb9a9f314b8b
249 user: test
250 date: Thu Jan 01 00:00:00 1970 +0000
251 summary: a
252
253
254 $ hg journal --commit -Tjson
255 [
256 {
257 "changesets": [{"bookmarks": ["bar", "baz"], "branch": "default", "date": [0, 0], "desc": "b", "node": "1e6c11564562b4ed919baca798bc4338bd299d6a", "parents": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"], "phase": "draft", "rev": 1, "tags": ["tip"], "user": "test"}],
258 "command": "up",
259 "date": [5, 0],
260 "name": ".",
261 "newnodes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
262 "oldnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
263 "user": "foobar"
264 },
265 {
266 "changesets": [{"bookmarks": [], "branch": "default", "date": [0, 0], "desc": "a", "node": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b", "parents": ["0000000000000000000000000000000000000000"], "phase": "draft", "rev": 0, "tags": [], "user": "test"}],
267 "command": "up 0",
268 "date": [2, 0],
269 "name": ".",
270 "newnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
271 "oldnodes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
272 "user": "foobar"
273 },
274 {
275 "changesets": [{"bookmarks": ["bar", "baz"], "branch": "default", "date": [0, 0], "desc": "b", "node": "1e6c11564562b4ed919baca798bc4338bd299d6a", "parents": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"], "phase": "draft", "rev": 1, "tags": ["tip"], "user": "test"}],
276 "command": "commit -Aqm b",
277 "date": [1, 0],
278 "name": ".",
279 "newnodes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
280 "oldnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
281 "user": "foobar"
282 },
283 {
284 "changesets": [{"bookmarks": [], "branch": "default", "date": [0, 0], "desc": "a", "node": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b", "parents": ["0000000000000000000000000000000000000000"], "phase": "draft", "rev": 0, "tags": [], "user": "test"}],
285 "command": "commit -Aqm a",
286 "date": [0, 0],
287 "name": ".",
288 "newnodes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
289 "oldnodes": ["0000000000000000000000000000000000000000"],
290 "user": "foobar"
291 }
292 ]
293
294 $ hg journal --commit \
295 > -T'command: {command}\n{changesets % " rev: {rev}\n children: {children}\n"}'
296 previous locations of '.':
297 command: up
298 rev: 1
299 children:
300 command: up 0
301 rev: 0
302 children: 1:1e6c11564562
303 command: commit -Aqm b
304 rev: 1
305 children:
306 command: commit -Aqm a
307 rev: 0
308 children: 1:1e6c11564562
309
310 Test for behaviour on unexpected storage version information
311
312 $ printf '42\0' > .hg/namejournal
313 $ hg journal
314 previous locations of '.':
315 abort: unknown journal file version '42'
316 [255]
317 $ hg book -r tip doomed
318 unsupported journal file version '42'