6 * Basic handler for bundle files to connect repositories via sneakernet.
7 * Invocation must include action.
8 * This function can create a bundle or provide information on an existing
9 * bundle supporting "fetch", "pull", and "ls-remote".
12 static const char builtin_bundle_usage
[] =
13 "git bundle create <file> <git-rev-list args>\n"
14 " or: git bundle verify <file>\n"
15 " or: git bundle list-heads <file> [<refname>...]\n"
16 " or: git bundle unbundle <file> [<refname>...]";
18 int cmd_bundle(int argc
, const char **argv
, const char *prefix
)
20 struct bundle_header header
;
21 const char *cmd
, *bundle_file
;
23 char buffer
[PATH_MAX
];
26 usage(builtin_bundle_usage
);
29 bundle_file
= argv
[2];
33 if (prefix
&& bundle_file
[0] != '/') {
34 snprintf(buffer
, sizeof(buffer
), "%s/%s", prefix
, bundle_file
);
38 memset(&header
, 0, sizeof(header
));
39 if (strcmp(cmd
, "create") && (bundle_fd
=
40 read_bundle_header(bundle_file
, &header
)) < 0)
43 if (!strcmp(cmd
, "verify")) {
46 usage(builtin_bundle_usage
);
49 if (verify_bundle(&header
, 1))
51 fprintf(stderr
, _("%s is okay\n"), bundle_file
);
54 if (!strcmp(cmd
, "list-heads")) {
56 return !!list_bundle_refs(&header
, argc
, argv
);
58 if (!strcmp(cmd
, "create")) {
60 usage(builtin_bundle_usage
);
63 if (!startup_info
->have_repository
)
64 die(_("Need a repository to create a bundle."));
65 return !!create_bundle(&header
, bundle_file
, argc
, argv
);
66 } else if (!strcmp(cmd
, "unbundle")) {
67 if (!startup_info
->have_repository
)
68 die(_("Need a repository to unbundle."));
69 return !!unbundle(&header
, bundle_fd
, 0) ||
70 list_bundle_refs(&header
, argc
, argv
);
72 usage(builtin_bundle_usage
);