Skip to content

Commit f6dff11

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 190c1cd commit f6dff11

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

git-am.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,10 +663,7 @@ do
663663
[eE]*) git_editor "$dotest/final-commit"
664664
action=again ;;
665665
[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" ;;
670667
*) action=again ;;
671668
esac
672669
done

git-sh-setup.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ git_editor() {
107107
eval "$GIT_EDITOR" '"$@"'
108108
}
109109
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+
110123
sane_grep () {
111124
GREP_OPTIONS= LC_ALL=C grep "$@"
112125
}

0 commit comments

Comments
 (0)