[Outreachy PATCH v2] t1402: test --no-allow-onelevel option precedence

From
Fien Dora <hidden>
Date
2026-10-27 14:54:59
Reply to
Fien Dora, 2026-10-26
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.

Signed-off-by: Fien Dora <redacted>
---

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(+)
diff --git a/t/t1402-check-ref-format.sh b/t/t1402-check-ref-format.sh
index 9dd64662b2..6036df0210 100755
--- a/t/t1402-check-ref-format.sh
+++ b/t/t1402-check-ref-format.sh
@@ -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
-- 
2.50.1 (Apple Git-155)
Thread (11 messages) 11 messages, 2 authors, last reply 10d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help