From: Rubén Justo Date: Sat, 13 Jul 2024 23:13:13 GMT Subject: Re: [PATCH 4/4] add-patch: render hunks through the pager Message-ID: <2ebcbe5e-a673-40ae-8326-65280dd6b18f@gmail.com> In-Reply-To: <9a2feb36-f8c4-4ea6-91a6-a3a24f359a6e@gmail.com> On Sat, Jul 13, 2024 at 02:17:49PM +0100, phillip.wood123@gmail.com wrote: > On 12/07/2024 17:24, Rubén Justo wrote: > > On Fri, Jul 12, 2024 at 02:26:22PM +0100, Phillip Wood wrote: > > > > > > +test_expect_success TTY 'P does not break if pager ends unexpectly' ' > > > > + test_when_finished "rm -f huge_file; git reset" && > > > > + printf "%2500000s" Y >huge_file && > > > > + git add -N huge_file && > > > > + cat >expect <<-EOF && > > > > + +22 > > > > + +23 > > > > + +24 > > > > + 30 > > > > + 40 > > > > + 50 > > > > + (1/1) Stage this hunk [y,n,q,a,d,s,e,p,?]? > > > > + EOF > > > > + test_write_lines P | > > > > + ( > > > > + GIT_PAGER="head -1" && > > > > + export GIT_PAGER && > > > > + test_terminal git add -p >actual > > > > + ) && > > > > + tail -n 7 actual.trimmed && > > > > + test_cmp expect actual.trimmed > > > > +' > > > > > > What is huge_file doing and what happens to the single line of pager output? > > > [...] > > I'm still confused why we don't > see any output from the pager - shouldn't the pager print the hunk header as > it does in the example below? In the test above, we would need to use "tail -n 18" to capture the header of the hunk. In the test below, the "q" allows "tail -n 3" to capture it. > > test_expect_success TTY 'P does not break if pager ends unexpectedly' ' > > test_when_finished "rm -f huge_file; git reset" && > > printf "%2500000s\nfrotz\n" Y >huge_file && > > git add -N huge_file && > > cat >expect <<-EOF && > > +frotz > > (1/1) Stage addition [y,n,q,a,d,e,p,?]? @@ -0,0 +1,2 @@ > > (1/1) Stage addition [y,n,q,a,d,e,p,?]? > > EOF > > test_write_lines P q | > > ( > > GIT_PAGER="head -1" && > > export GIT_PAGER && > > test_terminal git add -p >actual > > ) && > > tail -n 3 actual.trimmed && > > test_cmp expect actual.trimmed > > ' I wonder if the following would be desirable: --- a/add-patch.c +++ b/add-patch.c @@@ -1519,8 -1519,8 +1519,10 @@@ static int patch_update_file(struct add if (*s->s.reset_color) fputs(s->s.reset_color, stdout); fflush(stdout); -- if (read_single_character(s) == EOF) ++ if (read_single_character(s) == EOF) { ++ quit = 1; break; ++ } if (!s->answer.len) continue;