git-apply --directory: make --root more similar to GNU diff
Applying a patch in the directory that is different from what the patch records is done with --directory option in GNU diff. The --root option we introduced previously does the same, and we can call it the same way to give users more familiar feel. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 6, 2008 at 18:36 UTC
f55638874774acc1e13a046353449ebc8734ab08
3 files changed
+12
-8
Documentation/git-apply.txt
+6
-2
@@ -14,7 +14,7 @@ SYNOPSIS
14
[--allow-binary-replacement | --binary] [--reject] [-z]
15
[-pNUM] [-CNUM] [--inaccurate-eof] [--cached]
16
[--whitespace=<nowarn|warn|fix|error|error-all>]
17
- [--exclude=PATH] [--root=<root>] [--verbose] [<patch>...]
17
+ [--exclude=PATH] [--directory=<root>] [--verbose] [<patch>...]
18
19
DESCRIPTION
20
-----------
@@ -177,9 +177,13 @@ behavior:
177
current patch being applied will be printed. This option will cause
178
additional information to be reported.
179
180
---root=<root>::
180
+--directory=<root>::
181
Prepend <root> to all filenames. If a "-p" argument was passed, too,
182
it is applied before prepending the new root.
183
++
184
+For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh`
185
+can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by
186
+running `git apply --directory=modules/git-gui`.
187
188
Configuration
189
-------------
builtin-apply.c
+2
-2
@@ -3130,8 +3130,8 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
3130
inaccurate_eof = 1;
3131
continue;
3132
}
3133
- if (!prefixcmp(arg, "--root=")) {
3134
- arg += strlen("--root=");
3133
+ if (!prefixcmp(arg, "--directory=")) {
3134
+ arg += strlen("--directory=");
3135
root_len = strlen(arg);
3136
if (root_len && arg[root_len - 1] != '/') {
3137
char *new_root;
t/t4128-apply-root.sh
+4
-4
@@ -23,18 +23,18 @@ diff a/bla/blub/dir/file b/bla/blub/dir/file
23
+Bello
24
EOF
25
26
-test_expect_success 'apply --root -p (1)' '
26
+test_expect_success 'apply --directory -p (1)' '
27
28
- git apply --root=some/sub -p3 --index patch &&
28
+ git apply --directory=some/sub -p3 --index patch &&
29
test Bello = $(git show :some/sub/dir/file) &&
30
test Bello = $(cat some/sub/dir/file)
31
32
'
33
34
-test_expect_success 'apply --root -p (2) ' '
34
+test_expect_success 'apply --directory -p (2) ' '
35
36
git reset --hard initial &&
37
- git apply --root=some/sub/ -p3 --index patch &&
37
+ git apply --directory=some/sub/ -p3 --index patch &&
38
test Bello = $(git show :some/sub/dir/file) &&
39
test Bello = $(cat some/sub/dir/file)
40