File: test-bundle.t

package info (click to toggle)
hg-git 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,244 kB
  • sloc: python: 8,702; sh: 185; makefile: 23
file content (282 lines) | stat: -rw-r--r-- 8,114 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
 Load commonly used test logic
  $ . "$TESTDIR/testutil"

Enable bundling, and add a nice template for inspecting Git state.

  $ cat >> $HGRCPATH <<EOF
  > [experimental]
  > hg-git-bundle = yes
  > [templates]
  > git = {rev}:{node|short} | {gitnode|short} | {tags} |\n
  > EOF

Create a Git repository containing a couple of commits and two non-tip
tags:

  $ git init gitrepo
  Initialized empty Git repository in $TESTTMP/gitrepo/.git/
  $ cd gitrepo
  $ echo alpha > alpha
  $ git add alpha
  $ fn_git_commit -m 'add alpha'
  $ git tag thetag
  $ echo beta > beta
  $ git add beta
  $ fn_git_commit -m 'add beta'
  $ git tag -m 'an annotated tag' theothertag
  $ echo gamma > gamma
  $ git add gamma
  $ git add .
  $ fn_git_commit -m 'add gamma'
  $ git tag -ln
  theothertag     an annotated tag
  thetag          add alpha
  $ cd ..

Clone it!

  $ hg clone gitrepo hgrepo
  importing 3 git commits
  new changesets ff7a2f2d8d70:ca33a262eb46 (3 drafts)
  updating to bookmark master
  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cd hgrepo

Create a bundle with our metadata, and inspect it:

  $ hg bundle --all ../bundle-w-git.hg
  3 changesets found
  $ hg debugbundle --all ../bundle-w-git.hg | grep hg-git
  exp-hg-git-map -- {} (mandatory: False)
  exp-hg-git-tags -- {} (mandatory: False)
  $ hg debugbundle --all ../bundle-w-git.hg > bundle-w-git.out

Create a bundle without our metadata, and inspect it:

  $ hg bundle --all ../bundle-wo-git.hg --config experimental.hg-git-bundle=no
  3 changesets found
  $ hg debugbundle --all ../bundle-wo-git.hg | grep hg-git
  [1]

Verify that those are different:

  $ hg debugbundle --all ../bundle-wo-git.hg > bundle-wo-git.out
  $ cmp -s bundle-w-git.out bundle-wo-git.out
  [1]

Now create a bundle without hg-git enabled at all, which should be
exactly similar to what you get when you disable metadata embedding;
this verifies we don't accidentally pollute bundles.

  $ hg bundle --all  --config extensions.hggit=! ../bundle-wo-hggit.hg
  3 changesets found
  $ hg debugbundle --all ../bundle-wo-hggit.hg > bundle-wo-hggit.out
  $ cmp -s bundle-wo-git.hg bundle-wo-hggit.hg
  [2]
  $ cmp -s bundle-wo-git.out bundle-wo-hggit.out
  $ cd ..
  $ rm -r hgrepo

Does unbundling transfer state?

  $ hg init hgrepo
  $ hg -R hgrepo unbundle bundle-w-git.hg
  adding changesets
  adding manifests
  adding file changes
  added 3 changesets with 3 changes to 3 files
  new changesets * (glob)
  (run 'hg update' to get a working copy)
  $ hg -R hgrepo log -T git
  2:ca33a262eb46 | d338971a96e2 | tip |
  1:7fe02317c63d | 9497a4ee62e1 | theothertag |
  0:ff7a2f2d8d70 | 7eeab2ea75ec | thetag |
  $ hg -R hgrepo pull gitrepo
  pulling from gitrepo
  warning: created new git repository at $TESTTMP/hgrepo/.hg/git
  no changes found
  adding bookmark master
  $ rm -r hgrepo

Can we unbundle something without git state?

  $ hg init hgrepo
  $ hg -R hgrepo unbundle bundle-wo-git.hg
  adding changesets
  adding manifests
  adding file changes
  added 3 changesets with 3 changes to 3 files
  new changesets * (glob)
  (run 'hg update' to get a working copy)
  $ hg -R hgrepo log -T git
  2:ca33a262eb46 |  | tip |
  1:7fe02317c63d |  |  |
  0:ff7a2f2d8d70 |  |  |
  $ hg -R hgrepo pull gitrepo
  pulling from gitrepo
  importing 3 git commits
  adding bookmark master
  (run 'hg update' to get a working copy)
  $ rm -r hgrepo

