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

[PATCH v2 06/21] reflog tests: add --updateref tests

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Oct 16, 2021, 09:39 UTC
Message-ID
<patch-v2-06.21-d3242f5f687-20211016T093845Z-avarab@gmail.com>
In-Reply-To
<cover-v2-00.21-00000000000-20211016T093845Z-avarab@gmail.com>

Add tests that cover blindspots in "git reflog delete --updateref" behavior. Before this change removing the "type & REF_ISSYMREF" check added in 5e6f003ca8a (reflog_expire(): ignore --updateref for symbolic references, 2015-03-03) would not fail any tests.

The "--updateref" option was added in 55f10565371 (git-reflog: add option --updateref to write the last reflog sha1 into the ref, 2008-02-22) for use in git-stash.sh, see e25d5f9c82e (git-stash: add new 'drop' subcommand, 2008-02-22).

Even though the regression test I need is just the "C" case here, let's test all these combinations for good measure. I started out doing these as a for-loop, but I think this is more readable.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1417-reflog-updateref.sh | 65 +++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100755 t/t1417-reflog-updateref.sh
diff --git a/t/t1417-reflog-updateref.sh b/t/t1417-reflog-updateref.sh
new file mode 100755
index 00000000000..14f13b57c6d
--- /dev/null
+++ b/t/t1417-reflog-updateref.sh
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+test_description='git reflog --updateref'
+
+TEST_PASSES_SANITIZE_LEAK=true
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+	git init -b main repo &&
+	(
+		cd repo &&
+
+		test_commit A &&
+		test_commit B &&
+		test_commit C &&
+
+		cp .git/logs/HEAD HEAD.old &&
+		git reset --hard HEAD~ &&
+		cp HEAD.old .git/logs/HEAD
+	)
+'
+
+test_reflog_updateref () {
+	exp=$1
+	shift
+	args="$@"
+
+	test_expect_success REFFILES "get '$exp' with '$args'"  '
+		test_when_finished "rm -rf copy" &&
+		cp -R repo copy &&
+
+		(
+			cd copy &&
+
+			$args &&
+			git rev-parse $exp >expect &&
+			git rev-parse HEAD >actual &&
+
+			test_cmp expect actual
+		)
+	'
+}
+
+test_reflog_updateref B git reflog delete --updateref HEAD@{0}
+test_reflog_updateref B git reflog delete --updateref HEAD@{1}
+test_reflog_updateref C git reflog delete --updateref main@{0}
+test_reflog_updateref B git reflog delete --updateref main@{1}
+test_reflog_updateref B git reflog delete --updateref --rewrite HEAD@{0}
+test_reflog_updateref B git reflog delete --updateref --rewrite HEAD@{1}
+test_reflog_updateref C git reflog delete --updateref --rewrite main@{0}
+test_reflog_updateref B git reflog delete --updateref --rewrite main@{1}
+test_reflog_updateref B test_must_fail git reflog expire  HEAD@{0}
+test_reflog_updateref B test_must_fail git reflog expire  HEAD@{1}
+test_reflog_updateref B test_must_fail git reflog expire  main@{0}
+test_reflog_updateref B test_must_fail git reflog expire  main@{1}
+test_reflog_updateref B test_must_fail git reflog expire --updateref HEAD@{0}
+test_reflog_updateref B test_must_fail git reflog expire --updateref HEAD@{1}
+test_reflog_updateref B test_must_fail git reflog expire --updateref main@{0}
+test_reflog_updateref B test_must_fail git reflog expire --updateref main@{1}
+test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite HEAD@{0}
+test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite HEAD@{1}
+test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite main@{0}
+test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite main@{1}
+
+test_done
-- 
2.33.1.1338.g20da966911a
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 26 of 45 in “refs: stop having the API set "errno"”
  1. 00/20 refs: stop having the API set "errno"Ævar Arnfjörð Bjarmason, Oct 14, 2021
  2. 01/20 branch tests: test for errno propagating on failing readÆvar Arnfjörð Bjarmason, Oct 14, 2021
  3. Eric SunshineOct 14, 2021
  4. 02/20 refs API: add a version of refs_resolve_ref_unsafe() with "errno"Ævar Arnfjörð Bjarmason, Oct 14, 2021
  5. 03/20 refs API: make refs_read_raw_ref() not set errnoÆvar Arnfjörð Bjarmason, Oct 14, 2021
  6. 04/20 refs API: make parse_loose_ref_contents() not set errnoÆvar Arnfjörð Bjarmason, Oct 14, 2021
  7. 05/20 refs API: make refs_rename_ref_available() staticÆvar Arnfjörð Bjarmason, Oct 14, 2021
  8. 06/20 refs/files: remove "name exist?" check in lock_ref_oid_basic()Ævar Arnfjörð Bjarmason, Oct 14, 2021
  9. Junio C HamanoOct 14, 2021
  10. 07/20 refs API: remove refs_read_ref_full() wrapperÆvar Arnfjörð Bjarmason, Oct 14, 2021
  11. 08/20 refs API: make resolve_gitlink_ref() not set errnoÆvar Arnfjörð Bjarmason, Oct 14, 2021
  12. 09/20 refs API: make loose_fill_ref_dir() not set errnoÆvar Arnfjörð Bjarmason, Oct 14, 2021
  13. 10/20 refs API: make files_copy_or_rename_ref() et al not set errnoÆvar Arnfjörð Bjarmason, Oct 14, 2021
  14. 11/20 refs API: ignore errno in worktree.c's add_head_info()Ævar Arnfjörð Bjarmason, Oct 14, 2021
  15. 12/20 refs API: ignore errno in worktree.c's find_shared_symref()Ævar Arnfjörð Bjarmason, Oct 14, 2021
  16. 14/20 refs API: make refs_resolve_refdup() not set errnoÆvar Arnfjörð Bjarmason, Oct 14, 2021
  17. 13/20 refs tests: ignore ignore errno in test-ref-store helperÆvar Arnfjörð Bjarmason, Oct 14, 2021
  18. 15/20 refs API: make refs_ref_exists() not set errnoÆvar Arnfjörð Bjarmason, Oct 14, 2021
  19. 16/20 refs API: make resolve_ref_unsafe() not set errnoÆvar Arnfjörð Bjarmason, Oct 14, 2021
  20. 17/20 refs API: make expand_ref() & repo_dwim_log() not set errnoÆvar Arnfjörð Bjarmason, Oct 14, 2021
  21. 18/20 refs API: don't expose "errno" in run_transaction_hook()Ævar Arnfjörð Bjarmason, Oct 14, 2021
  22. 20/20 refs API: post-migration API renaming [2/2]Ævar Arnfjörð Bjarmason, Oct 14, 2021
  23. 19/20 refs API: post-migration API renaming [1/2]Ævar Arnfjörð Bjarmason, Oct 14, 2021
  24. 00/21 refs: stop having the API set "errno"Ævar Arnfjörð Bjarmason, Oct 16, 2021
  25. 04/21 refs API: make parse_loose_ref_contents() not set errnoÆvar Arnfjörð Bjarmason, Oct 16, 2021
  26. 06/21 reflog tests: add --updateref testsÆvar Arnfjörð Bjarmason, Oct 16, 2021
  27. 03/21 refs API: make refs_read_raw_ref() not set errnoÆvar Arnfjörð Bjarmason, Oct 16, 2021
  28. 01/21 branch tests: test for errno propagating on failing readÆvar Arnfjörð Bjarmason, Oct 16, 2021
  29. 08/21 refs API: remove refs_read_ref_full() wrapperÆvar Arnfjörð Bjarmason, Oct 16, 2021
  30. 02/21 refs API: add a version of refs_resolve_ref_unsafe() with "errno"Ævar Arnfjörð Bjarmason, Oct 16, 2021
  31. 05/21 refs API: make refs_rename_ref_available() staticÆvar Arnfjörð Bjarmason, Oct 16, 2021
  32. 07/21 refs/files: remove "name exist?" check in lock_ref_oid_basic()Ævar Arnfjörð Bjarmason, Oct 16, 2021
  33. 09/21 refs API: make resolve_gitlink_ref() not set errnoÆvar Arnfjörð Bjarmason, Oct 16, 2021
  34. 10/21 refs API: make loose_fill_ref_dir() not set errnoÆvar Arnfjörð Bjarmason, Oct 16, 2021
  35. 12/21 refs API: ignore errno in worktree.c's add_head_info()Ævar Arnfjörð Bjarmason, Oct 16, 2021
  36. 11/21 refs API: make files_copy_or_rename_ref() et al not set errnoÆvar Arnfjörð Bjarmason, Oct 16, 2021
  37. 14/21 refs tests: ignore ignore errno in test-ref-store helperÆvar Arnfjörð Bjarmason, Oct 16, 2021
  38. 17/21 refs API: make resolve_ref_unsafe() not set errnoÆvar Arnfjörð Bjarmason, Oct 16, 2021
  39. 13/21 refs API: ignore errno in worktree.c's find_shared_symref()Ævar Arnfjörð Bjarmason, Oct 16, 2021
  40. 16/21 refs API: make refs_ref_exists() not set errnoÆvar Arnfjörð Bjarmason, Oct 16, 2021
  41. 15/21 refs API: make refs_resolve_refdup() not set errnoÆvar Arnfjörð Bjarmason, Oct 16, 2021
  42. 20/21 refs API: post-migration API renaming [1/2]Ævar Arnfjörð Bjarmason, Oct 16, 2021
  43. 18/21 refs API: make expand_ref() & repo_dwim_log() not set errnoÆvar Arnfjörð Bjarmason, Oct 16, 2021
  44. 19/21 refs API: don't expose "errno" in run_transaction_hook()Ævar Arnfjörð Bjarmason, Oct 16, 2021
  45. 21/21 refs API: post-migration API renaming [2/2]Ævar Arnfjörð Bjarmason, Oct 16, 2021

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.