Re: [PATCH v3] [GSOC] cherry-pick: use better advice message
- From
ZheNing Hu <adlternative@gmail.com>
- Date
- Aug 14, 2021, 02:07 UTC
- Message-ID
- <CAOLTT8Qrz_t60i6U0YvrgXKGkqVEx13ts5T1J1qKht3iMzC2bg@mail.gmail.com>
- In-Reply-To
- <xmqqzgtlumob.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> 于2021年8月14日周六 上午4:14写道:
Show 32 quoted lines
> > Phillip Wood <phillip.wood123@gmail.com> writes: > > >> +++ b/t/t3507-cherry-pick-conflict.sh > >> @@ -53,9 +53,12 @@ test_expect_success 'advice from failed cherry-pick' " > >> picked=\$(git rev-parse --short picked) && > >> cat <<-EOF >expected && > > > > If you quote the here doc end marker then there is no substitution in > > the here doc so writing > > > > cat <<-\EOF >expected && > > > >> error: could not apply \$picked... picked > >> - hint: after resolving the conflicts, mark the corrected paths > >> - hint: with 'git add <paths>' or 'git rm <paths>' > >> - hint: and commit the result with 'git commit' > >> + hint: Resolve all conflicts manually, mark them as resolved with > >> + hint: \"git add/rm <conflicted_files>\", then run > > > > means you can replace \" with " here > > Hmph, actually the double-quote that opens the body of > test_expect_success should be stared at with a very cautious eyes, > as they often do not mean what the author of the patch thought they > do. I can see that it already fooled your eyes into thinking that > there is no substitution, but $picked needs to be substituted into > its value. The backslash before it is *not* about guarding it from > substitution inside here-doc; it is to pass literal "$" into the > string, which is the last parameter to test_expect_success, that > gets eval'ed. >
Yes, the escaping here comes from double-quote of test_expect_success instead of here-doc.
Show 19 quoted lines
> The original of this one, for example, would probably have been
> better if written like so:
>
> test_expect_success 'advice from failed cherry-pick' '
> pristine_detach initial &&
> SQ='\'' &&
>
> picked=$(git rev-parse --short picked) &&
> cat <<-EOF >expected &&
> error: could not apply $picked... picked
> hint: after resolving the conflicts, mark the corrected paths
> hint: with ${SQ}git add <paths>${SQ} or ${SQ}git rm <paths>${SQ}
> hint: and commit the result with ${SQ}git commit${SQ}
> EOF
> test_must_fail git cherry-pick picked 2>actual &&
>
> test_cmp expected actual
> '
>Um? This section is not working for me.
./test-lib.sh: eval: line 917: unexpected EOF while looking for matching `'' ./test-lib.sh: eval: line 932: syntax error: unexpected end of file
Show 19 quoted lines
> And because there is no single quote in the updated text, it would > become: > > test_expect_success 'advice from failed cherry-pick' ' > pristine_detach initial && > > picked=$(git rev-parse --short picked) && > cat <<-EOF >expected && > error: could not apply $picked... picked > hint: Resolve all conflicts manually, mark them as resolved with > hint: "git add/rm <conflicted_files>", then run > EOF > test_must_fail git cherry-pick picked 2>actual && > > test_cmp expected actual > ' > > which makes it far easier to see that $picked needs to be > substituted, and the "git add/rm" are to be enclosed in dq pair.
This section is exactly what I want. Using single quotes does make it look a lot easier.
-- ZheNing Hu