git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] mergetool: check return value from read

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 1, 2011, 23:11 UTC
Message-ID
<7vaacxoauj.fsf@alter.siamese.dyndns.org>

The process may not even have the standard input open in which case it will get stuck in an infinite loop to prompt and read nothing.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-mergetool.sh |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 3aab5aa..3c157bc 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -100,7 +100,7 @@ resolve_deleted_merge () {
 	else
 	    printf "Use (c)reated or (d)eleted file, or (a)bort? "
 	fi
-	read ans
+	read ans || return 1
 	case "$ans" in
 	    [mMcC]*)
 		git add -- "$MERGED"
@@ -122,7 +122,7 @@ resolve_deleted_merge () {
 resolve_submodule_merge () {
     while true; do
 	printf "Use (l)ocal or (r)emote, or (a)bort? "
-	read ans
+	read ans || return 1
 	case "$ans" in
 	    [lL]*)
 		if ! local_present; then
@@ -249,7 +249,7 @@ merge_file () {
     describe_file "$remote_mode" "remote" "$REMOTE"
     if "$prompt" = true; then
 	printf "Hit return to start merge resolution tool (%s): " "$merge_tool"
-	read ans
+	read ans || return 1
     fi
 
     if base_present; then
@@ -320,7 +320,7 @@ done
 prompt_after_failed_merge() {
     while true; do
 	printf "Continue merging other unresolved paths (y/n) ? "
-	read ans
+	read ans || return 1
 	case "$ans" in
 
 	    [yY]*)
Message 1 of 1 in “mergetool: check return value from read”
  1. mergetool: check return value from readJunio C Hamano, Jul 1, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.