git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/9] t/t0450: split whitespace consistency check per subcommand

From
Karthik Nayak <karthik.188@gmail.com>
Date
Oct 10, 2025, 10:27 UTC
Message-ID
<20251010-562-add-option-to-check-if-reference-backend-needs-repacking-v1-5-c7962be584fa@gmail.com>
In-Reply-To
<20251010-562-add-option-to-check-if-reference-backend-needs-repacking-v1-0-c7962be584fa@gmail.com>

The test t0450 contains a test to ensure that leading whitespaces within a commands help text is consistent. This would catch issues such as:

  usage: git show-ref [--head] [-d | --dereference]
                         [-s | --hash[=<n>]] [--abbrev[=<n>]] [--branches] [--tags]
                      [--] [<pattern>...]

where the second line has inconsistent leading whitespaces. However this considers that all lines within a command will be aligned similarly. This works for most commands, however when dealing commands which include subcommands, this assumption doesn't hold. Consider the help text for 'git-refs(1)':

  usage: git refs migrate --ref-format=<format> [--no-reflog] [--dry-run]
     or: git refs verify [--strict] [--verbose]
     or: git refs list [--count=<count>] [--shell|--perl|--python|--tcl]
                                  [(--sort=<key>)...] [--format=<format>]
                                  [--include-root-refs] [--points-at=<object>]
                                  [--merged[=<object>]] [--no-merged[=<object>]]
                                  [--contains[=<object>]] [--no-contains[=<object>]]
                                  [(--exclude=<pattern>)...] [--start-after=<marker>]
                                  [ --stdin | (<pattern>...)]
     or: git refs exists <ref>
     or: git refs optimize [--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]

With the current implementation of this test, any flags added to 'git refs optimize' in a newline would require it to be aligned with the flags of 'git refs list'. Which is incorrect, since we'd want it to be aligned with the flags already added to 'git refs optimize'.

Let's modify the test to work with subcommands. Do this by swapping out the old logic. The old logic simply counts the number of spaces for all lines with leading spaces and checks to make sure they're equal. Instead, now we create a list of (subcommand number, leading space) and then ensure that there are only unique values per subcommand.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 t/t0450-txt-doc-vs-help.sh | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/t/t0450-txt-doc-vs-help.sh b/t/t0450-txt-doc-vs-help.sh
index e12e18f97f..150655f9f0 100755
--- a/t/t0450-txt-doc-vs-help.sh
+++ b/t/t0450-txt-doc-vs-help.sh
@@ -94,19 +94,23 @@ do
 		check_dashed_labels "$(help_to_synopsis "$builtin")"
 	'
 
-	test_expect_success "$builtin -h output has consistent spacing" '
+	test_expect_success "$builtin -h output has consistent spacing for each subcommand" '
 		h2s="$(help_to_synopsis "$builtin")" &&
-		sed -n \
-			-e "/^ / {
-				s/[^ ].*//;
-				p;
-			}" \
-			<"$h2s" >help &&
-		sort -u help >help.ws &&
-		if test -s help.ws
-		then
-			test_line_count = 1 help.ws
-		fi
+
+		# For each subcommand, capture the number of whitespaces
+		# specific to that subcommand.
+		awk "
+		    /^[^ ]/ { subcommand++ } # Count the number of subcommands
+		    /^ / {
+		       match(\$0, /^ */);
+		       print subcommand, RLENGTH;
+		    }
+		" <"$h2s" \
+		| sort -u \
+		| cut -d" " -f1 \
+		| uniq -d > help.inconsistent &&
+
+		test_must_be_empty help.inconsistent
 	'
 
 	adoc="$(builtin_to_adoc "$builtin")" &&
-- 
2.51.0
Previous: Karthik NayakNext: Karthik Nayak
Message 14 of 36 in “refs: add a '--required' flag to 'git refs optimize'”
  1. 0/9 refs: add a '--required' flag to 'git refs optimize'Karthik Nayak, Oct 10, 2025
  2. 1/9 refs: move to using the '.optimize' functionsKarthik Nayak, Oct 10, 2025
  3. Patrick SteinhardtOct 10, 2025
  4. Karthik NayakOct 13, 2025
  5. 2/9 refs: cleanup code around optimizationKarthik Nayak, Oct 10, 2025
  6. Patrick SteinhardtOct 10, 2025
  7. Karthik NayakOct 13, 2025
  8. 3/9 refs: rename 'pack_refs_opts' to 'optimize_refs_opts'Karthik Nayak, Oct 10, 2025
  9. Patrick SteinhardtOct 10, 2025
  10. Karthik NayakOct 13, 2025
  11. 4/9 t/pack-refs-tests: move the 'test_done' to calleesKarthik Nayak, Oct 10, 2025
  12. Patrick SteinhardtOct 10, 2025
  13. Karthik NayakOct 13, 2025
  14. 5/9 t/t0450: split whitespace consistency check per subcommandKarthik Nayak, Oct 10, 2025
  15. 6/9 reftable/stack: return stack segments directlyKarthik Nayak, Oct 10, 2025
  16. Patrick SteinhardtOct 10, 2025
  17. Karthik NayakOct 13, 2025
  18. Patrick SteinhardtOct 13, 2025
  19. 7/9 reftable/stack: add function to check if optimization is requiredKarthik Nayak, Oct 10, 2025
  20. Patrick SteinhardtOct 10, 2025
  21. Karthik NayakOct 13, 2025
  22. 8/9 refs: add a `optimize_required` field to `struct ref_storage_be`Karthik Nayak, Oct 10, 2025
  23. Patrick SteinhardtOct 10, 2025
  24. Karthik NayakOct 13, 2025
  25. 9/9 refs: add a '--required' flag to 'git refs optimize'Karthik Nayak, Oct 10, 2025
  26. Patrick SteinhardtOct 10, 2025
  27. Karthik NayakOct 13, 2025
  28. Junio C HamanoOct 13, 2025
  29. Junio C HamanoOct 13, 2025
  30. Karthik NayakOct 14, 2025
  31. Junio C HamanoOct 14, 2025
  32. Srivastava, NitinOct 15, 2025
  33. Karthik NayakOct 15, 2025
  34. Karthik NayakOct 15, 2025
  35. Patrick SteinhardtOct 15, 2025
  36. Junio C HamanoOct 15, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.