Skip to contentSkip to conversation

prompt: squelch error output from cat

PATCH In review Ramkumar Ramachandra 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 prompt: squelch error output from cat

The files $g/rebase-{merge,apply}/{head-name,msgnum,end} are not guaranteed to exist. When attempting to cat them, squelch the error output.

In addition to guarding against stray directories, this patch addresses a real problem:

  # on terminal 1
  $ git rebase -i master
  # ignore editor, and switch to terminal 2
  cat: .git/rebase-merge/msgnum: No such file or directory
  cat: .git/rebase-merge/end: No such file or directory
  $

---
Better commit message.

 contrib/completion/git-prompt.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
contrib/completion/git-prompt.sh +6 -6
index 86a4f3f..07a6218 100644
@@ -347,9 +347,9 @@ __git_ps1 ()
 		local step=""
 		local total=""
 		if [ -d "$g/rebase-merge" ]; then
-			b="$(cat "$g/rebase-merge/head-name")"
-			step=$(cat "$g/rebase-merge/msgnum")
-			total=$(cat "$g/rebase-merge/end")
+			b="$(cat "$g/rebase-merge/head-name" 2>/dev/null)"
+			step=$(cat "$g/rebase-merge/msgnum" 2>/dev/null)
+			total=$(cat "$g/rebase-merge/end" 2>/dev/null)
 			if [ -f "$g/rebase-merge/interactive" ]; then
 				r="|REBASE-i"
 			else
@@ -357,10 +357,10 @@ __git_ps1 ()
 			fi
 		else
 			if [ -d "$g/rebase-apply" ]; then
-				step=$(cat "$g/rebase-apply/next")
-				total=$(cat "$g/rebase-apply/last")
+				step=$(cat "$g/rebase-apply/next" 2>/dev/null)
+				total=$(cat "$g/rebase-apply/last" 2>/dev/null)
 				if [ -f "$g/rebase-apply/rebasing" ]; then
-					b="$(cat "$g/rebase-apply/head-name")"
+					b="$(cat "$g/rebase-apply/head-name" 2>/dev/null)"
 					r="|REBASE"
 				elif [ -f "$g/rebase-apply/applying" ]; then
 					r="|AM"
Signature · 1 line
1.8.3.1.383.gbc1f167.dirty