From f55638874774acc1e13a046353449ebc8734ab08 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 6 Jul 2008 18:36:01 -0700 Subject: [PATCH] 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 --- Documentation/git-apply.txt | 8 ++++++-- builtin-apply.c | 4 ++-- t/t4128-apply-root.sh | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt index 63fce5369..3cd3179ff 100644 --- a/Documentation/git-apply.txt +++ b/Documentation/git-apply.txt @@ -14,7 +14,7 @@ SYNOPSIS [--allow-binary-replacement | --binary] [--reject] [-z] [-pNUM] [-CNUM] [--inaccurate-eof] [--cached] [--whitespace=] - [--exclude=PATH] [--root=] [--verbose] [...] + [--exclude=PATH] [--directory=] [--verbose] [...] DESCRIPTION ----------- @@ -177,9 +177,13 @@ behavior: current patch being applied will be printed. This option will cause additional information to be reported. ---root=:: +--directory=:: Prepend to all filenames. If a "-p" argument was passed, too, it is applied before prepending the new root. ++ +For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh` +can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by +running `git apply --directory=modules/git-gui`. Configuration ------------- diff --git a/builtin-apply.c b/builtin-apply.c index 6c3db60b6..c242bbd83 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -3130,8 +3130,8 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) inaccurate_eof = 1; continue; } - if (!prefixcmp(arg, "--root=")) { - arg += strlen("--root="); + if (!prefixcmp(arg, "--directory=")) { + arg += strlen("--directory="); root_len = strlen(arg); if (root_len && arg[root_len - 1] != '/') { char *new_root; diff --git a/t/t4128-apply-root.sh b/t/t4128-apply-root.sh index b65024545..2dd0c75f9 100755 --- a/t/t4128-apply-root.sh +++ b/t/t4128-apply-root.sh @@ -23,18 +23,18 @@ diff a/bla/blub/dir/file b/bla/blub/dir/file +Bello EOF -test_expect_success 'apply --root -p (1)' ' +test_expect_success 'apply --directory -p (1)' ' - git apply --root=some/sub -p3 --index patch && + git apply --directory=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) ' ' +test_expect_success 'apply --directory -p (2) ' ' git reset --hard initial && - git apply --root=some/sub/ -p3 --index patch && + git apply --directory=some/sub/ -p3 --index patch && test Bello = $(git show :some/sub/dir/file) && test Bello = $(cat some/sub/dir/file) -- 2.30.2