pager: die when paging to non-existing command
PATCH 1/1 pager: die when paging to non-existing command
When trying to execute a non-existent program from GIT_PAGER, we display an error. However, we also send the complete text to the terminal and return a successful exit code. This can be confusing for the user and the displayed error could easily become obscured by a lengthy text.
For example, here the error message would be very far above after sending 50 MB of text:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c
error: cannot run non-existent: No such file or directory
50314363Let's make the error clear by aborting the process and return an error so that the user can easily correct their mistake.
This will be the result of the change:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c
error: cannot run non-existent: No such file or directory
fatal: unable to start the pager: 'non-existent'
0The behavior change we're introducing in this commit affects two tests in t7006, which is a good sign regarding test coverage and requires us to address it.
The first test is 'git skips paging non-existing command'. This test comes from f7991f01f2 (t7006: clean up SIGPIPE handling in trace2 tests, 2021-11-21,) where a modification was made to a test that was originally introduced in c24b7f6736 (pager: test for exit code with and without SIGPIPE, 2021-02-02). That original test was, IMHO, in the same direction we're going in this commit.
At any rate, this test obviously needs to be adjusted to check the new behavior we are introducing. Do it.
The second test being affected is: 'non-existent pager doesnt cause crash', introduced in f917f57f40 (pager: fix crash when pager program doesn't exist, 2021-11-24). As its name states, it has the intention of checking that we don't introduce a regression that produces a crash when GIT_PAGER points to a nonexistent program.
This test could be considered redundant nowadays, due to us already having several tests checking implicitly what a non-existent command in GIT_PAGER produces. However, let's maintain a good belt-and-suspenders strategy; adapt it to the new world.
Finally, it's worth noting that we are not changing the behavior if the command specified in GIT_PAGER is a shell command. In such cases, it is:
$ GIT_PAGER=:\;non-existent t/test-terminal.perl git log
:;non-existent: 1: non-existent: not found
died of signal 13 at t/test-terminal.perl line 33.--- pager.c | 2 +- t/t7006-pager.sh | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-)
pager.c +1 -1
@@ -137,7 +137,7 @@ void setup_pager(void) pager_process.in =-1 ;strvec_push (&pager_process.env,"GIT_PAGER_IN_USE" );if (start_command (&pager_process)) -return ; +die ("unable to start the pager: '%s'" , pager);/* original process continues, but writes to the pipe */ dup2 (pager_process.in,1 );
t/t7006-pager.sh +3 -12
@@ -725,18 +725,9 @@ test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' ' test_path_is_file pager-used ' -test_expect_success TTY 'git skips paging nonexisting command' ' - test_when_finished "rm trace.normal" && +test_expect_success TTY 'git errors when asked to execute nonexisting pager' ' test_config core.pager "does-not-exist" && - GIT_TRACE2="$(pwd)/trace.normal" && - export GIT_TRACE2 && - test_when_finished "unset GIT_TRACE2" && - - test_terminal git log && - - grep child_exit trace.normal >child-exits && - test_line_count = 1 child-exits && - grep " code:-1 " child-exits + test_must_fail test_terminal git log ' test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
@@ -762,7 +753,7 @@ test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' ' test_expect_success TTY 'non-existent pager doesnt cause crash' ' test_config pager.show invalid-pager && - test_terminal git show + test_must_fail test_terminal git show ' test_done
Signature · 1 line
2.45.2.562.g334133e685
Quoted 7 lines · Rubén Justo
Finally, it's worth noting that we are not changing the behavior if the command specified in
GIT_PAGERis a shell command. In such cases, it is:$ GIT_PAGER=:\;non-existent t/test-terminal.perl git log :;non-existent: 1: non-existent: not found died of signal 13 at t/test-terminal.perl line 33.
IOW, the behaviours between the case where pager is spawned via the shell and bypassing the shell are different , and the case where the shell is involved behaves in a way that is easier to realize the mistake, so change the other case to match. WHich makes sense.
This seems to be an ancient regression introduced in bfdd9ffd (Windows: Make the pager work., 2007-12-08), which did not really affect anybody but MinGW users, but ea27a18c (spawn pager via run_command interface, 2008-07-22) inherited the "if we failed to start the pager, just silently return" from it when non-MinGW code was unified to use the run_command() codepath (the latter is attributed to Peff, which I presume is the reason why you cc'ed him?).
Quoted 11 lines
Signed-off-by Rubén Justo <[email protected]>--- pager.c | 2 +- t/t7006-pager.sh | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-)pager.c +0
-0
pager.c void setup_pager(void) · line 140
Quoted 5 lines
pager.c +1
-1@@ -137,7 +137,7 @@ void setup_pager(void) pager_process.in =-1 ;strvec_push (&pager_process.env,"GIT_PAGER_IN_USE" );if (start_command (&pager_process)) -return ; +die ("unable to start the pager: '%s'" , pager);
If this error string is not used elsewhere, it probably is a good idea to "revert" to the original error message lost by ea27a18c, which was:
die("unable to execute pager '%s'", pager);But I do not think of a reason why we want to avoid dying here.
Just in case there is a reason why we should instead silently return on MinGW, I'll Cc the author of bfdd9ffd, though.
Will queue. Thanks.
Quoted 7 lines · Junio C Hamano
pager.c void setup_pager(void) · line 140
Quoted 1 line
pager.c +1
-0+die ("unable to start the pager: '%s'" , pager);If this error string is not used elsewhere, it probably is a good idea to "revert" to the original error message lost by
ea27a18c, which was:die("unable to execute pager '%s'", pager);
Makes sense. Let me know if you need me to reroll.
Quoted 2 lines
Just in case there is a reason why we should instead silently return on MinGW, I'll Cc the author of
bfdd9ffd, though.
Yup. I did notice the MINGW conditions in t7006 but, to be honest, I hadn't thought about this. Thank you for considering it and seeking confirmation.
Quoted 10 lines · Rubén Justo
Quoted 7 lines · Junio C Hamano
pager.c void setup_pager(void) · line 140
Quoted 1 line
pager.c +1
-0+die ("unable to start the pager: '%s'" , pager);If this error string is not used elsewhere, it probably is a good idea to "revert" to the original error message lost by
ea27a18c, which was:die("unable to execute pager '%s'", pager);
Quoted 8 lines
Makes sense. Let me know if you need me to reroll.
Quoted 2 lines
Just in case there is a reason why we should instead silently return on MinGW, I'll Cc the author of
bfdd9ffd, though.Yup. I did notice the MINGW conditions in t7006 but, to be honest, I hadn't thought about this. Thank you for considering it and seeking confirmation.
After these questions are answered satisfactory, can you send an updated version to conclude the topic?
Thanks.
Am 20.06.24 um 21:04 schrieb Junio C Hamano:
Quoted 2 lines
Just in case there is a reason why we should instead silently return on MinGW, I'll Cc the author of
bfdd9ffd, though.
I don't think there is a reason. IIRC, originally on Windows, failing to start a pager would still let Git operate normally, just without paged output. I might have regarded this as better than to fail the operation.
-- Hannes
Quoted 7 lines · Johannes Sixt
Am 20.06.24 um 21:04 schrieb Junio C Hamano:
Quoted 2 lines
Just in case there is a reason why we should instead silently return on MinGW, I'll Cc the author of
bfdd9ffd, though.I don't think there is a reason. IIRC, originally on Windows, failing to start a pager would still let Git operate normally, just without paged output. I might have regarded this as better than to fail the operation.
The "better keep going than to fail" is what Rubén finds worse, so both sides are quite understandable.
It is unlikely that real-world users are taking advantage of the fact. If they do not want their invocation of Git command paged, "GIT_PAGER=cat git foo" is just as easy as "GIT_PAGER=no git foo", and if it was done by mistake to configure a non-working pager (e.g., configure core.pager to the program xyzzy and then uninstalling xyzzy without realizing you still have users), fixing it would be a one-time operation either way (you update core.pager or you reinstall xyzzy), so I would say that it is better to make the failure more stand out.
Thanks for a quick response.
Quoted 13 lines · Junio C Hamano
Quoted 7 lines · Johannes Sixt
Am 20.06.24 um 21:04 schrieb Junio C Hamano:
Quoted 2 lines
Just in case there is a reason why we should instead silently return on MinGW, I'll Cc the author of
bfdd9ffd, though.I don't think there is a reason. IIRC, originally on Windows, failing to start a pager would still let Git operate normally, just without paged output. I might have regarded this as better than to fail the operation.
The "better keep going than to fail" is what Rubén finds worse, so both sides are quite understandable.
Quoted 9 lines
It is unlikely that real-world users are taking advantage of the fact. If they do not want their invocation of Git command paged, "GIT_PAGER=cat git foo" is just as easy as "GIT_PAGER=no git foo", and if it was done by mistake to configure a non-working pager (e.g., configure core.pager to the program xyzzy and then uninstalling xyzzy without realizing you still have users), fixing it would be a one-time operation either way (you update core.pager or you reinstall xyzzy), so I would say that it is better to make the failure more stand out.
The compelling thing to me is that just about every other failure mode of the pager will result in a SIGPIPE, so the "be nice with a non-working pager" trick really only applies to the very narrow case of execve() failing.
I did assume that a bogus option like:
# oops, there is no -l option!
GIT_PAGER='less -l' git log
would be a plausible such misconfiguration, but to my surprise "less" prints "hey, there is no -l option" and then pages anyway. How helpful. :)
But something like:
# oops, there is no -X option!
GIT_PAGER='cat -X' git log
yields just:
cat: invalid option -- 'X'
Try 'cat --help' for more information.
with no other output. It's a little confusing if you don't realize that "cat" is the pager. We obviously don't want to complain about SIGPIPE, because it's common for the user to simply exit the pager without reading all of the possible data. It might be nice if we printed some message when the pager exits non-zero, but I'd worry there might be false positives, depending on the behavior of various pagers.
-Peff
Quoted 13 lines · Junio C Hamano
Quoted 7 lines · Johannes Sixt
Am 20.06.24 um 21:04 schrieb Junio C Hamano:
Quoted 2 lines
Just in case there is a reason why we should instead silently return on MinGW, I'll Cc the author of
bfdd9ffd, though.I don't think there is a reason. IIRC, originally on Windows, failing to start a pager would still let Git operate normally, just without paged output. I might have regarded this as better than to fail the operation.
The "better keep going than to fail" is what Rubén finds worse, so both sides are quite understandable.
Quoted 9 lines
It is unlikely that real-world users are taking advantage of the fact. If they do not want their invocation of Git command paged, "GIT_PAGER=cat git foo" is just as easy as "GIT_PAGER=no git foo", and if it was done by mistake to configure a non-working pager (e.g., configure core.pager to the program xyzzy and then uninstalling xyzzy without realizing you still have users), fixing it would be a one-time operation either way (you update core.pager or you reinstall xyzzy), so I would say that it is better to make the failure more stand out.
To me, failing when the configured pager cannot be executed is the way to go. Basically, if an invalid pager is configured, we're actually obliged to produce a failure, simply because we have to follow and apply the configuration strictly. This also applies to (partially) invalid configurations.
Hi Hannes,
Quoted 7 lines · Johannes Sixt
Am 20.06.24 um 21:04 schrieb Junio C Hamano:
Quoted 2 lines
Just in case there is a reason why we should instead silently return on MinGW, I'll Cc the author of
bfdd9ffd, though.I don't think there is a reason. IIRC, originally on Windows, failing to start a pager would still let Git operate normally, just without paged output. I might have regarded this as better than to fail the operation.
I recall regarding this a much better idea back then, too, because it was quite finicky to convince the MinGW variant of Git to play nice with the MSys variant of the pager.
In the meantime, things have become a lot more robust and consider it a net improvement to the change the behavior to _not_ silently continue if the pager failed to start.
Ciao,
Johannes
Quoted 14 lines · Junio C Hamano
pager.c void setup_pager(void) · line 140
Quoted 8 lines · Rubén Justo
pager.c +1
-1@@ -137,7 +137,7 @@ void setup_pager(void) pager_process.in =-1 ;strvec_push (&pager_process.env,"GIT_PAGER_IN_USE" );if (start_command (&pager_process)) -return ; +die ("unable to start the pager: '%s'" , pager);If this error string is not used elsewhere, it probably is a good idea to "revert" to the original error message lost by
ea27a18c, which was:
Quoted 1 line
die("unable to execute pager '%s'", pager);Either way I think we want to mark the message for translation
Best Wishes
Phillip
Quoted 15 lines · Phillip Wood
Quoted 12 lines · Junio C Hamano
pager.c void setup_pager(void) · line 140
Quoted 8 lines · Rubén Justo
pager.c +1
-1@@ -137,7 +137,7 @@ void setup_pager(void) pager_process.in =-1 ;strvec_push (&pager_process.env,"GIT_PAGER_IN_USE" );if (start_command (&pager_process)) -return ; +die ("unable to start the pager: '%s'" , pager);If this error string is not used elsewhere, it probably is a good idea to "revert" to the original error message lost by
ea27a18c, which was:Quoted 1 line
die("unable to execute pager '%s'", pager);
Quoted 1 line
Either way I think we want to mark the message for translation
Given that none of the die() message in this file is marked for localization, I would strongly prefer to see this patch not to do so. Possibly as part of a larger clean-up patch series, but not as "while at it" item for this fix.
Thanks.
Quoted 16 lines · Rubén Justo
When trying to execute a non-existent program from
GIT_PAGER, we display an error. However, we also send the complete text to the terminal and return a successful exit code. This can be confusing for the user and the displayed error could easily become obscured by a lengthy text.For example, here the error message would be very far above after sending 50 MB of text:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c error: cannot run non-existent: No such file or directory 50314363Let's make the error clear by aborting the process and return an error so that the user can easily correct their mistake.
Quoted 6 lines
This will be the result of the change:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c error: cannot run non-existent: No such file or directory fatal: unable to start the pager: 'non-existent' 0
OK. My initial reaction was "eh, who care? execve() failing is only one error mode, and we might see all kinds of failure modes from a missing or broken pager".
But this:
Quoted 7 lines
Finally, it's worth noting that we are not changing the behavior if the command specified in
GIT_PAGERis a shell command. In such cases, it is:$ GIT_PAGER=:\;non-existent t/test-terminal.perl git log :;non-existent: 1: non-existent: not found died of signal 13 at t/test-terminal.perl line 33.
...shows what happens in those other cases, and you are making things more consistent. So that seems reasonable to me.
Quoted 10 lines
The behavior change we're introducing in this commit affects two tests in t7006, which is a good sign regarding test coverage and requires us to address it.
The first test is 'git skips paging non-existing command'. This test comes from
f7991f01f2(t7006: clean up SIGPIPE handling in trace2 tests, 2021-11-21,) where a modification was made to a test that was originally introduced inc24b7f6736(pager: test for exit code with and without SIGPIPE, 2021-02-02). That original test was, IMHO, in the same direction we're going in this commit.
Yeah, the point of f7991f01f2 was just to clean up the tests. The modification was only documenting what Git happened to do for that case now, and not meant as an endorsement of the behavior. ;) So I have no problem changing it.
Quoted 10 lines
The second test being affected is: 'non-existent pager doesnt cause crash', introduced in
f917f57f40(pager: fix crash when pager program doesn't exist, 2021-11-24). As its name states, it has the intention of checking that we don't introduce a regression that produces a crash whenGIT_PAGERpoints to a nonexistent program.This test could be considered redundant nowadays, due to us already having several tests checking implicitly what a non-existent command in
GIT_PAGERproduces. However, let's maintain a good belt-and-suspenders strategy; adapt it to the new world.
OK. I would also be happy to see it go. The crash was about reusing the pager child_process struct, and no we know that cannot happen. Either we run the pager or we immediately bail. I think that the code change in that commit could also be reverted (to always re-init the child process), but it's probably more defensive to keep it.
-Peff
Quoted 67 lines · Jeff King
Quoted 16 lines
When trying to execute a non-existent program from
GIT_PAGER, we display an error. However, we also send the complete text to the terminal and return a successful exit code. This can be confusing for the user and the displayed error could easily become obscured by a lengthy text.For example, here the error message would be very far above after sending 50 MB of text:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c error: cannot run non-existent: No such file or directory 50314363Let's make the error clear by aborting the process and return an error so that the user can easily correct their mistake.
Quoted 6 lines
This will be the result of the change:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c error: cannot run non-existent: No such file or directory fatal: unable to start the pager: 'non-existent' 0OK. My initial reaction was "eh, who care?
execve()failing is only one error mode, and we might see all kinds of failure modes from a missing or broken pager".But this:
Quoted 7 lines
Finally, it's worth noting that we are not changing the behavior if the command specified in
GIT_PAGERis a shell command. In such cases, it is:$ GIT_PAGER=:\;non-existent t/test-terminal.perl git log :;non-existent: 1: non-existent: not found died of signal 13 at t/test-terminal.perl line 33....shows what happens in those other cases, and you are making things more consistent. So that seems reasonable to me.
Quoted 10 lines
The behavior change we're introducing in this commit affects two tests in t7006, which is a good sign regarding test coverage and requires us to address it.
The first test is 'git skips paging non-existing command'. This test comes from
f7991f01f2(t7006: clean up SIGPIPE handling in trace2 tests, 2021-11-21,) where a modification was made to a test that was originally introduced inc24b7f6736(pager: test for exit code with and without SIGPIPE, 2021-02-02). That original test was, IMHO, in the same direction we're going in this commit.Yeah, the point of
f7991f01f2was just to clean up the tests. The modification was only documenting what Git happened to do for that case now, and not meant as an endorsement of the behavior. ;) So I have no problem changing it.Quoted 10 lines
The second test being affected is: 'non-existent pager doesnt cause crash', introduced in
f917f57f40(pager: fix crash when pager program doesn't exist, 2021-11-24). As its name states, it has the intention of checking that we don't introduce a regression that produces a crash whenGIT_PAGERpoints to a nonexistent program.This test could be considered redundant nowadays, due to us already having several tests checking implicitly what a non-existent command in
GIT_PAGERproduces. However, let's maintain a good belt-and-suspenders strategy; adapt it to the new world.
Quoted 5 lines
OK. I would also be happy to see it go. The crash was about reusing the pager
child_processstruct, and no we know that cannot happen. Either we run the pager or we immediately bail. I think that the code change in that commit could also be reverted (to always re-init the child process), but it's probably more defensive to keep it.
Yeah. The name is what took most of my attention, I have to admit. A test named like "check that it doesn't crash" is defensive. ;)
Let's keep it.
Thanks for your review.
PATCH v2 1/1 pager: die when paging to non-existing command
In reply to Rubén JustoWhen trying to execute a non-existent program from GIT_PAGER, we display an error. However, we also send the complete text to the terminal and return a successful exit code. This can be confusing for the user and the displayed error could easily become obscured by a lengthy text.
For example, here the error message would be very far above after sending 50 MB of text:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c
error: cannot run non-existent: No such file or directory
50314363Let's make the error clear by aborting the process and return an error so that the user can easily correct their mistake.
This will be the result of the change:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c
error: cannot run non-existent: No such file or directory
fatal: unable to start the pager: 'non-existent'
0The behavior change we're introducing in this commit affects two tests in t7006, which is a good sign regarding test coverage and requires us to address it.
The first test is 'git skips paging non-existing command'. This test comes from f7991f01f2 (t7006: clean up SIGPIPE handling in trace2 tests, 2021-11-21,) where a modification was made to a test that was originally introduced in c24b7f6736 (pager: test for exit code with and without SIGPIPE, 2021-02-02). That original test was, IMHO, in the same direction we're going in this commit.
At any rate, this test obviously needs to be adjusted to check the new behavior we are introducing. Do it.
The second test being affected is: 'non-existent pager doesnt cause crash', introduced in f917f57f40 (pager: fix crash when pager program doesn't exist, 2021-11-24). As its name states, it has the intention of checking that we don't introduce a regression that produces a crash when GIT_PAGER points to a nonexistent program.
This test could be considered redundant nowadays, due to us already having several tests checking implicitly what a non-existent command in GIT_PAGER produces. However, let's maintain a good belt-and-suspenders strategy; adapt it to the new world.
Finally, it's worth noting that we are not changing the behavior if the command specified in GIT_PAGER is a shell command. In such cases, it is:
$ GIT_PAGER=:\;non-existent t/test-terminal.perl git log
:;non-existent: 1: non-existent: not found
died of signal 13 at t/test-terminal.perl line 33.---
This iteration, v2, is just to "revert" to the original error message lost by ea27a18c.
For those not yet used to it, the range-diff is at the end of the message. ;)
Thanks!
pager.c | 3 ++- t/t7006-pager.sh | 17 +++++------------ 2 files changed, 7 insertions(+), 13 deletions(-)
pager.c +2 -1
@@ -1,6 +1,7 @@#include "git-compat-util.h" #include "config.h" #include "editor.h" +#include "gettext.h" #include "pager.h" #include "run-command.h" #include "sigchain.h"
@@ -137,7 +138,7 @@ void setup_pager(void) pager_process.in =-1 ;strvec_push (&pager_process.env,"GIT_PAGER_IN_USE" );if (start_command (&pager_process)) -return ; +die (_ ("unable to execute pager '%s'" ), pager);/* original process continues, but writes to the pipe */ dup2 (pager_process.in,1 );
t/t7006-pager.sh +5 -12
@@ -725,18 +725,11 @@ test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' ' test_path_is_file pager-used ' -test_expect_success TTY 'git skips paging nonexisting command' ' - test_when_finished "rm trace.normal" && +test_expect_success TTY 'git errors when asked to execute nonexisting pager' ' + test_when_finished "rm -f err" && test_config core.pager "does-not-exist" && - GIT_TRACE2="$(pwd)/trace.normal" && - export GIT_TRACE2 && - test_when_finished "unset GIT_TRACE2" && - - test_terminal git log && - - grep child_exit trace.normal >child-exits && - test_line_count = 1 child-exits && - grep " code:-1 " child-exits + test_must_fail test_terminal git log 2>err && + test_grep "unable to execute pager" err ' test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
@@ -762,7 +755,7 @@ test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' ' test_expect_success TTY 'non-existent pager doesnt cause crash' ' test_config pager.show invalid-pager && - test_terminal git show + test_must_fail test_terminal git show ' test_done
Range-diff against v1:
1: 5c7997810c ! 1: 95a2f36d18 pager: die when paging to non-existing command
@@ Commit message
Signed-off-by: Rubén Justo <[email protected]>
## pager.c ##
+@@
+ #include "git-compat-util.h"
+ #include "config.h"
+ #include "editor.h"
++#include "gettext.h"
+ #include "pager.h"
+ #include "run-command.h"
+ #include "sigchain.h"
@@ pager.c: void setup_pager(void)
pager_process.in = -1;
strvec_push(&pager_process.env, "GIT_PAGER_IN_USE");
if (start_command(&pager_process))
- return;
-+ die("unable to start the pager: '%s'", pager);
++ die(_("unable to execute pager '%s'"), pager);
/* original process continues, but writes to the pipe */
dup2(pager_process.in, 1);
@@ t/t7006-pager.sh: test_expect_success TTY 'git discards pager non-zero exit with
-test_expect_success TTY 'git skips paging nonexisting command' '
- test_when_finished "rm trace.normal" &&
+test_expect_success TTY 'git errors when asked to execute nonexisting pager' '
++ test_when_finished "rm -f err" &&
test_config core.pager "does-not-exist" &&
- GIT_TRACE2="$(pwd)/trace.normal" &&
- export GIT_TRACE2 &&
@@ t/t7006-pager.sh: test_expect_success TTY 'git discards pager non-zero exit with
- grep child_exit trace.normal >child-exits &&
- test_line_count = 1 child-exits &&
- grep " code:-1 " child-exits
-+ test_must_fail test_terminal git log
++ test_must_fail test_terminal git log 2>err &&
++ test_grep "unable to execute pager" err
'
test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' 'Signature · 1 line
2.45.2.562.g737041e583
PATCH v3 1/1 pager: die when paging to non-existing command
When trying to execute a non-existent program from GIT_PAGER, we display an error. However, we also send the complete text to the terminal and return a successful exit code. This can be confusing for the user and the displayed error could easily become obscured by a lengthy text.
For example, here the error message would be very far above after sending 50 MB of text:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c
error: cannot run non-existent: No such file or directory
50314363Let's make the error clear by aborting the process and return an error so that the user can easily correct their mistake.
This will be the result of the change:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c
error: cannot run non-existent: No such file or directory
fatal: unable to start the pager: 'non-existent'
0The behavior change we're introducing in this commit affects two tests in t7006, which is a good sign regarding test coverage and requires us to address it.
The first test is 'git skips paging non-existing command'. This test comes from f7991f01f2 (t7006: clean up SIGPIPE handling in trace2 tests, 2021-11-21,) where a modification was made to a test that was originally introduced in c24b7f6736 (pager: test for exit code with and without SIGPIPE, 2021-02-02). That original test was, IMHO, in the same direction we're going in this commit.
At any rate, this test obviously needs to be adjusted to check the new behavior we are introducing. Do it.
The second test being affected is: 'non-existent pager doesnt cause crash', introduced in f917f57f40 (pager: fix crash when pager program doesn't exist, 2021-11-24). As its name states, it has the intention of checking that we don't introduce a regression that produces a crash when GIT_PAGER points to a nonexistent program.
This test could be considered redundant nowadays, due to us already having several tests checking implicitly what a non-existent command in GIT_PAGER produces. However, let's maintain a good belt-and-suspenders strategy; adapt it to the new world.
Finally, it's worth noting that we are not changing the behavior if the command specified in GIT_PAGER is a shell command. In such cases, it is:
$ GIT_PAGER=:\;non-existent t/test-terminal.perl git log
:;non-existent: 1: non-existent: not found
died of signal 13 at t/test-terminal.perl line 33.---
This is a response to
https://lore.kernel.org/git/[email protected]/
Range-diff against v2:
1: 95a2f36d18 ! 1: 60e852bffb pager: die when paging to non-existing command
@@ Commit message
Signed-off-by: Rubén Justo <[email protected]>
## pager.c ##
-@@
- #include "git-compat-util.h"
- #include "config.h"
- #include "editor.h"
-+#include "gettext.h"
- #include "pager.h"
- #include "run-command.h"
- #include "sigchain.h"
@@ pager.c: void setup_pager(void)
pager_process.in = -1;
strvec_push(&pager_process.env, "GIT_PAGER_IN_USE");
if (start_command(&pager_process))
- return;
-+ die(_("unable to execute pager '%s'"), pager);
++ die("unable to execute pager '%s'", pager);
/* original process continues, but writes to the pipe */
dup2(pager_process.in, 1);pager.c | 2 +- t/t7006-pager.sh | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-)
pager.c +1 -1
@@ -137,7 +137,7 @@ void setup_pager(void) pager_process.in =-1 ;strvec_push (&pager_process.env,"GIT_PAGER_IN_USE" );if (start_command (&pager_process)) -return ; +die ("unable to execute pager '%s'" , pager);/* original process continues, but writes to the pipe */ dup2 (pager_process.in,1 );
t/t7006-pager.sh +5 -12
@@ -725,18 +725,11 @@ test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' ' test_path_is_file pager-used ' -test_expect_success TTY 'git skips paging nonexisting command' ' - test_when_finished "rm trace.normal" && +test_expect_success TTY 'git errors when asked to execute nonexisting pager' ' + test_when_finished "rm -f err" && test_config core.pager "does-not-exist" && - GIT_TRACE2="$(pwd)/trace.normal" && - export GIT_TRACE2 && - test_when_finished "unset GIT_TRACE2" && - - test_terminal git log && - - grep child_exit trace.normal >child-exits && - test_line_count = 1 child-exits && - grep " code:-1 " child-exits + test_must_fail test_terminal git log 2>err && + test_grep "unable to execute pager" err ' test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
@@ -762,7 +755,7 @@ test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' ' test_expect_success TTY 'non-existent pager doesnt cause crash' ' test_config pager.show invalid-pager && - test_terminal git show + test_must_fail test_terminal git show ' test_done
Signature · 1 line
2.45.1
Am 22.06.24 um 01:31 schrieb Rubén Justo:
Quoted 9 lines
Let's make the error clear by aborting the process and return an error so that the user can easily correct their mistake.
This will be the result of the change:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c error: cannot run non-existent: No such file or directory fatal: unable to start the pager: 'non-existent' 0
Not a big deal, but the error message cited here does not match the actual new text:
pager.c void setup_pager(void) · line 140
Quoted 3 lines
pager.c +1
-1if (start_command (&pager_process)) -return ; +die ("unable to execute pager '%s'" , pager);
-- Hannes
PATCH v4 1/1 pager: die when paging to non-existing command
In reply to Rubén JustoWhen trying to execute a non-existent program from GIT_PAGER, we display an error. However, we also send the complete text to the terminal and return a successful exit code. This can be confusing for the user and the displayed error could easily become obscured by a lengthy text.
For example, here the error message would be very far above after sending 50 MB of text:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c
error: cannot run non-existent: No such file or directory
50314363Let's make the error clear by aborting the process and return an error so that the user can easily correct their mistake.
This will be the result of the change:
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c
error: cannot run non-existent: No such file or directory
fatal: unable to execute pager 'non-existent'
0The behavior change we're introducing in this commit affects two tests in t7006, which is a good sign regarding test coverage and requires us to address it.
The first test is 'git skips paging non-existing command'. This test comes from f7991f01f2 (t7006: clean up SIGPIPE handling in trace2 tests, 2021-11-21,) where a modification was made to a test that was originally introduced in c24b7f6736 (pager: test for exit code with and without SIGPIPE, 2021-02-02). That original test was, IMHO, in the same direction we're going in this commit.
At any rate, this test obviously needs to be adjusted to check the new behavior we are introducing. Do it.
The second test being affected is: 'non-existent pager doesnt cause crash', introduced in f917f57f40 (pager: fix crash when pager program doesn't exist, 2021-11-24). As its name states, it has the intention of checking that we don't introduce a regression that produces a crash when GIT_PAGER points to a nonexistent program.
This test could be considered redundant nowadays, due to us already having several tests checking implicitly what a non-existent command in GIT_PAGER produces. However, let's maintain a good belt-and-suspenders strategy; adapt it to the new world.
Finally, it's worth noting that we are not changing the behavior if the command specified in GIT_PAGER is a shell command. In such cases, it is:
$ GIT_PAGER=:\;non-existent t/test-terminal.perl git log
:;non-existent: 1: non-existent: not found
died of signal 13 at t/test-terminal.perl line 33.---
Error pointed out by Hannes in:
https://lore.kernel.org/git/[email protected]
Thanks!
Range-diff against v2:
1: 60e852bffb ! 1: 93d6074a17 pager: die when paging to non-existing command
@@ Commit message
$ GIT_PAGER=non-existent t/test-terminal.perl git log | wc -c
error: cannot run non-existent: No such file or directory
- fatal: unable to start the pager: 'non-existent'
+ fatal: unable to execute pager 'non-existent'
0
The behavior change we're introducing in this commit affects two tests
pager.c | 2 +- t/t7006-pager.sh | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-)
pager.c +1 -1
@@ -137,7 +137,7 @@ void setup_pager(void) pager_process.in =-1 ;strvec_push (&pager_process.env,"GIT_PAGER_IN_USE" );if (start_command (&pager_process)) -return ; +die ("unable to execute pager '%s'" , pager);/* original process continues, but writes to the pipe */ dup2 (pager_process.in,1 );
t/t7006-pager.sh +5 -12
@@ -725,18 +725,11 @@ test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' ' test_path_is_file pager-used ' -test_expect_success TTY 'git skips paging nonexisting command' ' - test_when_finished "rm trace.normal" && +test_expect_success TTY 'git errors when asked to execute nonexisting pager' ' + test_when_finished "rm -f err" && test_config core.pager "does-not-exist" && - GIT_TRACE2="$(pwd)/trace.normal" && - export GIT_TRACE2 && - test_when_finished "unset GIT_TRACE2" && - - test_terminal git log && - - grep child_exit trace.normal >child-exits && - test_line_count = 1 child-exits && - grep " code:-1 " child-exits + test_must_fail test_terminal git log 2>err && + test_grep "unable to execute pager" err ' test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
@@ -762,7 +755,7 @@ test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' ' test_expect_success TTY 'non-existent pager doesnt cause crash' ' test_config pager.show invalid-pager && - test_terminal git show + test_must_fail test_terminal git show ' test_done
Signature · 1 line
2.45.1