commit: allow partial commits with relative paths

Commit 8894d53580 (commit: allow partial commits with relative paths, 2011-07-30) ensured that partial commits were allowed when a user supplies a relative pathspec but then this was regressed in 5879f5684c (remove prefix argument from pathspec_prefix, 2011-09-04) when the prefix argument to 'pathspec_prefix' removed and the 'list_paths' function wasn't properly adjusted to cope with the change, resulting in over-eager pruning of the tree that is overlayed on the index. This fixes the regression and adds a regression test so this can be prevented in the future. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Apr 3, 2018 at 10:57 UTC 86238e07ef633f7488ac708578aaf71e4375c057
2 files changed +13 -2
builtin/commit.c
+1 -2
@@ -253,8 +253,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
253
254 if (with_tree) {
255 char *max_prefix = common_prefix(pattern);
256 - overlay_tree_on_index(&the_index, with_tree,
257 - max_prefix ? max_prefix : prefix);
256 + overlay_tree_on_index(&the_index, with_tree, max_prefix);
257 free(max_prefix);
258 }
259
t/t7501-commit.sh
+12
@@ -52,6 +52,18 @@ test_expect_success PERL 'can use paths with --interactive' '
52 git reset --hard HEAD^
53 '
54
55 +test_expect_success 'removed files and relative paths' '
56 + test_when_finished "rm -rf foo" &&
57 + git init foo &&
58 + >foo/foo.txt &&
59 + git -C foo add foo.txt &&
60 + git -C foo commit -m first &&
61 + git -C foo rm foo.txt &&
62 +
63 + mkdir -p foo/bar &&
64 + git -C foo/bar commit -m second ../foo.txt
65 +'
66 +
67 test_expect_success 'using invalid commit with -C' '
68 test_must_fail git commit --allow-empty -C bogus
69 '