Skip to contentSkip to conversation

t1402: test --no-allow-onelevel option precedence

PATCH Superseded Fien Dora 2 participants 11 messages Oct 26 – Oct 29

lore
Share & tools
lore

Fien Dora

author
#0 lore raw

PATCH 1/1 t1402: test --no-allow-onelevel option precedence

Git allows later command-line options to override earlier ones. Added tests to verify that --no-allow-onelevel overrides --allow-onelevel and vice versa.

This ensures that the expected behavior is preserved if the argument-parsing code changes in the future.

---
 t/t1402-check-ref-format.sh | 2 ++
 1 file changed, 2 insertions(+)
t/t1402-check-ref-format.sh +2 -0
index 9dd64662b2..6036df0210 100755
@@ -74,6 +74,8 @@ invalid_ref 'heads/foo*/bar*' --refspec-pattern
 ref='foo'
 invalid_ref "$ref"
 valid_ref "$ref" --allow-onelevel
+invalid_ref "$ref" '--allow-onelevel --no-allow-onelevel'
+valid_ref "$ref" '--no-allow-onelevel --allow-onelevel'
 invalid_ref "$ref" --refspec-pattern
 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
 invalid_ref "$ref" --normalize
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw
Quoted 3 lines · Fien Dora

Git allows later command-line options to override earlier ones. Added tests to verify that --no-allow-onelevel overrides --allow-onelevel and vice versa.

There are many other commands that take --[no-]foo options and a later --no-foo overrides an earlier --foo (and vice versa), and most of them do use the parse_options() API. It probably is not worth our brain cycles to add tests to cover all these other commands to cover all these options that can be negated in a way similar to this patch does for the ones based on parse_options().

What makes check-ref-format somewhat special is that it does not use the parse_options() API to handle command line options, and instead uses a handcrafted loop to parse them. Covering the behaviour of the command with tests may therefore make a bit more sense than all the others.

Quoted 2 lines

This ensures that the expected behavior is preserved if the argument-parsing code changes in the future.

So I would say that we need two changes to the log message:

* The rationale should highlight why check-ref-format is special and deserves to have this pretty common "no- prefix negates" behaviour tested (i.e., it is a handcrafted parse loop); and

* We have immediate plan to rewrite the option parsing logic (i.e., not a vague "if we change it in the fiture").

to sell this change better.

Thanks.

Quoted 19 lines
---
 t/t1402-check-ref-format.sh | 2 ++
 1 file changed, 2 insertions(+)
t/t1402-check-ref-format.sh +2 -0
index 9dd64662b2..6036df0210 100755
@@ -74,6 +74,8 @@ invalid_ref 'heads/foo*/bar*' --refspec-pattern
 ref='foo'
 invalid_ref "$ref"
 valid_ref "$ref" --allow-onelevel
+invalid_ref "$ref" '--allow-onelevel --no-allow-onelevel'
+valid_ref "$ref" '--no-allow-onelevel --allow-onelevel'
 invalid_ref "$ref" --refspec-pattern
 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
 invalid_ref "$ref" --normalize
author
#2 lore raw

Thank you for the feedback.

I'll revise the commit message to better explain why check-ref-format needs these tests, with the rationale highlighting its handcrafted option-parsing loop and the planned conversion to parse_options(), then send a v2 patch.

Thank you

Quoted 55 lines · Junio C Hamano
Quoted 3 lines · Fien Dora

Git allows later command-line options to override earlier ones. Added tests to verify that --no-allow-onelevel overrides --allow-onelevel and vice versa.

There are many other commands that take --[no-]foo options and a later --no-foo overrides an earlier --foo (and vice versa), and most of them do use the parse_options() API. It probably is not worth our brain cycles to add tests to cover all these other commands to cover all these options that can be negated in a way similar to this patch does for the ones based on parse_options().

What makes check-ref-format somewhat special is that it does not use the parse_options() API to handle command line options, and instead uses a handcrafted loop to parse them. Covering the behaviour of the command with tests may therefore make a bit more sense than all the others.

Quoted 2 lines

This ensures that the expected behavior is preserved if the argument-parsing code changes in the future.

So I would say that we need two changes to the log message:

* The rationale should highlight why check-ref-format is special and deserves to have this pretty common "no- prefix negates" behaviour tested (i.e., it is a handcrafted parse loop); and

* We have immediate plan to rewrite the option parsing logic (i.e., not a vague "if we change it in the fiture").

to sell this change better.

Thanks.

Quoted 19 lines
---
 t/t1402-check-ref-format.sh | 2 ++
 1 file changed, 2 insertions(+)
t/t1402-check-ref-format.sh +2 -0
index 9dd64662b2..6036df0210 100755
@@ -74,6 +74,8 @@ invalid_ref 'heads/foo*/bar*' --refspec-pattern
 ref='foo'
 invalid_ref "$ref"
 valid_ref "$ref" --allow-onelevel
