From: Junio C Hamano Date: Wed, 2 Jul 2008 22:28:22 +0000 (-0700) Subject: apply --root: thinkofix. X-Git-Tag: v1.6.0-rc0~94^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8ee4a6c2ec6738cfbc815dc59e44825f2a9b9f15;p=git.git 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 --- diff --git a/builtin-apply.c b/builtin-apply.c index bf528966c..6c3db60b6 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -3130,10 +3130,10 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) inaccurate_eof = 1; continue; } - if (!strncmp(arg, "--root=", strlen("--root="))) { + if (!prefixcmp(arg, "--root=")) { arg += strlen("--root="); root_len = strlen(arg); - if (root_len && arg[root_len + 1] != '/') { + if (root_len && arg[root_len - 1] != '/') { char *new_root; root = new_root = xmalloc(root_len + 2); strcpy(new_root, arg); diff --git a/t/t4128-apply-root.sh b/t/t4128-apply-root.sh index 80b5af2b4..b65024545 100755 --- a/t/t4128-apply-root.sh +++ b/t/t4128-apply-root.sh @@ -8,7 +8,9 @@ test_expect_success 'setup' ' mkdir -p some/sub/dir && echo Hello > some/sub/dir/file && - git add some/sub/dir/file + git add some/sub/dir/file && + git commit -m initial && + git tag initial ' @@ -21,7 +23,7 @@ diff a/bla/blub/dir/file b/bla/blub/dir/file +Bello EOF -test_expect_success 'apply --root -p --index' ' +test_expect_success 'apply --root -p (1)' ' git apply --root=some/sub -p3 --index patch && test Bello = $(git show :some/sub/dir/file) && @@ -29,4 +31,13 @@ test_expect_success 'apply --root -p --index' ' ' +test_expect_success 'apply --root -p (2) ' ' + + git reset --hard initial && + git apply --root=some/sub/ -p3 --index patch && + test Bello = $(git show :some/sub/dir/file) && + test Bello = $(cat some/sub/dir/file) + +' + test_done