Regular mercurial shouldn't choke on our bundle

  $ hg init hgrepo
  $ cat >> hgrepo/.hg/hgrc <<EOF
  > [extensions]
  > hggit = !
  > EOF
  $ hg -R hgrepo unbundle bundle-wo-git.hg
  adding changesets
  adding manifests
  adding file changes
  added 3 changesets with 3 changes to 3 files
  new changesets * (glob)
  (run 'hg update' to get a working copy)
  $ hg -R hgrepo log -T git
  2:ca33a262eb46 |  | tip |
  1:7fe02317c63d |  |  |
  0:ff7a2f2d8d70 |  |  |
  $ hg -R hgrepo pull gitrepo
  pulling from gitrepo
  abort: repository gitrepo not found!? (re)
  [255]
  $ rm -r hgrepo


What happens if we unbundle twice?

  $ hg init hgrepo
  $ hg -R hgrepo unbundle bundle-w-git.hg
  adding changesets
  adding manifests
  adding file changes
  added 3 changesets with 3 changes to 3 files
  new changesets * (glob)
  (run 'hg update' to get a working copy)
  $ hg -R hgrepo unbundle bundle-w-git.hg
  adding changesets
  adding manifests
  adding file changes
  added 0 changesets with 0 changes to 3 files
  (run 'hg update' to get a working copy)
  $ hg -R hgrepo log -T git
  2:ca33a262eb46 | d338971a96e2 | tip |
  1:7fe02317c63d | 9497a4ee62e1 | theothertag |
  0:ff7a2f2d8d70 | 7eeab2ea75ec | thetag |
  $ hg -R hgrepo pull gitrepo
  pulling from gitrepo
  warning: created new git repository at $TESTTMP/hgrepo/.hg/git
  no changes found
  adding bookmark master
  $ rm -r hgrepo

Alas, cloning a bundle doesn't work yet:

(Mercurial is apparently quite dumb here, so we won't try to fix this
for now, but this test mostly exists so that we notice if ever starts
working, or breaks entirely.)

  $ hg clone bundle-w-git.hg hgrepo
  requesting all changes
  adding changesets
  adding manifests
  adding file changes
  added 3 changesets with 3 changes to 3 files
  new changesets * (glob)
  updating to branch default
  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg -R hgrepo log -T git
  2:ca33a262eb46 |  | tip |
  1:7fe02317c63d |  |  |
  0:ff7a2f2d8d70 |  |  |
  $ rm -r hgrepo

Now, lets try to be a bit evil. How does pulling partial state work?

First, more git happenings:

  $ cd gitrepo
  $ git checkout -b otherbranch thetag
  Switched to a new branch 'otherbranch'
  $ echo 42 > baz
  $ git add baz
  $ fn_git_commit -m 3
  $ cd ..

Pull, 'em, and create a partial bundle:

  $ hg clone gitrepo hgrepo
  importing 4 git commits
  new changesets ff7a2f2d8d70:d87bf3ef6a53 (4 drafts)
  updating to bookmark otherbranch
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg -R hgrepo bundle --base 'p1(tip)' -r tip bundle-w-git-2.hg
  1 changesets found
  $ rm -r hgrepo

Now, load only that bundle into a repository without any git state

  $ hg clone -r 1 bundle-w-git.hg hgrepo --config extensions.hggit=!
  adding changesets
  adding manifests
  adding file changes
  added 2 changesets with 2 changes to 2 files
  new changesets * (glob)
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cd hgrepo
  $ hg unbundle ../bundle-w-git-2.hg
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
  new changesets * (glob)
  (run 'hg heads' to see heads, 'hg merge' to merge)
  $ hg pull ../gitrepo
  pulling from ../gitrepo
  warning: created new git repository at $TESTTMP/hgrepo/.hg/git
  importing 3 git commits
  adding bookmark master
  adding bookmark otherbranch
  new changesets ca33a262eb46 (1 drafts)
  (run 'hg update' to get a working copy)
  $ cd ..
  $ rm -r hgrepo

Now, try pushing with only the metadata:

  $ hg init hgrepo
  $ cd hgrepo
  $ hg unbundle -u ../bundle-w-git.hg
  adding changesets
  adding manifests
  adding file changes
  added 3 changesets with 3 changes to 3 files
  new changesets * (glob)
  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ echo kaflaflibob > bajizmo
  $ fn_hg_commit -A -m 4
  $ hg book -r tip master
  $ hg push ../gitrepo
  pushing to ../gitrepo
  warning: created new git repository at $TESTTMP/hgrepo/.hg/git
  abort: cannot push git commit d338971a96e2 as it is not present locally
  (please try pulling first, or as a fallback run git-cleanup to re-export the missing commits)
  [255]

Try to repopulate the git state from a bundle

  $ hg debug-remove-hggit-state
  clearing out the git cache data
  $ hg log -qr 'fromgit()'
  $ hg unbundle -u ../bundle-w-git.hg
  adding changesets
  adding manifests
  adding file changes
  added 0 changesets with 0 changes to 3 files
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg log -qr 'fromgit()'
  0:ff7a2f2d8d70
  1:7fe02317c63d
  2:ca33a262eb46