Skip to contentSkip to conversation

Allow passing of --directory to git-am.

PATCH In review Simon 'corecode' Schubert 4 participants 13 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow passing of --directory to git-am.

We need to play some shell tricks to be able to pass directory names which contain spaces and/or quotes.

---

Quoted 4 lines · Boyd Stephen Smith Jr.

I'm thinking your sed line doesn't do what you think it does. You probably want something like:

bss@monster:~$ echo "don't" | sed -e "s/'/'\\\\''/g"
don'\''t

Thanks, I clearly did not test this well enough.

 git-am.sh |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
git-am.sh +5 -3
index aa60261..3baff4e 100755
@@ -16,6 +16,7 @@ s,signoff       add a Signed-off-by line to the commit message
 u,utf8          recode into utf8 (default)
 k,keep          pass -k flag to git-mailinfo
 whitespace=     pass it through git-apply
+directory=      pass it through git-apply
 C=              pass it through git-apply
 p=              pass it through git-apply
 resolvemsg=     override error message when patch failure occurs
@@ -155,8 +156,9 @@ do
 		;;
 	--resolvemsg)
 		shift; resolvemsg=$1 ;;
-	--whitespace)
-		git_apply_opt="$git_apply_opt $1=$2"; shift ;;
+	--whitespace|--directory)
+		quot=$(echo "$2" | sed -e "s/'/'\\\''/g")
+		git_apply_opt="$git_apply_opt $1='$quot'"; shift ;;
 	-C|-p)
 		git_apply_opt="$git_apply_opt $1$2"; shift ;;
 	--)
@@ -454,7 +456,7 @@ do
 
 	case "$resolved" in
 	'')
-		git apply $git_apply_opt --index "$dotest/patch"
+		eval git apply $git_apply_opt --index '"$dotest/patch"'
 		apply_status=$?
 		;;
 	t)
Signature · 1 line
1.6.1.rc1.45.g123ed.dirty
#1 lore raw
Quoted 8 lines · Simon 'corecode' Schubert
Quoted 1 line · Boyd Stephen Smith Jr.

I'm thinking your sed line doesn't do what you think it does. You

probably

Quoted 3 lines

want something like:

bss@monster:~$ echo "don't" | sed -e "s/'/'\\\\''/g"
don'\''t

Thanks, I clearly did not test this well enough.

Maybe it would be a good idea to add a test to the test script, then?

-Peff

#2 lore raw
In reply to Simon 'corecode' Schubert
Quoted 2 lines · Simon 'corecode' Schubert

We need to play some shell tricks to be able to pass directory names which contain spaces and/or quotes.

There already was an earlier attempt for this feature by Kevin Ballard, which had issues I pointed out:

http://thread.gmane.org/gmane.comp.version-control.git/94335/focus=94456

The patch was carried for a few weeks in 'pu' but was dropped due to lack of follow-up updates.

Does your version address the issues Kevin's one had?

#3 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · Simon 'corecode' Schubert

We need to play some shell tricks to be able to pass directory names which contain spaces and/or quotes.

There already was an earlier attempt for this feature by Kevin Ballard, which had issues I pointed out:

Quoted 6 lines

http://thread.gmane.org/gmane.comp.version-control.git/94335/focus=94456

The patch was carried for a few weeks in 'pu' but was dropped due to lack of follow-up updates.

Does your version address the issues Kevin's one had?

You mean not storing/restoring the flags across an invocation? No, that's a different thing. My patch only adds the --directory option, it does not fix the previously existing bug.

cheers
simon

Signature · 4 lines
  <3 the future  +++  RENT this banner advert  +++   ASCII Ribbon   /"\
  rock the past  +++  space for low €€€ NOW!1  +++     Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \
#4 lore raw
Quoted 3 lines · Simon 'corecode' Schubert

You mean not storing/restoring the flags across an invocation? No, that's a different thing. My patch only adds the --directory option, it does not fix the previously existing bug.

The question is if it _introduces_ a bug that the directory given in the initial invocation of "git am --directory=foo" is lost if an patch does not apply and you need to manually resolve and continue.

If it does not introduce such a bug, you do not have the same issue as the old patch. Otherwise you have the same issue as the old patch. The question was if you have the same issue or you don't. Yes? No?

#5 lore raw
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Simon 'corecode' Schubert

You mean not storing/restoring the flags across an invocation? No, that's a different thing. My patch only adds the --directory option, it does not fix the previously existing bug.

Quoted 7 lines

The question is if it _introduces_ a bug that the directory given in the initial invocation of "git am --directory=foo" is lost if an patch does not apply and you need to manually resolve and continue.

