@matheusbsbs / matheus-bagliano / commits / 8ee4a6c2ec
Fork 0

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>

Junio C Hamano committed Jul 2, 2008 at 15:28 UTC 8ee4a6c2ec6738cfbc815dc59e44825f2a9b9f15
2 files changed +15 -4
builtin-apply.c
+2 -2
@@ -3130,10 +3130,10 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
3130 inaccurate_eof = 1;
3131 continue;
3132 }
3133 - if (!strncmp(arg, "--root=", strlen("--root="))) {
3133 + if (!prefixcmp(arg, "--root=")) {
3134 arg += strlen("--root=");
3135 root_len = strlen(arg);
3136 - if (root_len && arg[root_len + 1] != '/') {
3136 + if (root_len && arg[root_len - 1] != '/') {
3137 char *new_root;
3138 root = new_root = xmalloc(root_len + 2);
3139 strcpy(new_root, arg);
t/t4128-apply-root.sh
+13 -2
@@ -8,7 +8,9 @@ test_expect_success 'setup' '
8
9 mkdir -p some/sub/dir &&
10 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
14
15 '
16
@@ -21,7 +23,7 @@ diff a/bla/blub/dir/file b/bla/blub/dir/file
23 +Bello
24 EOF
25
24 -test_expect_success 'apply --root -p --index' '
26 +test_expect_success 'apply --root -p (1)' '
27
28 git apply --root=some/sub -p3 --index patch &&
29 test Bello = $(git show :some/sub/dir/file) &&
@@ -29,4 +31,13 @@ test_expect_success 'apply --root -p --index' '
31
32 '
33
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 +
43 test_done