Merge branch 'jk/maint-commit-amend-only-no-paths'
authorJunio C Hamano <gitster@pobox.com>
Mon, 16 Jul 2012 04:39:48 +0000 (21:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Jul 2012 04:39:48 +0000 (21:39 -0700)
"git commit --amend --only --" was meant to allow "Clever" people to
rewrite the commit message without making any change even when they
have already changes for the next commit added to their index, but
it never worked as advertised since it was introduced in 1.3.0 era.

* jk/maint-commit-amend-only-no-paths:
commit: fix "--amend --only" with no pathspec

builtin/commit.c
t/t7501-commit.sh
index 6515da27864feaac3931cf9fd53e3928583c081b..95eeab1d5146628277b0ba2c4e4bc7a6f77f3a4a 100644 (file)
@@ -184,6 +184,9 @@ static int list_paths(struct string_list *list, const char *with_tree,
        int i;
        char *m;
 
+       if (!pattern)
+               return 0;
+
        for (i = 0; pattern[i]; i++)
                ;
        m = xcalloc(1, i);
@@ -345,7 +348,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
         * and create commit from the_index.
         * We still need to refresh the index here.
         */
-       if (!pathspec || !*pathspec) {
+       if (!only && (!pathspec || !*pathspec)) {
                fd = hold_locked_index(&index_lock, 1);
                refresh_cache_or_die(refresh_flags);
                if (active_cache_changed) {
index 0f83be80efa0fa8d25dd667b2a667c8406df787f..195e7477d883f39d51f5740b5b309a489dd92d3d 100755 (executable)
@@ -108,6 +108,16 @@ test_expect_success 'amend commit' '
        EDITOR=./editor git commit --amend
 '
 
+test_expect_success 'amend --only ignores staged contents' '
+       cp file file.expect &&
+       echo changed >file &&
+       git add file &&
+       git commit --no-edit --amend --only &&
+       git cat-file blob HEAD:file >file.actual &&
+       test_cmp file.expect file.actual &&
+       git diff --exit-code
+'
+
 test_expect_success 'set up editor' '
        cat >editor <<-\EOF &&
        #!/bin/sh