threads / patch / 12486

patch, 3 partsam: read from the right mailbox when started from a subdirectory

Subject: [PATCH 1/3] am: read from the right mailbox when started from a subdirectory

## tl;dr

4 messages between Mar 4, 2008 and Mar 4, 2008. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Junio C Hamano· Mar 4, 2008, 08:25 UTC · lore

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>
---
 * This is a fixed-up version of an earlier patch I sent to Jeff and the
   list, and should be considered as a bugfix.
 git-am.sh            |   25 ++++++++++++++++-
 t/t4150-am-subdir.sh |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 2 deletions(-)
 create mode 100755 t/t4150-am-subdir.sh
Show changes to 2 files +95 −2

git-am.sh, t/t4150-am-subdir.sh

diff --git a/git-am.sh b/git-am.sh
index a2c6fea..2b5bbb7 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -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
@@ -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=
 
@@ -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)
@@ -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
diff --git a/t/t4150-am-subdir.sh b/t/t4150-am-subdir.sh
new file mode 100755
index 0000000..929d2cb
--- /dev/null
+++ b/t/t4150-am-subdir.sh
@@ -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
-- 
1.5.4.3.529.gb25fb
Junio C Hamano· Mar 4, 2008, 08:25 UTC · re: Junio C Hamano · lore

[PATCH 2/3] am: remove support for -d .dotest

It has been supported for a long time, but I do not think this feature has been in use in the real world at all. We would eventually move this out of the toplevel of the work tree and to somewhere under $GIT_DIR, so let's remove the command line option to specify the location now.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-am.sh |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)
Show changes to git-am.sh +5 −9
diff --git a/git-am.sh b/git-am.sh
index 2b5bbb7..25129e6 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -9,7 +9,7 @@ git-am [options] <mbox>|<Maildir>...
 git-am [options] --resolved
 git-am [options] --skip
 --
-d,dotest=       use <dir> and not .dotest
+d,dotest=       (removed -- do not use)
 i,interactive   run interactively
 b,binary        pass --allo-binary-replacement to git-apply
 3,3way          allow fall back on 3way merging if needed
@@ -50,10 +50,6 @@ stop_here_user_resolve () {
     then
         cmdline="$cmdline -3"
     fi
-    if test '.dotest' != "$dotest"
-    then
-        cmdline="$cmdline -d=$dotest"
-    fi
     echo "When you have resolved this problem run \"$cmdline --resolved\"."
     echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"."
 
@@ -125,7 +121,7 @@ reread_subject () {
 }
 
 prec=4
-dotest="${prefix}.dotest"
+dotest=".dotest"
 sign= utf8=t keep= skip= interactive= resolved= binary=
 resolvemsg= resume=
 git_apply_opt=
@@ -152,8 +148,8 @@ do
 	--skip)
 		skip=t ;;
 	-d|--dotest)
-		shift
-		case "$1" in /*) dotest=$1;; *) dotest="$prefix$1" ;; esac ;;
+		die "-d option is not longer supported.  Do not use."
+		;;
 	--resolvemsg)
 		shift; resolvemsg=$1 ;;
 	--whitespace)
@@ -189,7 +185,7 @@ then
 	0,)
 		# No file input but without resume parameters; catch
 		# user error to feed us a patch from standard input
-		# when there is already .dotest.  This is somewhat
+		# when there is already $dotest.  This is somewhat
 		# unreliable -- stdin could be /dev/null for example
 		# and the caller did not intend to feed us a patch but
 		# wanted to continue unattended.
-- 
1.5.4.3.529.gb25fb
Junio C Hamano· Mar 4, 2008, 08:25 UTC · re: Junio C Hamano · lore

[PATCH 3/3] am: --rebasing

The new option --rebasing is used internally for rebase to tell am that it is being used for its purpose. This would leave .dotest/rebasing to help "completion" scripts tell if the ongoing operation is am or rebase.

Also the option at the same time stands for --binary, -3 and -k which are always given when rebase drives am as its backend.

Using the information "am" leaves, git-completion.bash tells ongoing rebase and am apart.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 contrib/completion/git-completion.bash |   10 +++++++++-
 git-am.sh                              |   13 +++++++++++--
 git-rebase.sh                          |    2 +-
 3 files changed, 21 insertions(+), 4 deletions(-)
Show changes to 3 files +21 −4

contrib/completion/git-completion.bash, git-am.sh, git-rebase.sh

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8f70e1e..5ae8799 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -70,7 +70,15 @@ __git_ps1 ()
 		local b
 		if [ -d "$g/../.dotest" ]
 		then
-			r="|AM/REBASE"
+			if test -f "$g/../.dotest/rebasing"
+			then
+				r="|REBASE"
+			elif test -f "$g/../.dotest/applying"
+			then
+				r="|AM"
+			else
+				r="|AM/REBASE"
+			fi
 			b="$(git symbolic-ref HEAD 2>/dev/null)"
 		elif [ -f "$g/.dotest-merge/interactive" ]
 		then
diff --git a/git-am.sh b/git-am.sh
index 25129e6..db8171c 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -21,7 +21,8 @@ C=              pass it through git-apply
 p=              pass it through git-apply
 resolvemsg=     override error message when patch failure occurs
 r,resolved      to be used after a patch failure
-skip            skip the current patch"
+skip            skip the current patch
+rebasing        (internal use for git-rebase)"
 
 . git-sh-setup
 prefix=$(git rev-parse --show-prefix)
@@ -122,7 +123,7 @@ reread_subject () {
 
 prec=4
 dotest=".dotest"
-sign= utf8=t keep= skip= interactive= resolved= binary=
+sign= utf8=t keep= skip= interactive= resolved= binary= rebasing=
 resolvemsg= resume=
 git_apply_opt=
 
@@ -147,6 +148,8 @@ do
 		resolved=t ;;
 	--skip)
 		skip=t ;;
+	--rebasing)
+		rebasing=t threeway=t keep=t binary=t ;;
 	-d|--dotest)
 		die "-d option is not longer supported.  Do not use."
 		;;
@@ -237,6 +240,12 @@ else
 	echo "$utf8" >"$dotest/utf8"
 	echo "$keep" >"$dotest/keep"
 	echo 1 >"$dotest/next"
+	if test -n "$rebasing"
+	then
+		: >"$dotest/rebasing"
+	else
+		: >"$dotest/applying"
+	fi
 fi
 
 case "$resolved" in
diff --git a/git-rebase.sh b/git-rebase.sh
index 6b9af96..452c5e7 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -376,7 +376,7 @@ fi
 if test -z "$do_merge"
 then
 	git format-patch -k --stdout --full-index --ignore-if-in-upstream "$upstream"..ORIG_HEAD |
-	git am $git_am_opt --binary -3 -k --resolvemsg="$RESOLVEMSG" &&
+	git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
 	move_to_original_branch
 	ret=$?
 	test 0 != $ret -a -d .dotest &&
-- 
1.5.4.3.529.gb25fb
Jay Soffian· Mar 4, 2008, 08:57 UTC · re: Junio C Hamano · lore

Re: [PATCH 2/3] am: remove support for -d .dotest

On Tue, Mar 4, 2008 at 3:25 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 7 quoted lines
> @@ -152,8 +148,8 @@ do
>        --skip)
>                skip=t ;;
>        -d|--dotest)
> -               shift
> -               case "$1" in /*) dotest=$1;; *) dotest="$prefix$1" ;; esac ;;
> +               die "-d option is not longer supported.  Do not use."
s/not longer/no longer/

Also, probably want to remove mention of the option from Documentation/git-am.txt as well.

j.

← back to recent threads