# [PATCH] Allow passing of --directory to git-am.

2 messages from 2008-12-04 to 2008-12-04. Participants: Simon 'corecode' Schubert, Boyd Stephen Smith Jr..
Thread: https://gitlist.dev/t/16596

## Simon 'corecode' Schubert, 2008-12-04 17:04

Subject: [PATCH] Allow passing of --directory to git-am.
Message-ID: <49380D84.5050403@fs.ei.tum.de>
URL: https://gitlist.dev/e/49380D84.5050403%40fs.ei.tum.de

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

Signed-off-by: Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
---
  git-am.sh |    8 +++++---
  1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index aa60261..4052d7d 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -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)
-- 
1.6.1.rc1.45.g123ed.dirty

```

## Boyd Stephen Smith Jr., 2008-12-04 18:28

Subject: Re: [PATCH] Allow passing of --directory to git-am.
Message-ID: <200812041228.58885.bss03@volumehost.net>
URL: https://gitlist.dev/e/200812041228.58885.bss03%40volumehost.net
In-Reply-To: <49380D84.5050403@fs.ei.tum.de>

```
On Thursday 04 December 2008, Simon 'corecode' Schubert 
<corecode@fs.ei.tum.de> wrote about '[PATCH] Allow passing of --directory 
to git-am.':
>-	--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 ;;

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

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
-- 
Boyd Stephen Smith Jr.                     ,= ,-_-. =. 
bss03@volumehost.net                      ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' 
http://iguanasuicide.org/                      \_/     

```
