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

[PATCH] mergetool: Remove explicit references to /dev/tty

From
Charles Bailey <charles@hashpling.org>
Date
Aug 20, 2010, 11:17 UTC
Message-ID
<1282303049-11201-1-git-send-email-charles@hashpling.org>
In-Reply-To
<20100820035236.GA18267@gmail.com>

mergetool used /dev/tty to switch back to receiving input from the user via inside a block with a redirected stdin.

This harms testability, so change mergetool to save its original stdin to an alternative fd in this block and restore it for those sub-commands that need the original stdin.

Signed-off-by: Charles Bailey <charles@hashpling.org>
---

This works on my fedora 12 box with bash. The redirects should be standard but this could do with some testing on other bourne shell implementations.

 git-mergetool--lib.sh |    2 +-
 git-mergetool.sh      |    7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index 51dd0d6..b5e1943 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -35,7 +35,7 @@ check_unchanged () {
 		while true; do
 			echo "$MERGED seems unchanged."
 			printf "Was the merge successful? [y/n] "
-			read answer < /dev/tty
+			read answer
 			case "$answer" in
 			y*|Y*) status=0; break ;;
 			n*|N*) status=1; break ;;
diff --git a/git-mergetool.sh b/git-mergetool.sh
index bd7ab02..84edf7d 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -292,14 +292,15 @@ if test $# -eq 0 ; then
     printf "Merging:\n"
     printf "$files\n"
 
-    files_to_merge |
+    # Save original stdin to fd 3
+    files_to_merge 3<&0 |
     while IFS= read i
     do
 	if test $last_status -ne 0; then
-	    prompt_after_failed_merge < /dev/tty || exit 1
+	    prompt_after_failed_merge <&3 || exit 1
 	fi
 	printf "\n"
-	merge_file "$i" < /dev/tty > /dev/tty
+	merge_file "$i" <&3
 	last_status=$?
 	if test $last_status -ne 0; then
 	    rollup_status=1
-- 
1.7.2.2.110.gf04b9.dirty
Previous: Jonathan NiederNext: Jonathan Nieder
Message 12 of 16 in “Status of conflicted files resolved with rerere”
  1. Magnus BäckAug 12, 2010
  2. Avery PennarunAug 12, 2010
  3. Jay SoffianAug 13, 2010
  4. David AguilarAug 15, 2010
  5. Junio C HamanoAug 15, 2010
  6. Magnus BäckAug 15, 2010
  7. mergetool: Skip autoresolved pathsDavid Aguilar, Aug 17, 2010
  8. Thomas RastAug 19, 2010
  9. David AguilarAug 20, 2010
  10. Charles BaileyAug 20, 2010
  11. Jonathan NiederAug 20, 2010
  12. mergetool: Remove explicit references to /dev/ttyCharles Bailey, Aug 20, 2010
  13. Jonathan NiederAug 20, 2010
  14. Charles BaileyAug 20, 2010
  15. Jonathan NiederAug 20, 2010
  16. mergetool: Remove explicit references to /dev/ttyCharles Bailey, Aug 20, 2010

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.