Merge branch 'maint'
[gitweb.git] / builtin-bundle.c
index 616335819162be2163c655490724fb40f58f127f..786808081b8d5fe233ecd6533a4f5e8beb7d126c 100644 (file)
@@ -263,14 +263,14 @@ static int create_bundle(struct bundle_header *header, const char *path,
        int bundle_fd = -1;
        const char **argv_boundary = xmalloc((argc + 4) * sizeof(const char *));
        const char **argv_pack = xmalloc(5 * sizeof(const char *));
-       int pid, in, out, i, status;
+       int pid, in, out, i, status, ref_count = 0;
        char buffer[1024];
        struct rev_info revs;
 
        bundle_fd = (!strcmp(path, "-") ? 1 :
-                       open(path, O_CREAT | O_WRONLY, 0666));
+                       open(path, O_CREAT | O_EXCL | O_WRONLY, 0666));
        if (bundle_fd < 0)
-               return error("Could not write to '%s'", path);
+               return error("Could not create '%s': %s", path, strerror(errno));
 
        /* write signature */
        write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));
@@ -333,12 +333,15 @@ static int create_bundle(struct bundle_header *header, const char *path,
                                e->name);
                        continue;
                }
+               ref_count++;
                write_or_die(bundle_fd, sha1_to_hex(e->item->sha1), 40);
                write_or_die(bundle_fd, " ", 1);
                write_or_die(bundle_fd, ref, strlen(ref));
                write_or_die(bundle_fd, "\n", 1);
                free(ref);
        }
+       if (!ref_count)
+               die ("Refusing to create empty bundle.");
 
        /* end header */
        write_or_die(bundle_fd, "\n", 1);
@@ -374,7 +377,8 @@ static int create_bundle(struct bundle_header *header, const char *path,
 static int unbundle(struct bundle_header *header, int bundle_fd,
                int argc, const char **argv)
 {
-       const char *argv_index_pack[] = {"index-pack", "--stdin", NULL};
+       const char *argv_index_pack[] = {"index-pack",
+               "--fix-thin", "--stdin", NULL};
        int pid, status, dev_null;
 
        if (verify_bundle(header, 0))