If it does not introduce such a bug, you do not have the same issue as the old patch. Otherwise you have the same issue as the old patch. The question was if you have the same issue or you don't. Yes? No?

Yes, that's the issue. In this regard it behaves bug-compatible with the -p and -C options.

Signature · 4 lines
  <3 the future  +++  RENT this banner advert  +++   ASCII Ribbon   /"\
  rock the past  +++  space for low €€€ NOW!1  +++     Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \
#6 lore raw
Quoted 11 lines · Simon 'corecode' Schubert
Quoted 10 lines · Junio C Hamano
Quoted 3 lines · Simon 'corecode' Schubert

You mean not storing/restoring the flags across an invocation? No, that's a different thing. My patch only adds the --directory option, it does not fix the previously existing bug.

The question is if it _introduces_ a bug that the directory given in the initial invocation of "git am --directory=foo" is lost if an patch does not apply and you need to manually resolve and continue.

Quoted 6 lines
Quoted 3 lines

If it does not introduce such a bug, you do not have the same issue as the old patch. Otherwise you have the same issue as the old patch. The question was if you have the same issue or you don't. Yes? No?

Yes, that's the issue. In this regard it behaves bug-compatible with the -p and -C options.

If that is the case, and assuming that propagating -C/-p would be a good idea (which I am not sure yet), the patch I sent out earlier (which was flawed somewhat; it should use "$git_apply_opt_extra" where it invokes the "git apply" command) with necessary fix would serve as the basis to implement --directory=<dir>?

#7 lore raw
Quoted 5 lines · Junio C Hamano

If that is the case, and assuming that propagating -C/-p would be a good idea (which I am not sure yet), the patch I sent out earlier (which was flawed somewhat; it should use "$git_apply_opt_extra" where it invokes the "git apply" command) with necessary fix would serve as the basis to implement --directory=<dir>?

certainly. I'll be travelling, so don't expect anything real soon, will resubmit unless I forget.

Signature · 4 lines
  <3 the future  +++  RENT this banner advert  +++   ASCII Ribbon   /"\
  rock the past  +++  space for low €€€ NOW!1  +++     Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \
#8 lore raw
In reply to Junio C Hamano
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Simon 'corecode' Schubert

You mean not storing/restoring the flags across an invocation? No, that's a different thing. My patch only adds the --directory option, it does not fix the previously existing bug.

Quoted 7 lines

The question is if it _introduces_ a bug that the directory given in the initial invocation of "git am --directory=foo" is lost if an patch does not apply and you need to manually resolve and continue.

If it does not introduce such a bug, you do not have the same issue as the old patch. Otherwise you have the same issue as the old patch. The question was if you have the same issue or you don't. Yes? No?

I think this fixes the --whitespace=* one, although I obviously haven't tried to use it myself extensively.

The third hunk is just a style fix. "am" is written in a quite old fashioned way.

-- >8 --
Subject: [PATCH] git-am --whitespace: do not lose the command line option

When you start "git am --whitespace=fix" and the patch application process is interrupted by an unapplicable patch early in the series, after fixing the offending patch, the remainder of the patch should be processed still with --whitespace=fix when restarted with "git am --resolved".

The commit 67dad68 (add -C[NUM] to git-am, 2007-02-08) broke this long time ago. This should fix it.

---
 git-am.sh |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
git-am.sh +4 -4
index aa60261..1bf70d4 100755
@@ -121,7 +121,7 @@ It does not apply to blobs recorded in its index."
 
 prec=4
 dotest="$GIT_DIR/rebase-apply"
-sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
+sign= utf8=t keep= skip= interactive= resolved= rebasing= abort= ws=
 resolvemsg= resume=
 git_apply_opt=
 
@@ -156,7 +156,7 @@ do
 	--resolvemsg)
 		shift; resolvemsg=$1 ;;
 	--whitespace)
-		git_apply_opt="$git_apply_opt $1=$2"; shift ;;
+		ws="--whitespace=$2"; shift ;;
 	-C|-p)
 		git_apply_opt="$git_apply_opt $1$2"; shift ;;
 	--)
@@ -283,7 +283,7 @@ if test "$(cat "$dotest/keep")" = t
 then
 	keep=-k
 fi
