# [PATCH 0/3] Improve git-am error messages

7 messages from 2010-06-01 to 2010-06-01. Participants: Ramkumar Ramachandra, Johannes Sixt, Junio C Hamano.
Thread: https://gitlist.dev/t/23963

## Ramkumar Ramachandra, 2010-06-01 09:20

Subject: [PATCH 0/3] Improve git-am error messages
Message-ID: <1275384022-12131-1-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1275384022-12131-1-git-send-email-artagnon%40gmail.com

```
Hi,

This patch series aims to improve some of the error messages in git-am
that I came across.

-- Ram

Ramkumar Ramachandra (3):
  Initialize cmdline globally, not in stop_here_user_resolve
  Display some help text when patch is empty
  Remove stray error message from sed when continuing without changes

 git-am.sh |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

```

## Ramkumar Ramachandra, 2010-06-01 09:20

Subject: [PATCH 1/3] Set cmdline globally, not in stop_here_user_resolve
Message-ID: <1275384022-12131-2-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1275384022-12131-2-git-send-email-artagnon%40gmail.com
In-Reply-To: <1275384022-12131-1-git-send-email-artagnon@gmail.com>

```
Set the $cmdline variable globally, so it can be used in other code
fragments as well. Also, instead of hardcoding the string "git am",
use the command line argument "$0".

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 git-am.sh |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index 87ffae2..b779277 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -52,6 +52,16 @@ else
 	HAS_HEAD=
 fi
 
+cmdline="$0"
+if test '' != "$interactive"
+then
+    cmdline="$cmdline -i"
+fi
+if test '' != "$threeway"
+then
+    cmdline="$cmdline -3"
+fi
+
 sq () {
 	git rev-parse --sq-quote "$@"
 }
@@ -66,15 +76,6 @@ stop_here_user_resolve () {
 	    printf '%s\n' "$resolvemsg"
 	    stop_here $1
     fi
-    cmdline="git am"
-    if test '' != "$interactive"
-    then
-        cmdline="$cmdline -i"
-    fi
-    if test '' != "$threeway"
-    then
-        cmdline="$cmdline -3"
-    fi
     echo "When you have resolved this problem run \"$cmdline --resolved\"."
     echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"."
     echo "To restore the original branch and stop patching run \"$cmdline --abort\"."
-- 
1.7.1

```

## Ramkumar Ramachandra, 2010-06-01 09:20

Subject: [PATCH 2/3] Display some help text when patch is empty
Message-ID: <1275384022-12131-3-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1275384022-12131-3-git-send-email-artagnon%40gmail.com
In-Reply-To: <1275384022-12131-1-git-send-email-artagnon@gmail.com>

```
When a patch is found to be empty, prompt the user to use either
--skip or --abort.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 git-am.sh |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index b779277..04f02a8 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -592,6 +592,8 @@ do
 
 		test -s "$dotest/patch" || {
 			echo "Patch is empty.  Was it split wrong?"
+			echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"."
+			echo "To restore the original branch and stop patching run \"$cmdline --abort\"."
 			stop_here $this
 		}
 		rm -f "$dotest/original-commit"
-- 
1.7.1

```

## Ramkumar Ramachandra, 2010-06-01 09:20

Subject: [PATCH 3/3] Remove stray error message from sed
Message-ID: <1275384022-12131-4-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1275384022-12131-4-git-send-email-artagnon%40gmail.com
In-Reply-To: <1275384022-12131-1-git-send-email-artagnon@gmail.com>

```
When --continue is invoked without any changes, the following stray
error message appears- sed: can't read $dotest/final-commit: No such
file or directory. Remove this by making sure that the file actually
exists.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 git-am.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index 04f02a8..e61f47a 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -693,7 +693,7 @@ do
 	else
 	    action=yes
 	fi
-	FIRSTLINE=$(sed 1q "$dotest/final-commit")
+	test -e "$dotest/final-commit" && FIRSTLINE=$(sed 1q "$dotest/final-commit")
 
 	if test $action = skip
 	then
-- 
1.7.1

```

## Johannes Sixt, 2010-06-01 09:27

Subject: Re: [PATCH 1/3] Set cmdline globally, not in stop_here_user_resolve
Message-ID: <4C04D268.6070908@viscovery.net>
URL: https://gitlist.dev/e/4C04D268.6070908%40viscovery.net
In-Reply-To: <1275384022-12131-2-git-send-email-artagnon@gmail.com>

```
Am 6/1/2010 11:20, schrieb Ramkumar Ramachandra:
> Set the $cmdline variable globally, so it can be used in other code
> fragments as well. Also, instead of hardcoding the string "git am",
> use the command line argument "$0".

Did you test this? "$0" prints the full path to git-am. This does not
count as user-friendly in my book!

-- Hannes

```

## Ramkumar Ramachandra, 2010-06-01 09:36

Subject: Re: [PATCH 1/3] Set cmdline globally, not in stop_here_user_resolve
Message-ID: <AANLkTinY8Z-Y_1aFnJrojaAMs68FITt-whC0fLbpIR8h@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinY8Z-Y_1aFnJrojaAMs68FITt-whC0fLbpIR8h%40mail.gmail.com
In-Reply-To: <4C04D268.6070908@viscovery.net>

```
Hi,

> Did you test this? "$0" prints the full path to git-am. This does not
> count as user-friendly in my book!

Doesn't it print out exactly the way you invoke the application ie.
either "./git-am.sh" or "git am"? Then again, when git-am is invoked
internally by git, it possibly uses the full path instead of relying
on $PATH, and this is quite ugly. I noticed that all the other other
shell scripts in git.git also hardcode the string, and there must be a
good reason for this. Therefore I think this particular change should
be dropped.

Thanks for pointing this out.

-- Ram

```

## Junio C Hamano, 2010-06-01 17:44

Subject: Re: [PATCH 3/3] Remove stray error message from sed
Message-ID: <7veigqvea6.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7veigqvea6.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1275384022-12131-4-git-send-email-artagnon@gmail.com>

```
Ramkumar Ramachandra <artagnon@gmail.com> writes:

> When --continue is invoked without any changes, the following stray
> error message appears- sed: can't read $dotest/final-commit: No such
> file or directory. Remove this by making sure that the file actually
> exists.

>
> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> ---
>  git-am.sh |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/git-am.sh b/git-am.sh
> index 04f02a8..e61f47a 100755
> --- a/git-am.sh
> +++ b/git-am.sh
> @@ -693,7 +693,7 @@ do
>  	else
>  	    action=yes
>  	fi
> -	FIRSTLINE=$(sed 1q "$dotest/final-commit")
> +	test -e "$dotest/final-commit" && FIRSTLINE=$(sed 1q "$dotest/final-commit")

This will let the command follow the same codepath as before but the
change in behaviour is that it does not reset FIRSTLINE to an empty
string.  Does this difference affect what the user sees after this part of
the code?

I would generally prefer to use "test -f" not "-e" (simply because it came
later and I am an old-timer), but if you want to use something newer than
"test -f", it might be worth using "test -r" instead, as readability (not
existence) is what you are after anyway.

>  
>  	if test $action = skip
>  	then
> -- 
> 1.7.1

```
