Skip to content

Commit 8ee4a6c

Browse files
committed
apply --root: thinkofix.
The end of a string is string[length-1], not string[length+1]. I pointed it out during the review, but I forgot about it when applying the patch. This should fix it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c4730f3 commit 8ee4a6c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

builtin-apply.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,10 +3130,10 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
31303130
inaccurate_eof = 1;
31313131
continue;
31323132
}
3133-
if (!strncmp(arg, "--root=", strlen("--root="))) {
3133+
if (!prefixcmp(arg, "--root=")) {
31343134
arg += strlen("--root=");
31353135
root_len = strlen(arg);
3136-
if (root_len && arg[root_len + 1] != '/') {
3136+
if (root_len && arg[root_len - 1] != '/') {
31373137
char *new_root;
31383138
root = new_root = xmalloc(root_len + 2);
31393139
strcpy(new_root, arg);

t/t4128-apply-root.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ test_expect_success 'setup' '
88
99
mkdir -p some/sub/dir &&
1010
echo Hello > some/sub/dir/file &&
11-
git add some/sub/dir/file
11+
git add some/sub/dir/file &&
12+
git commit -m initial &&
13+
git tag initial
1214
1315
'
1416

@@ -21,12 +23,21 @@ diff a/bla/blub/dir/file b/bla/blub/dir/file
2123
+Bello
2224
EOF
2325

24-
test_expect_success 'apply --root -p --index' '
26+
test_expect_success 'apply --root -p (1)' '
2527
2628
git apply --root=some/sub -p3 --index patch &&
2729
test Bello = $(git show :some/sub/dir/file) &&
2830
test Bello = $(cat some/sub/dir/file)
2931
3032
'
3133

34+
test_expect_success 'apply --root -p (2) ' '
35+
36+
git reset --hard initial &&
37+
git apply --root=some/sub/ -p3 --index patch &&
38+
test Bello = $(git show :some/sub/dir/file) &&
39+
test Bello = $(cat some/sub/dir/file)
40+
41+
'
42+
3243
test_done

0 commit comments

Comments
 (0)