-ws=`cat "$dotest/whitespace"`
+ws=$(cat "$dotest/whitespace")
 if test "$(cat "$dotest/sign")" = t
 then
 	SIGNOFF=`git var GIT_COMMITTER_IDENT | sed -e '
@@ -454,7 +454,7 @@ do
 
 	case "$resolved" in
 	'')
-		git apply $git_apply_opt --index "$dotest/patch"
+		git apply $git_apply_opt $ws --index "$dotest/patch"
 		apply_status=$?
 		;;
 	t)
Signature · 1 line
1.6.1.rc1.60.g1d1d7
#9 lore raw

PATCH 1/1 git-am: propagate -C/-p as well

Quoted 2 lines · Junio C Hamano

I think this fixes the --whitespace=* one, although I obviously haven't tried to use it myself extensively.

This one comes on top of it *if* you want to propagate -C/-p as well, but I think it might be a wrong idea to propagate these to begin with.

Just like --3way is a one-shot option to deal with a single unapplicable patch (because it was based on an old version) in the whole series, and is designed not to get propagated, I suspect that people use -C<n> to fix a single broken patch and they may expect it not to apply to the whole series.

The breakage --whitespace deals with is an attribute of the submitter (use of a broken editor and lack of diligence). You most often feed a single series from the same submitter in the same mbox to "git am", preserving the --whitespace=fix option during the same "am" run makes sense, and somewhat more importantly, even though the option indeed modifies what you received, the change the option causes and the risk of breaking the semantics of the patch is minimum. I am not sure the breakage --3way deals with falls into the exactly the same category, but it is similar (if the first patch in the series was based on an old version, it is very likely that the subsequent ones are also based on the same old version). So after all it might be better to propagate --3way as well (which this patch does not do).

If we decide that propagating --3way is a good thing, then it would be equally good to propagate -C, -p and --directory options.

I dunno.

 git-am.sh |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)
git-am.sh +6 -8
index 1bf70d4..a35e07a 100755
@@ -121,7 +121,7 @@ It does not apply to blobs recorded in its index."
 
 prec=4
 dotest="$GIT_DIR/rebase-apply"
-sign= utf8=t keep= skip= interactive= resolved= rebasing= abort= ws=
+sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
 resolvemsg= resume=
 git_apply_opt=
 
@@ -155,9 +155,7 @@ do
 		;;
 	--resolvemsg)
 		shift; resolvemsg=$1 ;;
-	--whitespace)
-		ws="--whitespace=$2"; shift ;;
-	-C|-p)
+	-C|-p|--whitespace)
 		git_apply_opt="$git_apply_opt $1$2"; shift ;;
 	--)
 		shift; break ;;
@@ -247,10 +245,10 @@ else
 		exit 1
 	}
 
-	# -s, -u, -k and --whitespace flags are kept for the
-	# resuming session after a patch failure.
+	# -s, -u, -k, --whitespace, -C and -p flags are kept
+	# for the resuming session after a patch failure.
 	# -3 and -i can and must be given when resuming.
-	echo " $ws" >"$dotest/whitespace"
+	echo " $git_apply_opt" >"$dotest/apply_opt_extra"
 	echo "$sign" >"$dotest/sign"
 	echo "$utf8" >"$dotest/utf8"
 	echo "$keep" >"$dotest/keep"
@@ -283,7 +281,7 @@ if test "$(cat "$dotest/keep")" = t
 then
 	keep=-k
 fi
-ws=$(cat "$dotest/whitespace")
+apply_opt_extra=$(cat "$dotest/apply_opt_extra")
 if test "$(cat "$dotest/sign")" = t
 then
 	SIGNOFF=`git var GIT_COMMITTER_IDENT | sed -e '
#10 lore raw
In reply to Simon 'corecode' Schubert
Quoted 22 lines · Simon 'corecode' Schubert

We need to play some shell tricks to be able to pass directory names which contain spaces and/or quotes.

---

Quoted 4 lines · Boyd Stephen Smith Jr.

I'm thinking your sed line doesn't do what you think it does. You probably want something like:

bss@monster:~$ echo "don't" | sed -e "s/'/'\\\\''/g"
don'\''t

Thanks, I clearly did not test this well enough.

  git-am.sh |    8 +++++---
  1 files changed, 5 insertions(+), 3 deletions(-)
git-am.sh +0 -0
index aa60261..3baff4e 100755

git-am.sh s,signoff add a Signed-off-by line to the commit message · line 19

Quoted 4 lines
git-am.sh +1 -0
@@ -16,6 +16,7 @@ s,signoff       add a Signed-off-by line to the commit message
  u,utf8          recode into utf8 (default)
  k,keep          pass -k flag to git-mailinfo
  whitespace=     pass it through git-apply
+directory=      pass it through git-apply

Shouldn't it be

+ directory= pass it through git-apply

to have it aligned like the rest of it?

By the way, your patch looks whitespace damaged, although only context for the above chunk was wrapped...

git-am.sh do · line 160

