am: read from the right mailbox when started from a subdirectory
An earlier commit c149184 (allow git-am to run in a subdirectory) taught git-am to start from a subdirectory by going up to the root of the work tree byitself, but it did not adjust the path to read the mbox from when it did so. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Mar 4, 2008 at 00:25 UTC
bb034f839a396cf0660024a59bbff61f8ef0c5af
2 files changed
+95
-2
git-am.sh
+23
-2
@@ -24,6 +24,7 @@ r,resolved to be used after a patch failure
24
skip skip the current patch"
25
26
. git-sh-setup
27
+prefix=$(git rev-parse --show-prefix)
28
set_reflog_action am
29
require_work_tree
30
cd_to_toplevel
@@ -124,7 +125,8 @@ reread_subject () {
125
}
126
127
prec=4
127
-dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
128
+dotest="${prefix}.dotest"
129
+sign= utf8=t keep= skip= interactive= resolved= binary=
130
resolvemsg= resume=
131
git_apply_opt=
132
@@ -150,7 +152,8 @@ do
152
--skip)
153
skip=t ;;
154
-d|--dotest)
153
- shift; dotest=$1;;
155
+ shift
156
+ case "$1" in /*) dotest=$1;; *) dotest="$prefix$1" ;; esac ;;
157
--resolvemsg)
158
shift; resolvemsg=$1 ;;
159
--whitespace)
@@ -206,6 +209,24 @@ else
209
# Start afresh.
210
mkdir -p "$dotest" || exit
211
212
+ if test -n "$prefix" && test $# != 0
213
+ then
214
+ first=t
215
+ for arg
216
+ do
217
+ test -n "$first" && {
218
+ set x
219
+ first=
220
+ }
221
+ case "$arg" in
222
+ /*)
223
+ set "$@" "$arg" ;;
224
+ *)
225
+ set "$@" "$prefix$arg" ;;
226
+ esac
227
+ done
228
+ shift
229
+ fi
230
git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
231
rm -fr "$dotest"
232
exit 1
t/t4150-am-subdir.sh
new
+72
@@ -0,0 +1,72 @@
1
+#!/bin/sh
2
+
3
+test_description='git am running from a subdirectory'
4
+
5
+. ./test-lib.sh
6
+
7
+test_expect_success setup '
8
+ echo hello >world &&
9
+ git add world &&
10
+ test_tick &&
11
+ git commit -m initial &&
12
+ git tag initial &&
13
+ echo goodbye >world &&
14
+ git add world &&
15
+ test_tick &&
16
+ git commit -m second &&
17
+ git format-patch --stdout HEAD^ >patchfile &&
18
+ : >expect
19
+'
20
+
21
+test_expect_success 'am regularly from stdin' '
22
+ git checkout initial &&
23
+ git am <patchfile &&
24
+ git diff master >actual &&
25
+ diff -u expect actual
26
+'
27
+
28
+test_expect_success 'am regularly from file' '
29
+ git checkout initial &&
30
+ git am patchfile &&
31
+ git diff master >actual &&
32
+ diff -u expect actual
33
+'
34
+
35
+test_expect_success 'am regularly from stdin in subdirectory' '
36
+ rm -fr subdir &&
37
+ git checkout initial &&
38
+ (
39
+ mkdir -p subdir &&
40
+ cd subdir &&
41
+ git am <../patchfile
42
+ ) &&
43
+ git diff master>actual &&
44
+ diff -u expect actual
45
+'
46
+
47
+test_expect_success 'am regularly from file in subdirectory' '
48
+ rm -fr subdir &&
49
+ git checkout initial &&
50
+ (
51
+ mkdir -p subdir &&
52
+ cd subdir &&
53
+ git am ../patchfile
54
+ ) &&
55
+ git diff master >actual &&
56
+ diff -u expect actual
57
+'
58
+
59
+test_expect_success 'am regularly from file in subdirectory with full path' '
60
+ rm -fr subdir &&
61
+ git checkout initial &&
62
+ P=$(pwd) &&
63
+ (
64
+ mkdir -p subdir &&
65
+ cd subdir &&
66
+ git am "$P/patchfile"
67
+ ) &&
68
+ git diff master >actual &&
69
+ diff -u expect actual
70
+'
71
+
72
+test_done