am: Fix launching of pager
The pagination functionality in git am has some problems: - It does not check if stdout is a tty, so it always paginates. - If $GIT_PAGER uses any environment variables, they are being ignored, since it does not run $GIT_PAGER through eval. - If $GIT_PAGER is set to the empty string, instead of passing output through to stdout, it tries to run $dotest/patch. Fix them. While at it, move the definition of git_pager() to git-sh-setup so authors of other commands are not tempted to reimplement it with the same mistakes. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Feb 14, 2010 at 23:04 UTC
f6dff119d51e0067d213068093039bb2f939d139
2 files changed
+14
-4
git-am.sh
+1
-4
@@ -663,10 +663,7 @@ do
663
[eE]*) git_editor "$dotest/final-commit"
664
action=again ;;
665
[vV]*) action=again
666
- : ${GIT_PAGER=$(git var GIT_PAGER)}
667
- : ${LESS=-FRSX}
668
- export LESS
669
- $GIT_PAGER "$dotest/patch" ;;
666
+ git_pager "$dotest/patch" ;;
667
*) action=again ;;
668
esac
669
done
git-sh-setup.sh
+13
@@ -107,6 +107,19 @@ git_editor() {
107
eval "$GIT_EDITOR" '"$@"'
108
}
109
110
+git_pager() {
111
+ if test -t 1
112
+ then
113
+ GIT_PAGER=$(git var GIT_PAGER)
114
+ else
115
+ GIT_PAGER=cat
116
+ fi
117
+ : ${LESS=-FRSX}
118
+ export LESS
119
+
120
+ eval "$GIT_PAGER" '"$@"'
121
+}
122
+
123
sane_grep () {
124
GREP_OPTIONS= LC_ALL=C grep "$@"
125
}