Quoted 11 lines
git-am.sh +2 -2
  C=              pass it through git-apply
  p=              pass it through git-apply
  resolvemsg=     override error message when patch failure occurs
@@ -155,8 +156,9 @@ do
  		;;
  	--resolvemsg)
  		shift; resolvemsg=$1 ;;
-	--whitespace)
-		git_apply_opt="$git_apply_opt $1=$2"; shift ;;
+	--whitespace|--directory)
+		quot=$(echo "$2" | sed -e "s/'/'\\\''/g")

Why not simply use "git rev-parse --sq"?

git-am.sh do · line 459

Quoted 10 lines
git-am.sh +2 -1
+		git_apply_opt="$git_apply_opt $1='$quot'"; shift ;;
  	-C|-p)
  		git_apply_opt="$git_apply_opt $1$2"; shift ;;
  	--)
@@ -454,7 +456,7 @@ do
 
  	case "$resolved" in
  	'')
-		git apply $git_apply_opt --index "$dotest/patch"
+		eval git apply $git_apply_opt --index '"$dotest/patch"'

Why eval?

Quoted 5 lines
git-am.sh +0 -0
  		apply_status=$?
  		;;
  	t)
Signature · 1 line
1.6.1.rc1.45.g123ed.dirty

Hmmm...

Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#11 lore raw
Quoted 8 lines · Jakub Narebski

Shouldn't it be

+ directory= pass it through git-apply

to have it aligned like the rest of it?

By the way, your patch looks whitespace damaged, although only context for the above chunk was wrapped...

Thunderbird must have pummeled it. No clue why it does that though. Black magic software.

Quoted 10 lines

git-am.sh do · line 160

Quoted 8 lines
git-am.sh +2 -2
@@ -155,8 +156,9 @@ do
  		;;
  	--resolvemsg)
  		shift; resolvemsg=$1 ;;
-	--whitespace)
-		git_apply_opt="$git_apply_opt $1=$2"; shift ;;
+	--whitespace|--directory)
+		quot=$(echo "$2" | sed -e "s/'/'\\\''/g")

Why not simply use "git rev-parse --sq"?

What I need is to convert $2 into a form suitable for quoting, does git rev-parse --sq do that?

Quoted 6 lines
Quoted 6 lines
git-am.sh +1 -0
+		git_apply_opt="$git_apply_opt $1='$quot'"; shift ;;
  	-C|-p)
  		git_apply_opt="$git_apply_opt $1$2"; shift ;;
  	--)
@@ -454,7 +456,7 @@ do
 
Quoted 6 lines

git-am.sh do · line 459

Quoted 4 lines
git-am.sh +1 -1
  	case "$resolved" in
  	'')
-		git apply $git_apply_opt --index "$dotest/patch"
+		eval git apply $git_apply_opt --index '"$dotest/patch"'

Why eval?

I quoted the above variable, so I now need to unquote it, that's done by eval.

Signature · 4 lines
  <3 the future  +++  RENT this banner advert  +++   ASCII Ribbon   /"\
  rock the past  +++  space for low €€€ NOW!1  +++     Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \
#12 lore raw
Quoted 14 lines · Simon 'corecode' Schubert
Quoted 12 lines · Jakub Narebski

git-am.sh do · line 160

Quoted 8 lines · Simon 'corecode' Schubert
git-am.sh +2 -2
@@ -155,8 +156,9 @@ do
  		;;
  	--resolvemsg)
  		shift; resolvemsg=$1 ;;
-	--whitespace)
-		git_apply_opt="$git_apply_opt $1=$2"; shift ;;
+	--whitespace|--directory)
+		quot=$(echo "$2" | sed -e "s/'/'\\\''/g")

Why not simply use "git rev-parse --sq"?

Quoted 2 lines

What I need is to convert $2 into a form suitable for quoting, does git rev-parse --sq do that?

  $ git rev-parse --sq -- "don't do that"
  '--' 'don'\''t do that'

Without terminating newline. The '--' is needed because otherwise git-rev-parse expects revisions... and doesn't find any.

By the way you could both simplify option parsing _and_ take care of proper quoting by using --parseopt, i.e. use git-rev-parse in PARSEOPT mode. But that is more involved change.

Quoted 10 lines
Quoted 8 lines

git-am.sh do · line 459

Quoted 6 lines
git-am.sh +1 -1
@@ -454,7 +456,7 @@ do
 
  	case "$resolved" in
  	'')
-		git apply $git_apply_opt --index "$dotest/patch"
+		eval git apply $git_apply_opt --index '"$dotest/patch"'

Why eval?

I quoted the above variable, so I now need to unquote it, that's done by eval.

Ah.

Signature · 2 lines
Jakub Narebski
Poland