+invalid_ref "$ref" '--allow-onelevel --no-allow-onelevel'
+valid_ref "$ref" '--no-allow-onelevel --allow-onelevel'
 invalid_ref "$ref" --refspec-pattern
 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
 invalid_ref "$ref" --normalize
#3 lore raw
Quoted 8 lines · Fien Dora

Thank you for the feedback.

I'll revise the commit message to better explain why check-ref-format needs these tests, with the rationale highlighting its handcrafted option-parsing loop and the planned conversion to parse_options(), then send a v2 patch.

Thank you

Please do not top-post. Your response will come _after_ the lines you quote from the message you are responding to.

And trim your quote to the parts necessary for bystanders to understand what is being discussed. Do not quote the entire message.

Thanks.

author
#4 lore raw
Quoted 4 lines

Please do not top-post. Your response will come _after_ the lines you quote from the message you are responding to.
And trim your quote to the parts necessary for bystanders to understand what is being discussed. Do not quote the entire message.

Thank you very much, Junio, for your guidance,

I now understand the convention, I will implement it in my future replies

Thank you

Quoted 19 lines · Junio C Hamano
Quoted 8 lines · Fien Dora

Thank you for the feedback.

I'll revise the commit message to better explain why check-ref-format needs these tests, with the rationale highlighting its handcrafted option-parsing loop and the planned conversion to parse_options(), then send a v2 patch.

Thank you

Please do not top-post. Your response will come _after_ the lines you quote from the message you are responding to.

And trim your quote to the parts necessary for bystanders to understand what is being discussed. Do not quote the entire message.

Thanks.

author
#5 lore raw
In reply to Junio C Hamano
Quoted 7 lines

Fien Dora <[email protected]> writes:

Please do not top-post. Your response will come _after_ the lines you quote from the message you are responding to.

And trim your quote to the parts necessary for bystanders to understand what is being discussed. Do not quote the entire message.

Thank you very much, Junio, for your guidance.

I now understand the convention, I will apply them in my future replies

Thank you

author
#6 lore raw

PATCH v2 1/1 t1402: test --no-allow-onelevel option precedence

In reply to Fien Dora

Unlike most Git commands that use the parse_options() API, check-ref-format relies on a handcrafted loop to parse command-line options. Although the --no- prefix is commonly used to negate options in Git, the precedence of --allow-onelevel and --no-allow-onelevel is not explicitly covered by the existing tests.

Add regression tests for both orders of --allow-onelevel and --no-allow-onelevel to verify that the last option takes precedence. The tests confirm that --no-allow-onelevel overrides a preceding --allow-onelevel, and that --allow-onelevel similarly overrides a preceding --no-allow-onelevel.

Git's planned work to improve argument parsing includes replacing suitable handcrafted parsers with existing APIs. These tests establish check-ref-format's current option precedence behavior so it can be preserved when its parsing logic is updated.

---

Changes since v1:
- Explain why check-ref-format's handcrafted parser needs explicit option-precedence tests.
- Clarify how the tests relate to Git's planned parsing work.
- No changes to the test code.

 t/t1402-check-ref-format.sh | 2 ++
 1 file changed, 2 insertions(+)
t/t1402-check-ref-format.sh +2 -0
index 9dd64662b2..6036df0210 100755
@@ -74,6 +74,8 @@ invalid_ref 'heads/foo*/bar*' --refspec-pattern
 ref='foo'
 invalid_ref "$ref"
 valid_ref "$ref" --allow-onelevel
+invalid_ref "$ref" '--allow-onelevel --no-allow-onelevel'
+valid_ref "$ref" '--no-allow-onelevel --allow-onelevel'
 invalid_ref "$ref" --refspec-pattern
 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
 invalid_ref "$ref" --normalize
Signature · 1 line
2.50.1 (Apple Git-155)
#7 lore raw
Quoted 11 lines · Fien Dora

Unlike most Git commands that use the parse_options() API, check-ref-format relies on a handcrafted loop to parse command-line options. Although the --no- prefix is commonly used to negate options in Git, the precedence of --allow-onelevel and --no-allow-onelevel is not explicitly covered by the existing tests.

Add regression tests for both orders of --allow-onelevel and --no-allow-onelevel to verify that the last option takes precedence. The tests confirm that --no-allow-onelevel overrides a preceding --allow-onelevel, and that --allow-onelevel similarly overrides a preceding --no-allow-onelevel.

Nicely described.

Quoted 2 lines

Git's planned work to improve argument parsing includes replacing suitable handcrafted parsers with existing APIs.

I haven't heard of anybody planning to do such a conversion, but do you mean you are planning to do such a work as a follow-up? If so, write it more like "I plan to do X in a separate series". If not, please do not make up hallucinated facts.

Quoted 19 lines

