Skip to content

Commit

Permalink
am: read from the right mailbox when started from a subdirectory
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Mar 5, 2008
1 parent 79b1138 commit bb034f8
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
25 changes: 23 additions & 2 deletions git-am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ r,resolved to be used after a patch failure
skip skip the current patch"

. git-sh-setup
prefix=$(git rev-parse --show-prefix)
set_reflog_action am
require_work_tree
cd_to_toplevel
Expand Down Expand Up @@ -124,7 +125,8 @@ reread_subject () {
}

prec=4
dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
dotest="${prefix}.dotest"
sign= utf8=t keep= skip= interactive= resolved= binary=
resolvemsg= resume=
git_apply_opt=

Expand All @@ -150,7 +152,8 @@ do
--skip)
skip=t ;;
-d|--dotest)
shift; dotest=$1;;
shift
case "$1" in /*) dotest=$1;; *) dotest="$prefix$1" ;; esac ;;
--resolvemsg)
shift; resolvemsg=$1 ;;
--whitespace)
Expand Down Expand Up @@ -206,6 +209,24 @@ else
# Start afresh.
mkdir -p "$dotest" || exit

if test -n "$prefix" && test $# != 0
then
first=t
for arg
do
test -n "$first" && {
set x
first=
}
case "$arg" in
/*)
set "$@" "$arg" ;;
*)
set "$@" "$prefix$arg" ;;
esac
done
shift
fi
git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
rm -fr "$dotest"
exit 1
Expand Down
72 changes: 72 additions & 0 deletions t/t4150-am-subdir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/sh

test_description='git am running from a subdirectory'

. ./test-lib.sh

test_expect_success setup '
echo hello >world &&
git add world &&
test_tick &&
git commit -m initial &&
git tag initial &&
echo goodbye >world &&
git add world &&
test_tick &&
git commit -m second &&
git format-patch --stdout HEAD^ >patchfile &&
: >expect
'

test_expect_success 'am regularly from stdin' '
git checkout initial &&
git am <patchfile &&
git diff master >actual &&
diff -u expect actual
'

test_expect_success 'am regularly from file' '
git checkout initial &&
git am patchfile &&
git diff master >actual &&
diff -u expect actual
'

test_expect_success 'am regularly from stdin in subdirectory' '
rm -fr subdir &&
git checkout initial &&
(
mkdir -p subdir &&
cd subdir &&
git am <../patchfile
) &&
git diff master>actual &&
diff -u expect actual
'

test_expect_success 'am regularly from file in subdirectory' '
rm -fr subdir &&
git checkout initial &&
(
mkdir -p subdir &&
cd subdir &&
git am ../patchfile
) &&
git diff master >actual &&
diff -u expect actual
'

test_expect_success 'am regularly from file in subdirectory with full path' '
rm -fr subdir &&
git checkout initial &&
P=$(pwd) &&
(
mkdir -p subdir &&
cd subdir &&
git am "$P/patchfile"
) &&
git diff master >actual &&
diff -u expect actual
'

test_done

0 comments on commit bb034f8

Please sign in to comment.