From: Rubén Justo Date: Fri, 12 Jul 2024 16:24:32 GMT Subject: Re: [PATCH 4/4] add-patch: render hunks through the pager Message-ID: In-Reply-To: <803b10ed-1cb3-4314-82c9-cf48d5d0bb90@gmail.com> 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? The huge file is to make sure we are receiving a SIGPIPE. We don't really care about the line "head -1" produces, only that we don't break due to the SIGPIPE that occurs. Maybe a test like this would be clearer? 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 ' > > Thanks Thank you.