Git 2.23
[gitweb.git] / builtin / bundle.c
index 2006cc5cd5cc4d381189f5cf7bdd09fcdd66b9ca..1ea4bfdfc19868d9cb89bb7014c138f145f7dd67 100644 (file)
 static const char builtin_bundle_usage[] =
   "git bundle create <file> <git-rev-list args>\n"
   "   or: git bundle verify <file>\n"
-  "   or: git bundle list-heads <file> [refname...]\n"
-  "   or: git bundle unbundle <file> [refname...]";
+  "   or: git bundle list-heads <file> [<refname>...]\n"
+  "   or: git bundle unbundle <file> [<refname>...]";
 
 int cmd_bundle(int argc, const char **argv, const char *prefix)
 {
        struct bundle_header header;
-       int nongit;
        const char *cmd, *bundle_file;
        int bundle_fd = -1;
-       char buffer[PATH_MAX];
 
        if (argc < 3)
                usage(builtin_bundle_usage);
 
        cmd = argv[1];
-       bundle_file = argv[2];
+       bundle_file = prefix_filename(prefix, argv[2]);
        argc -= 2;
        argv += 2;
 
-       prefix = setup_git_directory_gently(&nongit);
-       if (prefix && bundle_file[0] != '/') {
-               snprintf(buffer, sizeof(buffer), "%s/%s", prefix, bundle_file);
-               bundle_file = buffer;
-       }
-
        memset(&header, 0, sizeof(header));
        if (strcmp(cmd, "create") && (bundle_fd =
                                read_bundle_header(bundle_file, &header)) < 0)
@@ -44,9 +36,13 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
 
        if (!strcmp(cmd, "verify")) {
                close(bundle_fd);
-               if (verify_bundle(&header, 1))
+               if (argc != 1) {
+                       usage(builtin_bundle_usage);
                        return 1;
-               fprintf(stderr, "%s is okay\n", bundle_file);
+               }
+               if (verify_bundle(the_repository, &header, 1))
+                       return 1;
+               fprintf(stderr, _("%s is okay\n"), bundle_file);
                return 0;
        }
        if (!strcmp(cmd, "list-heads")) {
@@ -54,13 +50,17 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
                return !!list_bundle_refs(&header, argc, argv);
        }
        if (!strcmp(cmd, "create")) {
-               if (nongit)
-                       die("Need a repository to create a bundle.");
-               return !!create_bundle(&header, bundle_file, argc, argv);
+               if (argc < 2) {
+                       usage(builtin_bundle_usage);
+                       return 1;
+               }
+               if (!startup_info->have_repository)
+                       die(_("Need a repository to create a bundle."));
+               return !!create_bundle(the_repository, bundle_file, argc, argv);
        } else if (!strcmp(cmd, "unbundle")) {
-               if (nongit)
-                       die("Need a repository to unbundle.");
-               return !!unbundle(&header, bundle_fd) ||
+               if (!startup_info->have_repository)
+                       die(_("Need a repository to unbundle."));
+               return !!unbundle(the_repository, &header, bundle_fd, 0) ||
                        list_bundle_refs(&header, argc, argv);
        } else
                usage(builtin_bundle_usage);