author | Junio C Hamano <gitster@pobox.com> | |
Fri, 27 Nov 2009 08:56:05 +0000 (00:56 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 27 Nov 2009 08:56:05 +0000 (00:56 -0800) |
* maint:
builtin-apply.c: pay attention to -p<n> when determining the name
builtin-apply.c: pay attention to -p<n> when determining the name
builtin-apply.c | patch | blob | history | |
t/t4128-apply-root.sh | patch | blob | history |
diff --git a/builtin-apply.c b/builtin-apply.c
index f667368d161609ea3c93fc6ebe2452b9cd0e557d..36e2f9dda5c85c346e31f45afa6d28b107679970 100644 (file)
--- a/builtin-apply.c
+++ b/builtin-apply.c
static const char *stop_at_slash(const char *line, int llen)
{
+ int nslash = p_value;
int i;
for (i = 0; i < llen; i++) {
int ch = line[i];
- if (ch == '/')
- return line + i;
+ if (ch == '/' && --nslash <= 0)
+ return &line[i];
}
return NULL;
}
diff --git a/t/t4128-apply-root.sh b/t/t4128-apply-root.sh
index 8f6aea48d84621ae3b7304636452c724a4bbe5b6..6cc741a634b0352c54fe8e5f61f1e99543909b8c 100755 (executable)
--- a/t/t4128-apply-root.sh
+++ b/t/t4128-apply-root.sh
test content = $(cat some/sub/dir/newfile)
'
+cat > patch << EOF
+diff --git a/c/newfile2 b/c/newfile2
+new file mode 100644
+index 0000000..d95f3ad
+--- /dev/null
++++ b/c/newfile2
+@@ -0,0 +1 @@
++content
+EOF
+
+test_expect_success 'apply --directory -p (new file)' '
+ git reset --hard initial &&
+ git apply -p2 --directory=some/sub/dir/ --index patch &&
+ test content = $(git show :some/sub/dir/newfile2) &&
+ test content = $(cat some/sub/dir/newfile2)
+'
+
cat > patch << EOF
diff --git a/delfile b/delfile
deleted file mode 100644