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

[PATCH v3 1/4] t6301: new tests of for-each-ref error handling

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jun 3, 2015, 13:51 UTC
Message-ID
<48c6ecbe5a963a9ba89e3c25fc6e075a52ebcdbd.1433339279.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1433339279.git.mhagger@alum.mit.edu>

Add tests that for-each-ref correctly reports broken loose reference files and references that point at missing objects. In fact, two of these tests fail, because (1) NULL_SHA1 is not recognized as an invalid reference value, and (2) for-each-ref doesn't respect REF_ISBROKEN. Fixes to come.

Note that when for-each-ref is run with a --format option that doesn't require the object to be looked up, then we should still notice if a loose reference file is corrupt or contains NULL_SHA1, but we don't notice if it points at a missing object because we don't do an object lookup. This is OK.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 t/t6301-for-each-ref-errors.sh | 56 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100755 t/t6301-for-each-ref-errors.sh
diff --git a/t/t6301-for-each-ref-errors.sh b/t/t6301-for-each-ref-errors.sh
new file mode 100755
index 0000000..cf25244
--- /dev/null
+++ b/t/t6301-for-each-ref-errors.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+test_description='for-each-ref errors for broken refs'
+
+. ./test-lib.sh
+
+ZEROS=$_z40
+MISSING=abababababababababababababababababababab
+
+test_expect_success setup '
+	git commit --allow-empty -m "Initial" &&
+	git tag testtag &&
+	git for-each-ref >full-list &&
+	git for-each-ref --format="%(objectname) %(refname)" >brief-list
+'
+
+test_expect_failure 'Broken refs are reported correctly' '
+	r=refs/heads/bogus &&
+	: >.git/$r &&
+	test_when_finished "rm -f .git/$r" &&
+	echo "warning: ignoring broken ref $r" >broken-err &&
+	git for-each-ref >out 2>err &&
+	test_cmp full-list out &&
+	test_cmp broken-err err
+'
+
+test_expect_failure 'NULL_SHA1 refs are reported correctly' '
+	r=refs/heads/zeros &&
+	echo $ZEROS >.git/$r &&
+	test_when_finished "rm -f .git/$r" &&
+	echo "warning: ignoring broken ref $r" >zeros-err &&
+	git for-each-ref >out 2>err &&
+	test_cmp full-list out &&
+	test_cmp zeros-err err &&
+	git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err &&
+	test_cmp brief-list brief-out &&
+	test_cmp zeros-err brief-err
+'
+
+test_expect_success 'Missing objects are reported correctly' '
+	r=refs/heads/missing &&
+	echo $MISSING >.git/$r &&
+	test_when_finished "rm -f .git/$r" &&
+	echo "fatal: missing object $MISSING for $r" >missing-err &&
+	test_must_fail git for-each-ref 2>err &&
+	test_cmp missing-err err &&
+	(
+		cat brief-list &&
+		echo "$MISSING $r"
+	) | sort -k 2 >missing-brief-expected &&
+	git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err &&
+	test_cmp missing-brief-expected brief-out &&
+	test_must_be_empty brief-err
+'
+
+test_done
-- 
2.1.4
Previous: Michael HaggertyNext: Michael Haggerty
Message 2 of 11 in “Fix how for-each-ref handles broken loose references”
  1. 0/4 Fix how for-each-ref handles broken loose referencesMichael Haggerty, Jun 3, 2015
  2. 1/4 t6301: new tests of for-each-ref error handlingMichael Haggerty, Jun 3, 2015
  3. 2/4 for-each-ref: report broken references correctlyMichael Haggerty, Jun 3, 2015
  4. 3/4 read_loose_refs(): simplify function logicMichael Haggerty, Jun 3, 2015
  5. 4/4 read_loose_refs(): treat NULL_SHA1 loose references as brokenMichael Haggerty, Jun 3, 2015
  6. Jeff KingJun 3, 2015
  7. Junio C HamanoJun 3, 2015
  8. Jeff KingJun 3, 2015
  9. Junio C HamanoJun 3, 2015
  10. Michael HaggertyJun 8, 2015
  11. Junio C HamanoJun 8, 2015

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.