@matheusbsbs / matheus-bagliano / commits / 2e0afafebd
Fork 0

Add git-bundle: move objects and references by archive

Some workflows require use of repositories on machines that cannot be connected, preventing use of git-fetch / git-push to transport objects and references between the repositories. git-bundle provides an alternate transport mechanism, effectively allowing git-fetch and git-pull to operate using sneakernet transport. `git-bundle create` allows the user to create a bundle containing one or more branches or tags, but with specified basis assumed to exist on the target repository. At the receiving end, git-bundle acts like git-fetch-pack, allowing the user to invoke git-fetch or git-pull using the bundle file as the URL. git-fetch and git-ls-remote determine they have a bundle URL by checking that the URL points to a file, but are otherwise unchanged in operation with bundles. The original patch was done by Mark Levedahl <mdl123@verizon.net>. It was updated to make git-bundle a builtin, and get rid of the tar format: now, the first line is supposed to say "# v2 git bundle", the next lines either contain a prerequisite ("-" followed by the hash of the needed commit), or a ref (the hash of a commit, followed by the name of the ref), and finally the pack. As a result, the bundle argument can be "-" now. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Feb 22, 2007 at 01:59 UTC 2e0afafebd8c5a1a8cdddb0714073461229ecfef
11 files changed +575 -4
.gitignore
+1
@@ -13,6 +13,7 @@ git-archive
13 git-bisect
14 git-blame
15 git-branch
16 +git-bundle
17 git-cat-file
18 git-check-ref-format
19 git-checkout
Documentation/cmd-list.perl
+1
@@ -70,6 +70,7 @@ git-archive mainporcelain
70 git-bisect mainporcelain
71 git-blame ancillaryinterrogators
72 git-branch mainporcelain
73 +git-bundle mainporcelain
74 git-cat-file plumbinginterrogators
75 git-checkout-index plumbingmanipulators
76 git-checkout mainporcelain
Documentation/git-bundle.txt new
+139
@@ -0,0 +1,139 @@
1 +git-bundle(1)
2 +=============
3 +
4 +NAME
5 +----
6 +git-bundle - Move objects and refs by archive
7 +
8 +
9 +SYNOPSIS
10 +--------
11 +'git-bundle' create <file> [git-rev-list args]
12 +'git-bundle' verify <file>
13 +'git-bundle' list-heads <file> [refname...]
14 +'git-bundle' unbundle <file> [refname...]
15 +
16 +DESCRIPTION
17 +-----------
18 +
19 +Some workflows require that one or more branches of development on one
20 +machine be replicated on another machine, but the two machines cannot
21 +be directly connected so the interactive git protocols (git, ssh,
22 +rsync, http) cannot be used. This command provides suport for
23 +git-fetch and git-pull to operate by packaging objects and references
24 +in an archive at the originating machine, then importing those into
25 +another repository using gitlink:git-fetch[1] and gitlink:git-pull[1]
26 +after moving the archive by some means (i.e., by sneakernet). As no
27 +direct connection between repositories exists, the user must specify a
28 +basis for the bundle that is held by the destination repository: the
29 +bundle assumes that all objects in the basis are already in the
30 +destination repository.
31 +
32 +OPTIONS
33 +-------
34 +
35 +create <file>::
36 + Used to create a bundle named 'file'. This requires the
37 + git-rev-list arguments to define the bundle contents.
38 +
39 +verify <file>::
40 + Used to check that a bundle file is valid and will apply
41 + cleanly to the current repository. This includes checks on the
42 + bundle format itself as well as checking that the prerequisite
43 + commits exist and are fully linked in the current repository.
44 + git-bundle prints a list of missing commits, if any, and exits
45 + with non-zero status.
46 +
47 +list-heads <file>::
48 + Lists the references defined in the bundle. If followed by a
49 + list of references, only references matching those given are
50 + printed out.
51 +
52 +unbundle <file>::
53 + Passes the objects in the bundle to gitlink:git-index-pack[1]
54 + for storage in the repository, then prints the names of all
55 + defined references. If a reflist is given, only references
56 + matching those in the given list are printed. This command is
57 + really plumbing, intended to be called only by
58 + gitlink:git-fetch[1].
59 +
60 +[git-rev-list-args...]::
61 + A list of arguments, accepatble to git-rev-parse and
62 + git-rev-list, that specify the specific objects and references
63 + to transport. For example, "master~10..master" causes the
64 + current master reference to be packaged along with all objects
65 + added since its 10th ancestor commit. There is no explicit
66 + limit to the number of references and objects that may be
67 + packaged.
68 +
69 +
70 +[refname...]::
71 + A list of references used to limit the references reported as
72 + available. This is principally of use to git-fetch, which
73 + expects to recieve only those references asked for and not
74 + necessarily everything in the pack (in this case, git-bundle is
75 + acting like gitlink:git-fetch-pack[1]).
76 +
77 +SPECIFYING REFERENCES
78 +---------------------
79 +
80 +git-bundle will only package references that are shown by
81 +git-show-ref: this includes heads, tags, and remote heads. References
82 +such as master~1 cannot be packaged, but are perfectly suitable for
83 +defining the basis. More than one reference may be packaged, and more
84 +than one basis can be specified. The objects packaged are those not
85 +contained in the union of the given bases. Each basis can be
86 +specified explicitly (e.g., ^master~10), or implicitly (e.g.,
87 +master~10..master, master --since=10.days.ago).
88 +
89 +It is very important that the basis used be held by the destination.
90 +It is ok to err on the side of conservatism, causing the bundle file
91 +to contain objects already in the destination as these are ignored
92 +when unpacking at the destination.
93 +
94 +EXAMPLE
95 +-------
96 +
97 +Assume two repositories exist as R1 on machine A, and R2 on machine B.
98 +For whatever reason, direct connection between A and B is not allowed,
99 +but we can move data from A to B via some mechanism (CD, email, etc).
100 +We want to update R2 with developments made on branch master in R1.
101 +We set a tag in R1 (lastR2bundle) after the previous such transport,
102 +and move it afterwards to help build the bundle.
103 +
104 +in R1 on A:
105 +$ git-bundle create mybundle master ^lastR2bundle
106 +$ git tag -f lastR2bundle master
107 +
108 +(move mybundle from A to B by some mechanism)
109 +
110 +in R2 on B:
111 +$ git-bundle verify mybundle
112 +$ git-fetch mybundle refspec
113 +
114 +where refspec is refInBundle:localRef
115 +
116 +
117 +Also, with something like this in your config:
118 +
119 +[remote "bundle"]
120 + url = /home/me/tmp/file.bdl
121 + fetch = refs/heads/*:refs/remotes/origin/*
122 +
123 +You can first sneakernet the bundle file to ~/tmp/file.bdl and
124 +then these commands:
125 +
126 +$ git ls-remote bundle
127 +$ git fetch bundle
128 +$ git pull bundle
129 +
130 +would treat it as if it is talking with a remote side over the
131 +network.
132 +
133 +Author
134 +------
135 +Written by Mark Levedahl <mdl123@verizon.net>
136 +
137 +GIT
138 +---
139 +Part of the gitlink:git[7] suite
Makefile
+1
@@ -271,6 +271,7 @@ BUILTIN_OBJS = \
271 builtin-archive.o \
272 builtin-blame.o \
273 builtin-branch.o \
274 + builtin-bundle.o \
275 builtin-cat-file.o \
276 builtin-checkout-index.o \
277 builtin-check-ref-format.o \
builtin-bundle.c new
+389
@@ -0,0 +1,389 @@
1 +#include "cache.h"
2 +#include "object.h"
3 +#include "commit.h"
4 +#include "diff.h"
5 +#include "revision.h"
6 +#include "list-objects.h"
7 +#include "exec_cmd.h"
8 +
9 +/*
10 + * Basic handler for bundle files to connect repositories via sneakernet.
11 + * Invocation must include action.
12 + * This function can create a bundle or provide information on an existing
13 + * bundle supporting git-fetch, git-pull, and git-ls-remote
14 + */
15 +
16 +static const char *bundle_usage="git-bundle (--create <bundle> <git-rev-list args> | --verify <bundle> | --list-heads <bundle> [refname]... | --unbundle <bundle> [refname]... )";
17 +
18 +static const char bundle_signature[] = "# v2 git bundle\n";
19 +
20 +struct ref_list {
21 + unsigned int nr, alloc;
22 + struct {
23 + unsigned char sha1[20];
24 + char *name;
25 + } *list;
26 +};
27 +
28 +static void add_to_ref_list(const unsigned char *sha1, const char *name,
29 + struct ref_list *list)
30 +{
31 + if (list->nr + 1 >= list->alloc) {
32 + list->alloc = alloc_nr(list->nr + 1);
33 + list->list = xrealloc(list->list,
34 + list->alloc * sizeof(list->list[0]));
35 + }
36 + memcpy(list->list[list->nr].sha1, sha1, 20);
37 + list->list[list->nr].name = xstrdup(name);
38 + list->nr++;
39 +}
40 +
41 +struct bundle_header {
42 + struct ref_list prerequisites, references;
43 +};
44 +
45 +/* this function returns the length of the string */
46 +static int read_string(int fd, char *buffer, int size)
47 +{
48 + int i;
49 + for (i = 0; i < size - 1; i++) {
50 + int count = read(fd, buffer + i, 1);
51 + if (count < 0)
52 + return error("Read error: %s", strerror(errno));
53 + if (count == 0) {
54 + i--;
55 + break;
56 + }
57 + if (buffer[i] == '\n')
58 + break;
59 + }
60 + buffer[i + 1] = '\0';
61 + return i + 1;
62 +}
63 +
64 +/* returns an fd */
65 +static int read_header(const char *path, struct bundle_header *header) {
66 + char buffer[1024];
67 + int fd = open(path, O_RDONLY);
68 +
69 + if (fd < 0)
70 + return error("could not open '%s'", path);
71 + if (read_string(fd, buffer, sizeof(buffer)) < 0 ||
72 + strcmp(buffer, bundle_signature)) {
73 + close(fd);
74 + return error("'%s' does not look like a v2 bundle file", path);
75 + }
76 + while (read_string(fd, buffer, sizeof(buffer)) > 0
77 + && buffer[0] != '\n') {
78 + int offset = buffer[0] == '-' ? 1 : 0;
79 + int len = strlen(buffer);
80 + unsigned char sha1[20];
81 + struct ref_list *list = offset ? &header->prerequisites
82 + : &header->references;
83 + if (get_sha1_hex(buffer + offset, sha1)) {
84 + close(fd);
85 + return error("invalid SHA1: %s", buffer);
86 + }
87 + if (buffer[len - 1] == '\n')
88 + buffer[len - 1] = '\0';
89 + add_to_ref_list(sha1, buffer + 41 + offset, list);
90 + }
91 + return fd;
92 +}
93 +
94 +/* if in && *in >= 0, take that as input file descriptor instead */
95 +static int fork_with_pipe(const char **argv, int *in, int *out)
96 +{
97 + int needs_in, needs_out;
98 + int fdin[2], fdout[2], pid;
99 +
100 + needs_in = in && *in < 0;
101 + if (needs_in) {
102 + if (pipe(fdin) < 0)
103 + return error("could not setup pipe");
104 + *in = fdin[1];
105 + }
106 +
107 + needs_out = out && *out < 0;
108 + if (needs_out) {
109 + if (pipe(fdout) < 0)
110 + return error("could not setup pipe");
111 + *out = fdout[0];
112 + }
113 +
114 + if ((pid = fork()) < 0) {
115 + if (needs_in) {
116 + close(fdin[0]);
117 + close(fdin[1]);
118 + }
119 + if (needs_out) {
120 + close(fdout[0]);
121 + close(fdout[1]);
122 + }
123 + return error("could not fork");
124 + }
125 + if (!pid) {
126 + if (needs_in) {
127 + dup2(fdin[0], 0);
128 + close(fdin[0]);
129 + close(fdin[1]);
130 + } else if (in)
131 + dup2(*in, 0);
132 + if (needs_out) {
133 + dup2(fdout[1], 1);
134 + close(fdout[0]);
135 + close(fdout[1]);
136 + } else if (out)
137 + dup2(*out, 1);
138 + exit(execv_git_cmd(argv));
139 + }
140 + if (needs_in)
141 + close(fdin[0]);
142 + if (needs_out)
143 + close(fdout[1]);
144 + return pid;
145 +}
146 +
147 +static int verify_bundle(struct bundle_header *header)
148 +{
149 + /*
150 + * Do fast check, then if any prereqs are missing then go line by line
151 + * to be verbose about the errors
152 + */
153 + struct ref_list *p = &header->prerequisites;
154 + const char *argv[5] = {"rev-list", "--stdin", "--not", "--all", NULL};
155 + int pid, in, out, i, ret = 0;
156 + char buffer[1024];
157 +
158 + in = out = -1;
159 + pid = fork_with_pipe(argv, &in, &out);
160 + if (pid < 0)
161 + return error("Could not fork rev-list");
162 + if (!fork()) {
163 + for (i = 0; i < p->nr; i++) {
164 + write(in, sha1_to_hex(p->list[i].sha1), 40);
165 + write(in, "\n", 1);
166 + }
167 + close(in);
168 + exit(0);
169 + }
170 + close(in);
171 + while (read_string(out, buffer, sizeof(buffer)) > 0) {
172 + if (ret++ == 0)
173 + error ("The bundle requires the following commits you lack:");
174 + fprintf(stderr, "%s", buffer);
175 + }
176 + close(out);
177 + while (waitpid(pid, &i, 0) < 0)
178 + if (errno != EINTR)
179 + return -1;
180 + if (!ret && (!WIFEXITED(i) || WEXITSTATUS(i)))
181 + return error("At least one prerequisite is lacking.");
182 +
183 + return ret;
184 +}
185 +
186 +static int list_heads(struct bundle_header *header, int argc, const char **argv)
187 +{
188 + int i;
189 + struct ref_list *r = &header->references;
190 +
191 + for (i = 0; i < r->nr; i++) {
192 + if (argc > 1) {
193 + int j;
194 + for (j = 1; j < argc; j++)
195 + if (!strcmp(r->list[i].name, argv[j]))
196 + break;
197 + if (j == argc)
198 + continue;
199 + }
200 + printf("%s %s\n", sha1_to_hex(r->list[i].sha1),
201 + r->list[i].name);
202 + }
203 + return 0;
204 +}
205 +
206 +static void show_commit(struct commit *commit)
207 +{
208 + write(1, sha1_to_hex(commit->object.sha1), 40);
209 + write(1, "\n", 1);
210 + if (commit->parents) {
211 + free_commit_list(commit->parents);
212 + commit->parents = NULL;
213 + }
214 +}
215 +
216 +static void show_object(struct object_array_entry *p)
217 +{
218 + /* An object with name "foo\n0000000..." can be used to
219 + * * confuse downstream git-pack-objects very badly.
220 + * */
221 + const char *ep = strchr(p->name, '\n');
222 + int len = ep ? ep - p->name : strlen(p->name);
223 + write(1, sha1_to_hex(p->item->sha1), 40);
224 + write(1, " ", 1);
225 + if (len)
226 + write(1, p->name, len);
227 + write(1, "\n", 1);
228 +}
229 +
230 +static int create_bundle(struct bundle_header *header, const char *path,
231 + int argc, const char **argv)
232 +{
233 + int bundle_fd = -1;
234 + const char **argv_boundary = xmalloc((argc + 3) * sizeof(const char *));
235 + const char **argv_pack = xmalloc(4 * sizeof(const char *));
236 + int pid, in, out, i, status;
237 + char buffer[1024];
238 + struct rev_info revs;
239 +
240 + bundle_fd = (!strcmp(path, "-") ? 1 :
241 + open(path, O_CREAT | O_WRONLY, 0666));
242 + if (bundle_fd < 0)
243 + return error("Could not write to '%s'", path);
244 +
245 + /* write signature */
246 + write(bundle_fd, bundle_signature, strlen(bundle_signature));
247 +
248 + /* write prerequisites */
249 + memcpy(argv_boundary + 2, argv + 1, argc * sizeof(const char *));
250 + argv_boundary[0] = "rev-list";
251 + argv_boundary[1] = "--boundary";
252 + argv_boundary[argc + 1] = NULL;
253 + out = -1;
254 + pid = fork_with_pipe(argv_boundary, NULL, &out);
255 + if (pid < 0)
256 + return -1;
257 + while ((i = read_string(out, buffer, sizeof(buffer))) > 0)
258 + if (buffer[0] == '-')
259 + write(bundle_fd, buffer, i);
260 + while ((i = waitpid(pid, &status, 0)) < 0)
261 + if (errno != EINTR)
262 + return error("rev-list died");
263 + if (!WIFEXITED(status) || WEXITSTATUS(status))
264 + return error("rev-list died %d", WEXITSTATUS(status));
265 +
266 + /* write references */
267 + save_commit_buffer = 0;
268 + init_revisions(&revs, NULL);
269 + revs.tag_objects = 1;
270 + revs.tree_objects = 1;
271 + revs.blob_objects = 1;
272 + argc = setup_revisions(argc, argv, &revs, NULL);
273 + if (argc > 1)
274 + return error("unrecognized argument: %s'", argv[1]);
275 + for (i = 0; i < revs.pending.nr; i++) {
276 + struct object_array_entry *e = revs.pending.objects + i;
277 + if (!(e->item->flags & UNINTERESTING)) {
278 + unsigned char sha1[20];
279 + char *ref;
280 + if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
281 + continue;
282 + write(bundle_fd, sha1_to_hex(e->item->sha1), 40);
283 + write(bundle_fd, " ", 1);
284 + write(bundle_fd, ref, strlen(ref));
285 + write(bundle_fd, "\n", 1);
286 + free(ref);
287 + }
288 + }
289 +
290 + /* end header */
291 + write(bundle_fd, "\n", 1);
292 +
293 + /* write pack */
294 + argv_pack[0] = "pack-objects";
295 + argv_pack[1] = "--all-progress";
296 + argv_pack[2] = "--stdout";
297 + argv_pack[3] = NULL;
298 + in = -1;
299 + out = bundle_fd;
300 + pid = fork_with_pipe(argv_pack, &in, &out);
301 + if (pid < 0)
302 + return error("Could not spawn pack-objects");
303 + close(1);
304 + close(bundle_fd);
305 + dup2(in, 1);
306 + close(in);
307 + prepare_revision_walk(&revs);
308 + traverse_commit_list(&revs, show_commit, show_object);
309 + close(1);
310 + while (waitpid(pid, &status, 0) < 0)
311 + if (errno != EINTR)
312 + return -1;
313 + if (!WIFEXITED(status) || WEXITSTATUS(status))
314 + return error ("pack-objects died");
315 + return 0;
316 +}
317 +
318 +static int unbundle(struct bundle_header *header, int bundle_fd,
319 + int argc, const char **argv)
320 +{
321 + const char *argv_index_pack[] = {"index-pack", "--stdin", NULL};
322 + int pid, status, dev_null;
323 +
324 + if (verify_bundle(header))
325 + return -1;
326 + dev_null = open("/dev/null", O_WRONLY);
327 + pid = fork_with_pipe(argv_index_pack, &bundle_fd, &dev_null);
328 + if (pid < 0)
329 + return error("Could not spawn index-pack");
330 + close(bundle_fd);
331 + while (waitpid(pid, &status, 0) < 0)
332 + if (errno != EINTR)
333 + return error("index-pack died");
334 + if (!WIFEXITED(status) || WEXITSTATUS(status))
335 + return error("index-pack exited with status %d",
336 + WEXITSTATUS(status));
337 + return list_heads(header, argc, argv);
338 +}
339 +
340 +int cmd_bundle(int argc, const char **argv, const char *prefix)
341 +{
342 + struct bundle_header header;
343 + int nongit = 0;
344 + const char *cmd, *bundle_file;
345 + int bundle_fd = -1;
346 + char buffer[PATH_MAX];
347 +
348 + if (argc < 3)
349 + usage(bundle_usage);
350 +
351 + cmd = argv[1];
352 + bundle_file = argv[2];
353 + argc -= 2;
354 + argv += 2;
355 +
356 + prefix = setup_git_directory_gently(&nongit);
357 + if (prefix && bundle_file[0] != '/') {
358 + snprintf(buffer, sizeof(buffer), "%s/%s", prefix, bundle_file);
359 + bundle_file = buffer;
360 + }
361 +
362 + memset(&header, 0, sizeof(header));
363 + if (strcmp(cmd, "create") &&
364 + !(bundle_fd = read_header(bundle_file, &header)))
365 + return 1;
366 +
367 + if (!strcmp(cmd, "verify")) {
368 + close(bundle_fd);
369 + if (verify_bundle(&header))
370 + return 1;
371 + fprintf(stderr, "%s is okay\n", bundle_file);
372 + return 0;
373 + }
374 + if (!strcmp(cmd, "list-heads")) {
375 + close(bundle_fd);
376 + return !!list_heads(&header, argc, argv);
377 + }
378 + if (!strcmp(cmd, "create")) {
379 + if (nongit)
380 + die("Need a repository to create a bundle.");
381 + return !!create_bundle(&header, bundle_file, argc, argv);
382 + } else if (!strcmp(cmd, "unbundle")) {
383 + if (nongit)
384 + die("Need a repository to unbundle.");
385 + return !!unbundle(&header, bundle_fd, argc, argv);
386 + } else
387 + usage(bundle_usage);
388 +}
389 +
builtin.h
+1
@@ -19,6 +19,7 @@ extern int cmd_apply(int argc, const char **argv, const char *prefix);
19 extern int cmd_archive(int argc, const char **argv, const char *prefix);
20 extern int cmd_blame(int argc, const char **argv, const char *prefix);
21 extern int cmd_branch(int argc, const char **argv, const char *prefix);
22 +extern int cmd_bundle(int argc, const char **argv, const char *prefix);
23 extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
24 extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);
25 extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix);
git-fetch.sh
+7
@@ -377,8 +377,15 @@ fetch_main () {
377 ( : subshell because we muck with IFS
378 IFS=" $LF"
379 (
380 + if test -f "$remote" ; then
381 + test -n "$shallow_depth" &&
382 + die "shallow clone with bundle is not supported"
383 + git-bundle unbundle "$remote" $rref ||
384 + echo failed "$remote"
385 + else
386 git-fetch-pack --thin $exec $keep $shallow_depth "$remote" $rref ||
387 echo failed "$remote"
388 + fi
389 ) |
390 (
391 trap '
git-ls-remote.sh
+6 -1
@@ -89,8 +89,13 @@ rsync://* )
89 ;;
90
91 * )
92 - git-peek-remote $exec "$peek_repo" ||
92 + if test -f "$peek_repo" ; then
93 + git bundle list-heads "$peek_repo" ||
94 echo "failed slurping"
95 + else
96 + git-peek-remote $exec "$peek_repo" ||
97 + echo "failed slurping"
98 + fi
99 ;;
100 esac |
101 sort -t ' ' -k 2 |
git.c
+1
@@ -229,6 +229,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
229 { "archive", cmd_archive },
230 { "blame", cmd_blame, RUN_SETUP },
231 { "branch", cmd_branch, RUN_SETUP },
232 + { "bundle", cmd_bundle },
233 { "cat-file", cmd_cat_file, RUN_SETUP },
234 { "checkout-index", cmd_checkout_index, RUN_SETUP },
235 { "check-ref-format", cmd_check_ref_format },
index-pack.c
+2 -2
@@ -457,8 +457,8 @@ static void parse_pack_objects(unsigned char *sha1)
457 /* If input_fd is a file, we should have reached its end now. */
458 if (fstat(input_fd, &st))
459 die("cannot fstat packfile: %s", strerror(errno));
460 - if (S_ISREG(st.st_mode) && st.st_size != consumed_bytes)
461 - die("pack has junk at the end");
460 + if (input_fd && S_ISREG(st.st_mode) && st.st_size != consumed_bytes)
461 + die("pack has junk at the end: 0%o, %d, %d %d", st.st_mode, (int)st.st_size, (int)consumed_bytes, input_fd);
462
463 if (!nr_deltas)
464 return;
t/t5510-fetch.sh
+27 -1
@@ -35,7 +35,9 @@ test_expect_success "clone and setup child repos" '
35 echo "URL: ../two/.git/"
36 echo "Pull: refs/heads/master:refs/heads/two"
37 echo "Pull: refs/heads/one:refs/heads/one"
38 - } >.git/remotes/two
38 + } >.git/remotes/two &&
39 + cd .. &&
40 + git clone . bundle
41 '
42
43 test_expect_success "fetch test" '
@@ -81,4 +83,28 @@ test_expect_success 'fetch following tags' '
83
84 '
85
86 +test_expect_success 'create bundle 1' '
87 + cd "$D" &&
88 + echo >file updated again by origin &&
89 + git commit -a -m "tip" &&
90 + git bundle create bundle1 master^..master
91 +'
92 +
93 +test_expect_success 'create bundle 2' '
94 + cd "$D" &&
95 + git bundle create bundle2 master~2..master
96 +'
97 +
98 +test_expect_failure 'unbundle 1' '
99 + cd "$D/bundle" &&
100 + git checkout -b some-branch &&
101 + git fetch "$D/bundle1" master:master
102 +'
103 +
104 +test_expect_success 'unbundle 2' '
105 + cd "$D/bundle" &&
106 + git fetch ../bundle2 master:master &&
107 + test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
108 +'
109 +
110 test_done