@matheusbsbs / matheus-bagliano / commits / b47dfe9e9c
Fork 0

git-am: add --directory=<dir> option

Thanks to a200337 (git-am: propagate -C<n>, -p<n> options as well, 2008-12-04) and commits around it, "git am" is equipped to correctly propagate the command line flags such as -C/-p/-whitespace across a patch failure and restart. It is trivial to support --directory option now, resurrecting previous attempts by Kevin and Simon. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jan 11, 2009 at 22:21 UTC b47dfe9e9c86be97fc07c4c04e26a303730f76c6
5 files changed +58 -9
Documentation/git-am.txt
+2 -5
@@ -11,7 +11,7 @@ SYNOPSIS
11 [verse]
12 'git am' [--signoff] [--keep] [--utf8 | --no-utf8]
13 [--3way] [--interactive]
14 - [--whitespace=<option>] [-C<n>] [-p<n>]
14 + [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
15 [<mbox> | <Maildir>...]
16 'git am' (--skip | --resolved | --abort)
17
@@ -60,12 +60,9 @@ default. You could use `--no-utf8` to override this.
60 available locally.
61
62 --whitespace=<option>::
63 - This flag is passed to the 'git-apply' (see linkgit:git-apply[1])
64 - program that applies
65 - the patch.
66 -
63 -C<n>::
64 -p<n>::
65 +--directory=<dir>::
66 These flags are passed to the 'git-apply' (see linkgit:git-apply[1])
67 program that applies
68 the patch.
git-am.sh
+13 -4
@@ -16,6 +16,7 @@ s,signoff add a Signed-off-by line to the commit message
16 u,utf8 recode into utf8 (default)
17 k,keep pass -k flag to git-mailinfo
18 whitespace= pass it through git-apply
19 +directory= pass it through git-apply
20 C= pass it through git-apply
21 p= pass it through git-apply
22 resolvemsg= override error message when patch failure occurs
@@ -33,6 +34,14 @@ cd_to_toplevel
34 git var GIT_COMMITTER_IDENT >/dev/null ||
35 die "You need to set your committer info first"
36
37 +sq () {
38 + for sqarg
39 + do
40 + printf "%s" "$sqarg" |
41 + sed -e 's/'\''/'\''\'\'''\''/g' -e 's/.*/ '\''&'\''/'
42 + done
43 +}
44 +
45 stop_here () {
46 echo "$1" >"$dotest/next"
47 exit 1
@@ -155,10 +164,10 @@ do
164 ;;
165 --resolvemsg)
166 shift; resolvemsg=$1 ;;
158 - --whitespace)
159 - git_apply_opt="$git_apply_opt $1=$2"; shift ;;
167 + --whitespace|--directory)
168 + git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;;
169 -C|-p)
161 - git_apply_opt="$git_apply_opt $1$2"; shift ;;
170 + git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;;
171 --)
172 shift; break ;;
173 *)
@@ -459,7 +468,7 @@ do
468
469 case "$resolved" in
470 '')
462 - git apply $git_apply_opt --index "$dotest/patch"
471 + eval 'git apply '"$git_apply_opt"' --index "$dotest/patch"'
472 apply_status=$?
473 ;;
474 t)
t/t4252-am-options.sh
+8
@@ -50,4 +50,12 @@ test_expect_success 'interrupted am -C1 -p2' '
50 grep "^Three$" file-2
51 '
52
53 +test_expect_success 'interrupted am --directory="frotz nitfol"' '
54 + rm -rf .git/rebase-apply &&
55 + git reset --hard initial &&
56 + test_must_fail git am --directory="frotz nitfol" "$tm"/am-test-5-? &&
57 + git am --skip &&
58 + grep One "frotz nitfol/file-5"
59 +'
60 +
61 test_done
t/t4252/am-test-5-1 new
+20
@@ -0,0 +1,20 @@
1 +From: A U Thor <au.thor@example.com>
2 +Date: Thu Dec 4 16:00:00 2008 -0800
3 +Subject: Six
4 +
5 +Applying this patch with --directory='frotz nitfol' should fail
6 +
7 +diff --git i/junk/file-2 w/junk/file-2
8 +index 06e567b..b6f3a16 100644
9 +--- i/junk/file-2
10 ++++ w/junk/file-2
11 +@@ -1,7 +1,7 @@
12 + One
13 + 2
14 +-3
15 ++Three
16 + 4
17 + 5
18 +-6
19 ++Six
20 + 7
t/t4252/am-test-5-2 new
+15
@@ -0,0 +1,15 @@
1 +From: A U Thor <au.thor@example.com>
2 +Date: Thu Dec 4 16:00:00 2008 -0800
3 +Subject: Six
4 +
5 +Applying this patch with --directory='frotz nitfol' should succeed
6 +
7 +diff --git i/file-5 w/file-5
8 +new file mode 100644
9 +index 000000..1d6ed9f
10 +--- /dev/null
11 ++++ w/file-5
12 +@@ -0,0 +1,3 @@
13 ++One
14 ++two
15 ++three