Skip to content

Commit 86238e0

Browse files
bmwillgitster
authored andcommitted
commit: allow partial commits with relative paths
Commit 8894d53 (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 5879f56 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc849d8 commit 86238e0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

builtin/commit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
253253

254254
if (with_tree) {
255255
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);
258257
free(max_prefix);
259258
}
260259

t/t7501-commit.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ test_expect_success PERL 'can use paths with --interactive' '
5252
git reset --hard HEAD^
5353
'
5454

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+
5567
test_expect_success 'using invalid commit with -C' '
5668
test_must_fail git commit --allow-empty -C bogus
5769
'

0 commit comments

Comments
 (0)