mergetool: Remove explicit references to /dev/tty
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. Includes additional compatibility fix from Jonathan Nieder. Tested-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Charles Bailey committed
Aug 20, 2010 at 16:25 UTC
af3147147f39274bd0d47faca196f84c4e9ec68d
2 files changed
+7
-3
git-mergetool--lib.sh
+1
-1
@@ -35,7 +35,7 @@ check_unchanged () {
35
while true; do
36
echo "$MERGED seems unchanged."
37
printf "Was the merge successful? [y/n] "
38
- read answer < /dev/tty
38
+ read answer
39
case "$answer" in
40
y*|Y*) status=0; break ;;
41
n*|N*) status=1; break ;;
git-mergetool.sh
+6
-2
@@ -271,6 +271,10 @@ if test $# -eq 0 ; then
271
echo "No files need merging"
272
exit 0
273
fi
274
+
275
+ # Save original stdin
276
+ exec 3<&0
277
+
278
echo Merging the files: "$files"
279
git ls-files -u |
280
sed -e 's/^[^ ]* //' |
@@ -278,10 +282,10 @@ if test $# -eq 0 ; then
282
while IFS= read i
283
do
284
if test $last_status -ne 0; then
281
- prompt_after_failed_merge < /dev/tty || exit 1
285
+ prompt_after_failed_merge <&3 || exit 1
286
fi
287
printf "\n"
284
- merge_file "$i" < /dev/tty > /dev/tty
288
+ merge_file "$i" <&3
289
last_status=$?
290
if test $last_status -ne 0; then
291
rollup_status=1