]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/bundle.c
worktree: fix worktree add race
[thirdparty/git.git] / builtin / bundle.c
CommitLineData
baffc0e7 1#include "builtin.h"
2e0afafe 2#include "cache.h"
30415d50 3#include "bundle.h"
2e0afafe
JS
4
5/*
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
34baebce 9 * bundle supporting "fetch", "pull", and "ls-remote".
2e0afafe
JS
10 */
11
1f986c4a
TF
12static const char builtin_bundle_usage[] =
13 "git bundle create <file> <git-rev-list args>\n"
14 " or: git bundle verify <file>\n"
62b4698e
ŠN
15 " or: git bundle list-heads <file> [<refname>...]\n"
16 " or: git bundle unbundle <file> [<refname>...]";
2e0afafe 17
2e0afafe
JS
18int cmd_bundle(int argc, const char **argv, const char *prefix)
19{
20 struct bundle_header header;
2e0afafe
JS
21 const char *cmd, *bundle_file;
22 int bundle_fd = -1;
2e0afafe
JS
23
24 if (argc < 3)
1f986c4a 25 usage(builtin_bundle_usage);
2e0afafe
JS
26
27 cmd = argv[1];
3b754eed 28 bundle_file = prefix_filename(prefix, argv[2]);
2e0afafe
JS
29 argc -= 2;
30 argv += 2;
31
2e0afafe 32 memset(&header, 0, sizeof(header));
30415d50
JS
33 if (strcmp(cmd, "create") && (bundle_fd =
34 read_bundle_header(bundle_file, &header)) < 0)
2e0afafe
JS
35 return 1;
36
37 if (!strcmp(cmd, "verify")) {
38 close(bundle_fd);
7886cfa0
PS
39 if (argc != 1) {
40 usage(builtin_bundle_usage);
41 return 1;
42 }
74ae4b63 43 if (verify_bundle(the_repository, &header, 1))
2e0afafe 44 return 1;
c7c4efac 45 fprintf(stderr, _("%s is okay\n"), bundle_file);
2e0afafe
JS
46 return 0;
47 }
48 if (!strcmp(cmd, "list-heads")) {
49 close(bundle_fd);
30415d50 50 return !!list_bundle_refs(&header, argc, argv);
2e0afafe
JS
51 }
52 if (!strcmp(cmd, "create")) {
7886cfa0
PS
53 if (argc < 2) {
54 usage(builtin_bundle_usage);
55 return 1;
56 }
2cb60093 57 if (!startup_info->have_repository)
c7c4efac 58 die(_("Need a repository to create a bundle."));
fcb133e9 59 return !!create_bundle(the_repository, bundle_file, argc, argv);
2e0afafe 60 } else if (!strcmp(cmd, "unbundle")) {
2cb60093 61 if (!startup_info->have_repository)
c7c4efac 62 die(_("Need a repository to unbundle."));
74ae4b63 63 return !!unbundle(the_repository, &header, bundle_fd, 0) ||
30415d50 64 list_bundle_refs(&header, argc, argv);
2e0afafe 65 } else
1f986c4a 66 usage(builtin_bundle_usage);
2e0afafe 67}