index-pack: correct --keep[=<msg>]
authorJunio C Hamano <gitster@pobox.com>
Thu, 3 Mar 2016 18:52:53 +0000 (10:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 3 Mar 2016 19:06:01 +0000 (11:06 -0800)
When 592ce208 (index-pack: use strip_suffix to avoid magic numbers,
2014-06-30) refactored the code to derive names of .idx and .keep
files from the name of .pack file, a copy-and-paste typo crept in,
mistakingly attempting to create and store the keep message file in
the .idx file we just created, instead of .keep file.

As we create the .keep file with O_CREAT|O_EXCL, and we do so after
we write the .idx file, we luckily do not clobber the .idx file, but
because we deliberately ignored EEXIST when creating .keep file
(which is justifiable because only the existence of .keep file
matters), nobody noticed this mistake so far.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/index-pack.c
t/t5300-pack-object.sh
index d4b77fd1285a4305341a358386b05434fab7e5e9..3814731f54a727b2114f9cbdd137f85d03e56d0b 100644 (file)
@@ -1617,7 +1617,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
                        die(_("packfile name '%s' does not end with '.pack'"),
                            pack_name);
                strbuf_add(&keep_name_buf, pack_name, len);
-               strbuf_addstr(&keep_name_buf, ".idx");
+               strbuf_addstr(&keep_name_buf, ".keep");
                keep_name = keep_name_buf.buf;
        }
        if (verify) {
index 20c1961515a02e3411d02a5656bf8a9dc6b198de..0e3cadfd577b2d6691bc9b8e9bfd6f83b99c4525 100755 (executable)
@@ -284,6 +284,12 @@ test_expect_success \
      git index-pack test-3.pack &&
      cmp test-3.idx test-3-${packname_3}.idx &&
 
+     cat test-1-${packname_1}.pack >test-4.pack &&
+     rm -f test-4.keep &&
+     git index-pack --keep=why test-4.pack &&
+     cmp test-1-${packname_1}.idx test-4.idx &&
+     test -f test-4.keep &&
+
      :'
 
 test_expect_success 'unpacking with --strict' '