Skip to content

Commit

Permalink
apply --root: thinkofix.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jul 2, 2008
1 parent c4730f3 commit 8ee4a6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions builtin-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 13 additions & 2 deletions t/t4128-apply-root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
'

Expand All @@ -21,12 +23,21 @@ 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) &&
test Bello = $(cat some/sub/dir/file)
'

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

0 comments on commit 8ee4a6c

Please sign in to comment.