Skip to content

Commit f556388

Browse files
committed
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>
1 parent 8ee4a6c commit f556388

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Documentation/git-apply.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SYNOPSIS
1414
[--allow-binary-replacement | --binary] [--reject] [-z]
1515
[-pNUM] [-CNUM] [--inaccurate-eof] [--cached]
1616
[--whitespace=<nowarn|warn|fix|error|error-all>]
17-
[--exclude=PATH] [--root=<root>] [--verbose] [<patch>...]
17+
[--exclude=PATH] [--directory=<root>] [--verbose] [<patch>...]
1818

1919
DESCRIPTION
2020
-----------
@@ -177,9 +177,13 @@ behavior:
177177
current patch being applied will be printed. This option will cause
178178
additional information to be reported.
179179

180-
--root=<root>::
180+
--directory=<root>::
181181
Prepend <root> to all filenames. If a "-p" argument was passed, too,
182182
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`.
183187

184188
Configuration
185189
-------------

builtin-apply.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,8 +3130,8 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
31303130
inaccurate_eof = 1;
31313131
continue;
31323132
}
3133-
if (!prefixcmp(arg, "--root=")) {
3134-
arg += strlen("--root=");
3133+
if (!prefixcmp(arg, "--directory=")) {
3134+
arg += strlen("--directory=");
31353135
root_len = strlen(arg);
31363136
if (root_len && arg[root_len - 1] != '/') {
31373137
char *new_root;

t/t4128-apply-root.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ diff a/bla/blub/dir/file b/bla/blub/dir/file
2323
+Bello
2424
EOF
2525

26-
test_expect_success 'apply --root -p (1)' '
26+
test_expect_success 'apply --directory -p (1)' '
2727
28-
git apply --root=some/sub -p3 --index patch &&
28+
git apply --directory=some/sub -p3 --index patch &&
2929
test Bello = $(git show :some/sub/dir/file) &&
3030
test Bello = $(cat some/sub/dir/file)
3131
3232
'
3333

34-
test_expect_success 'apply --root -p (2) ' '
34+
test_expect_success 'apply --directory -p (2) ' '
3535
3636
git reset --hard initial &&
37-
git apply --root=some/sub/ -p3 --index patch &&
37+
git apply --directory=some/sub/ -p3 --index patch &&
3838
test Bello = $(git show :some/sub/dir/file) &&
3939
test Bello = $(cat some/sub/dir/file)
4040

0 commit comments

Comments
 (0)