Discussion:
Cygwin + git log = no pager!
Robert Dailey
2014-02-22 05:18:44 UTC
Permalink
So it seems that the pager doesn't work by default when running `git
log` from Cygwin like it does in msysgit for Windows.

I know I can pipe to `less` but that requires the additional typing
obviously. Does anyone know how I can get the pager to work in Cygwin
for git log, reflog, and other commands like it does in msysgit?

Thanks in advance.
Chris Packham
2014-02-22 07:39:32 UTC
Permalink
Post by Robert Dailey
So it seems that the pager doesn't work by default when running `git
log` from Cygwin like it does in msysgit for Windows.
I know I can pipe to `less` but that requires the additional typing
obviously. Does anyone know how I can get the pager to work in Cygwin
for git log, reflog, and other commands like it does in msysgit?
Thanks in advance.
Add GIT_PAGER=less to your environment. I don't know if you were using
the cygwin packaged git or building from source but I'm surprised the
pager is not set by default as you actually have to define the use of
something other than less.
Robert Dailey
2014-02-23 20:33:01 UTC
Permalink
Post by Chris Packham
Post by Robert Dailey
So it seems that the pager doesn't work by default when running `git
log` from Cygwin like it does in msysgit for Windows.
I know I can pipe to `less` but that requires the additional typing
obviously. Does anyone know how I can get the pager to work in Cygwin
for git log, reflog, and other commands like it does in msysgit?
Thanks in advance.
Add GIT_PAGER=less to your environment. I don't know if you were using
the cygwin packaged git or building from source but I'm surprised the
pager is not set by default as you actually have to define the use of
something other than less.
Thanks for the response. I did set this environment variable in my
.bashrc like so:

export GIT_PAGER=less

However after I do a 'git log' it is just spitting it out all at once
and not entering the pager.
Chris Packham
2014-02-24 07:55:41 UTC
Permalink
Post by Robert Dailey
Post by Chris Packham
Post by Robert Dailey
So it seems that the pager doesn't work by default when running `git
log` from Cygwin like it does in msysgit for Windows.
I know I can pipe to `less` but that requires the additional typing
obviously. Does anyone know how I can get the pager to work in Cygwin
for git log, reflog, and other commands like it does in msysgit?
Thanks in advance.
Add GIT_PAGER=less to your environment. I don't know if you were using
the cygwin packaged git or building from source but I'm surprised the
pager is not set by default as you actually have to define the use of
something other than less.
Thanks for the response. I did set this environment variable in my
export GIT_PAGER=less
However after I do a 'git log' it is just spitting it out all at once
and not entering the pager.
Um OK that was the obvious thing to try. There is also the config
variable core.pager but GIT_PAGER should take precedence.

Could something be setting the environment variable LESS? Reading the
git-config man page for core.pager git wants to set LESS to FRSX but if
it is already set git takes that as an indication that you don't want to
set LESS automatically.

If neither of those help you probably want to let us know your cygwin
version as well as your git version and how you installed git (i.e.
built from source or installed via cygwin).
Jeff King
2014-02-24 09:06:18 UTC
Permalink
Post by Chris Packham
Post by Robert Dailey
Thanks for the response. I did set this environment variable in my
export GIT_PAGER=less
However after I do a 'git log' it is just spitting it out all at once
and not entering the pager.
Um OK that was the obvious thing to try. There is also the config
variable core.pager but GIT_PAGER should take precedence.
Presumably we are actually running what's in GIT_PAGER, but we can
double-check with:

GIT_PAGER='echo custom pager' git log

You can also try:

GIT_TRACE=1 git log

which should describe the pager being run.
Post by Chris Packham
Could something be setting the environment variable LESS? Reading the
git-config man page for core.pager git wants to set LESS to FRSX but if
it is already set git takes that as an indication that you don't want to
set LESS automatically.
We can also double-check the LESS setting in the executed pager:

GIT_PAGER='echo LESS=$LESS' git log

If we are running less, and it is using FRSX, I'd suspect some kind of
terminal weirdness with less itself. With "-F", less will quit if the
whole output can be displayed; it's possible it thinks the screen is
bigger than it is.

Trying:

GIT_PAGER=less LESS=RSX git log

might help.

-Peff
Robert Dailey
2014-02-24 19:34:34 UTC
Permalink
Post by Jeff King
Post by Chris Packham
Post by Robert Dailey
Thanks for the response. I did set this environment variable in my
export GIT_PAGER=less
However after I do a 'git log' it is just spitting it out all at once
and not entering the pager.
Um OK that was the obvious thing to try. There is also the config
variable core.pager but GIT_PAGER should take precedence.
Presumably we are actually running what's in GIT_PAGER, but we can
GIT_PAGER='echo custom pager' git log
GIT_TRACE=1 git log
which should describe the pager being run.
Post by Chris Packham
Could something be setting the environment variable LESS? Reading the
git-config man page for core.pager git wants to set LESS to FRSX but if
it is already set git takes that as an indication that you don't want to
set LESS automatically.
GIT_PAGER='echo LESS=$LESS' git log
If we are running less, and it is using FRSX, I'd suspect some kind of
terminal weirdness with less itself. With "-F", less will quit if the
whole output can be displayed; it's possible it thinks the screen is
bigger than it is.
GIT_PAGER=less LESS=RSX git log
might help.
-Peff
So I set GIT_PAGER to 'echo custom pager' as you instructed, and I
noticed that wasn't being printed when I ran my git log alias. So what
I did after that was set GIT_TRACE=1 and here is the output I see
before my logs start printing:

$ git lg
trace: exec: 'git-lg'
trace: run_command: 'git-lg'
trace: run_command: 'git lg1'
trace: exec: 'git-lg1'
trace: run_command: 'git-lg1'
trace: run_command: 'git short-log-base --branches --remotes --tags'
trace: exec: 'git-short-log-base' '--branches' '--remotes' '--tags'
trace: run_command: 'git-short-log-base' '--branches' '--remotes' '--tags'
trace: alias expansion: short-log-base => 'log' '--graph'
'--abbrev-commit' '--decorate' '--date=relative'
'--format=format:%C(bold blue)%h%C(reset)%x09%C(bold
green)(%ar)%C(reset)%C(bold yellow)%d%C(reset) %C(dim
white)%an%C(reset) - %C(white)%s%C(reset)'
trace: built-in: git 'log' '--graph' '--abbrev-commit' '--decorate'
'--date=relative' '--format=format:%C(bold blue)%h%C(reset)%x09%C(bold
green)(%ar)%C(reset)%C(bold yellow)%d%C(reset) %C(dim
white)%an%C(reset) - %C(white)%s%C(reset)' '--branches' '--remotes'
'--tags'

Does using an alias have something to do with this?
Jeff King
2014-02-26 09:26:10 UTC
Permalink
Post by Robert Dailey
So I set GIT_PAGER to 'echo custom pager' as you instructed, and I
noticed that wasn't being printed when I ran my git log alias. So what
I did after that was set GIT_TRACE=1 and here is the output I see
[...]
Does using an alias have something to do with this?
The aliases shouldn't matter (and I constructed a scenario like the one
you showed and it starts the pager for me on Linux). It's more like git
is deciding not to show a pager at all (e.g., it thinks your stdout is
not a tty). Does running:

git log

not use a pager, but:

git -p log

does? In that case, I think that your stdout is not a tty for some
reason.

If that is the case, try:

git -p lg

That _should_ turn on the pager, but I think it does not due to a bug
with setup_pager and aliases. Something like the patch below would make
it work (but if you are having to use "-p" manually, there is something
to fix in your cygwin environment, which does not think you are on a
terminal).

-Peff

---
diff --git a/cache.h b/cache.h
index dc040fb..ecc410e 100644
--- a/cache.h
+++ b/cache.h
@@ -1238,6 +1238,7 @@ static inline ssize_t write_str_in_full(int fd, const char *str)

/* pager.c */
extern void setup_pager(void);
+extern void setup_pager_with_options(int stdout_is_tty);
extern const char *pager_program;
extern int pager_in_use(void);
extern int pager_use_color;
diff --git a/git.c b/git.c
index 7cf2953..ad54891 100644
--- a/git.c
+++ b/git.c
@@ -27,7 +27,7 @@ static void commit_pager_choice(void) {
setenv("GIT_PAGER", "cat", 1);
break;
case 1:
- setup_pager();
+ setup_pager_with_options(1);
break;
default:
break;
diff --git a/pager.c b/pager.c
index 0cc75a8..b28125d 100644
--- a/pager.c
+++ b/pager.c
@@ -62,7 +62,12 @@ const char *git_pager(int stdout_is_tty)

void setup_pager(void)
{
- const char *pager = git_pager(isatty(1));
+ setup_pager_with_options(isatty(1));
+}
+
+void setup_pager_with_options(int stdout_is_tty)
+{
+ const char *pager = git_pager(stdout_is_tty);

if (!pager || pager_in_use())
return;
Robert Dailey
2014-02-26 15:54:39 UTC
Permalink
Post by Jeff King
Post by Robert Dailey
So I set GIT_PAGER to 'echo custom pager' as you instructed, and I
noticed that wasn't being printed when I ran my git log alias. So what
I did after that was set GIT_TRACE=1 and here is the output I see
[...]
Does using an alias have something to do with this?
The aliases shouldn't matter (and I constructed a scenario like the one
you showed and it starts the pager for me on Linux). It's more like git
is deciding not to show a pager at all (e.g., it thinks your stdout is
git log
git -p log
does? In that case, I think that your stdout is not a tty for some
reason.
git -p lg
That _should_ turn on the pager, but I think it does not due to a bug
with setup_pager and aliases. Something like the patch below would make
it work (but if you are having to use "-p" manually, there is something
to fix in your cygwin environment, which does not think you are on a
terminal).
-Peff
<snip>
I have tried `git -p log` and `git log` and neither use the pager.
Should I apply the provided patch to the Git for Windows master
branch? Also I'm not sure if there is a convenient way to apply a
patch via email, so should I copy & paste it to a file & then apply
the file?

I'm assuming your patch depended on -p working but not without it, so
I'm not sure if you still think the patch might help. Let me know!
Thanks for your help.
Robert Dailey
2014-02-26 16:41:18 UTC
Permalink
Copying the patch from the email text results in corrupted patch,
something isn't quite right with it so it won't let me apply it.

Can you attach it as an actual file so I can try again? Thanks.
Jeff King
2014-02-27 06:21:07 UTC
Permalink
Post by Robert Dailey
Post by Jeff King
That _should_ turn on the pager, but I think it does not due to a bug
with setup_pager and aliases. Something like the patch below would make
it work (but if you are having to use "-p" manually, there is something
to fix in your cygwin environment, which does not think you are on a
terminal).
I have tried `git -p log` and `git log` and neither use the pager.
I thought Git's behavior was a bug, but it seems to be the intended
effect that "-p" is just "cancel --no-pager" and not "turn on the pager,
even if stdout is not a tty".

So the patch I sent is not something we would want to apply, but it
might help debugging your situation (if my hunch is right that isatty()
is returning false, then "git -p log" would work with it). Or perhaps a
simpler way to check that is just:

diff --git a/pager.c b/pager.c
index 0cc75a8..6d870ac 100644
--- a/pager.c
+++ b/pager.c
@@ -41,8 +41,10 @@ const char *git_pager(int stdout_is_tty)
{
const char *pager;

- if (!stdout_is_tty)
+ if (!stdout_is_tty) {
+ warning("disabling pager, stdout is not a tty");
return NULL;
+ }

pager = getenv("GIT_PAGER");
if (!pager) {
Post by Robert Dailey
Should I apply the provided patch to the Git for Windows master
branch? Also I'm not sure if there is a convenient way to apply a
patch via email, so should I copy & paste it to a file & then apply
the file?
The usual way is to save the patch to an mbox, then use "git am" to
apply it. Most Unix-y mail clients have mbox support, but I suspect many
Windows ones do not.

-Peff
Chris Packham
2014-02-27 07:36:19 UTC
Permalink
Post by Robert Dailey
Post by Jeff King
Post by Robert Dailey
So I set GIT_PAGER to 'echo custom pager' as you instructed, and I
noticed that wasn't being printed when I ran my git log alias. So what
I did after that was set GIT_TRACE=1 and here is the output I see
[...]
Does using an alias have something to do with this?
The aliases shouldn't matter (and I constructed a scenario like the one
you showed and it starts the pager for me on Linux). It's more like git
is deciding not to show a pager at all (e.g., it thinks your stdout is
git log
git -p log
does? In that case, I think that your stdout is not a tty for some
reason.
git -p lg
That _should_ turn on the pager, but I think it does not due to a bug
with setup_pager and aliases. Something like the patch below would make
it work (but if you are having to use "-p" manually, there is something
to fix in your cygwin environment, which does not think you are on a
terminal).
-Peff
<snip>
I have tried `git -p log` and `git log` and neither use the pager.
Should I apply the provided patch to the Git for Windows master
branch?
That may be relevant (refer to my previous questions about what version
you're using and how you got it). Are you using git via cygwin or "Git
For Windows"? I believe the two are different (*caveat* I haven't used
windows in years and I've never used Git For Windows, I've added the
msysgit list to this email thread).

If you're executing the Git For Windows installation from the cygwin
bash shell that's probably why the terminal detection is getting
confused. If you've installed Git For Windows you should use the Git
BASH shell that comes with it. If you want to use git with other bits of
cygwin I suggest uninstalling Git For Windows and installing the git
package via the cygwin setup tool.
Post by Robert Dailey
Also I'm not sure if there is a convenient way to apply a
patch via email, so should I copy & paste it to a file & then apply
the file?
Save the email file in your email client. Most support saving as plain
text or RFC822 format. Then 'git am <filename>' should do the trick.
Post by Robert Dailey
I'm assuming your patch depended on -p working but not without it, so
I'm not sure if you still think the patch might help. Let me know!
Thanks for your help.
Loading...