Re: [PATCH v3] [GSOC] cherry-pick: use better advice message

3 messages, 3 authors, 2021-08-17 · open the first message on its own page

Re: [PATCH v3] [GSOC] cherry-pick: use better advice message

From: Junio C Hamano <hidden>
Date: 2021-08-13 20:14:51

Phillip Wood [off-list ref] writes:
quoted
+++ 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 &&
quoted
  	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.

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
'

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.

Re: [PATCH v3] [GSOC] cherry-pick: use better advice message

From: ZheNing Hu <hidden>
Date: 2021-08-14 02:07:53

Junio C Hamano [off-list ref] 于2021年8月14日周六 上午4:14写道:
Phillip Wood [off-list ref] writes:
quoted
quoted
+++ 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 &&
quoted
     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.
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
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

Re: [PATCH v3] [GSOC] cherry-pick: use better advice message

From: Phillip Wood <hidden>
Date: 2021-08-17 10:09:45

On 13/08/2021 21:14, Junio C Hamano wrote:
Phillip Wood [off-list ref] writes:
quoted
quoted
+++ 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 &&
quoted
   	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.
Good point, you're right I had completely missed that, thanks for 
pointing it out

Phillip
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
'

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.

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help