---

 t/t1402-check-ref-format.sh | 2 ++
 1 file changed, 2 insertions(+)
t/t1402-check-ref-format.sh +2 -0
index 9dd64662b2..6036df0210 100755
@@ -74,6 +74,8 @@ invalid_ref 'heads/foo*/bar*' --refspec-pattern
 ref='foo'
 invalid_ref "$ref"
 valid_ref "$ref" --allow-onelevel
+invalid_ref "$ref" '--allow-onelevel --no-allow-onelevel'
+valid_ref "$ref" '--no-allow-onelevel --allow-onelevel'
 invalid_ref "$ref" --refspec-pattern
 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
 invalid_ref "$ref" --normalize
author
#8 lore raw
Quoted 4 lines

I haven't heard of anybody planning to do such a conversion, but do you mean you are planning to do such a work as a follow-up? If so, write it more like "I plan to do X in a separate series". If not, please do not make up hallucinated facts.

Thank you, Junio.

I apologise for presenting the possible conversion as though it were already planned.

I would be very interested in taking on the conversion of check-ref-format to parse_options() as a follow-up contribution. Although it would be a learning challenge for me, I am willing to study the existing implementation and work through it carefully.

I would be grateful for your guidance on whether this would be a suitable follow-up project and how best to approach it.

In the meantime, I will revise the current commit message to remove the unsupported statement.

Thank you again for your guidance.

author
#9 lore raw

PATCH v3 1/1 t1402: test --no-allow-onelevel option precedence

In reply to Fien Dora

Unlike most Git commands that use the parse_options() API, check-ref-format relies on a handcrafted loop to parse command-line options. Although the --no- prefix is commonly used to negate options in Git, the precedence of --allow-onelevel and --no-allow-onelevel is not explicitly covered by the existing tests.

Add regression tests for both orders of --allow-onelevel and --no-allow-onelevel to verify that the last option takes precedence. The tests confirm that --no-allow-onelevel overrides a preceding --allow-onelevel, and that --allow-onelevel similarly overrides a preceding --no-allow-onelevel.

To improve Git's command-line argument parsing, I plan to explore converting check-ref-format's handcrafted parser to parse_options() API in a separate patch series. These tests establish the current option-precedence behavior that the conversion would need to preserve.

---

Changes since v2:
- Clarify that converting check-ref-format to parse_options() is work I plan to explore in a separate patch series, not an existing Git development plan.
- No changes to the tests.

 t/t1402-check-ref-format.sh | 2 ++
 1 file changed, 2 insertions(+)
t/t1402-check-ref-format.sh +2 -0
index 9dd64662b2..6036df0210 100755
@@ -74,6 +74,8 @@ invalid_ref 'heads/foo*/bar*' --refspec-pattern
 ref='foo'
 invalid_ref "$ref"
 valid_ref "$ref" --allow-onelevel
+invalid_ref "$ref" '--allow-onelevel --no-allow-onelevel'
+valid_ref "$ref" '--no-allow-onelevel --allow-onelevel'
 invalid_ref "$ref" --refspec-pattern
 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
 invalid_ref "$ref" --normalize
Signature · 1 line
2.50.1 (Apple Git-155)
#10 lore raw
Quoted 12 lines · Fien Dora

Unlike most Git commands that use the parse_options() API, check-ref-format relies on a handcrafted loop to parse command-line options. Although the --no- prefix is commonly used to negate options in Git, the precedence of --allow-onelevel and --no-allow-onelevel is not explicitly covered by the existing tests.

Add regression tests for both orders of --allow-onelevel and --no-allow-onelevel to verify that the last option takes precedence. The tests confirm that --no-allow-onelevel overrides a preceding --allow-onelevel, and that --allow-onelevel similarly overrides a preceding --no-allow-onelevel.

Quoted 8 lines

To improve Git's command-line argument parsing, I plan to explore converting check-ref-format's handcrafted parser to parse_options() API in a separate patch series. These tests establish the current option-precedence behavior that the conversion would need to preserve.

---

Well explained.

t/t1402-check-ref-format.sh invalid_ref 'heads/foo*/bar*' --refspec-pattern · line 81

Quoted 13 lines
t/t1402-check-ref-format.sh +2 -0
index 9dd64662b2..6036df0210 100755
@@ -74,6 +74,8 @@ invalid_ref 'heads/foo*/bar*' --refspec-pattern
 ref='foo'
 invalid_ref "$ref"
 valid_ref "$ref" --allow-onelevel
+invalid_ref "$ref" '--allow-onelevel --no-allow-onelevel'
+valid_ref "$ref" '--no-allow-onelevel --allow-onelevel'
 invalid_ref "$ref" --refspec-pattern
 valid_ref "$ref" '--refspec-pattern --allow-onelevel'
 invalid_ref "$ref" --normalize

Will queue. Thanks.