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

[PATCH 9/9] refs: forbid pseudoref updates through ref update API

From
David Turner <dturner@twopensource.com>
Date
Jul 24, 2015, 04:45 UTC
Message-ID
<1437713129-19373-10-git-send-email-dturner@twopensource.com>
In-Reply-To
<1437713129-19373-1-git-send-email-dturner@twopensource.com>

It is now forbidden to update pseudorefs through the ref update framework.

Because of the pseudoref update rules change, test cases that used git update-ref on a pseudoref now operate on plain refs.

Signed-off-by: David Turner <dturner@twopensource.com>
---
 bisect.c              |  2 +-
 refs.c                |  2 ++
 t/t1400-update-ref.sh | 24 ++++++++++++------------
 3 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/bisect.c b/bisect.c
index 3a9fd63..47cc778 100644
--- a/bisect.c
+++ b/bisect.c
@@ -969,7 +969,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
 
 	if (!hashcmp(bisect_rev, current_bad_oid->hash)) {
 		exit_if_skipped_commits(tried, current_bad_oid);
-		printf("%s is the first %s commit\n", bisect_rev_hex,
+		printf("%s is the first %s commit\n", sha1_to_hex(bisect_rev),
 			term_bad);
 		show_diff_tree(prefix, revs.commits->item);
 		/* This means the bisection process succeeded. */
diff --git a/refs.c b/refs.c
index efa84e3..f8dc877 100644
--- a/refs.c
+++ b/refs.c
@@ -3902,6 +3902,8 @@ int ref_transaction_update(struct ref_transaction *transaction,
 	struct ref_update *update;
 
 	assert(err);
+	if (is_pseudoref(refname))
+		return error(_("BUG: Cannot update pseudorefs (all-caps files in .git) through the refs API"));
 
 	if (transaction->state != REF_TRANSACTION_OPEN)
 		die("BUG: update called for transaction that is not open");
diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh
index 0038f28..b05657c 100755
--- a/t/t1400-update-ref.sh
+++ b/t/t1400-update-ref.sh
@@ -608,13 +608,13 @@ test_expect_success 'stdin delete ref fails with zero old value' '
 '
 
 test_expect_success 'stdin update symref works option no-deref' '
-	git symbolic-ref TESTSYMREF $b &&
+	git symbolic-ref refs/TESTSYMREF $b &&
 	cat >stdin <<-EOF &&
 	option no-deref
-	update TESTSYMREF $a $b
+	update refs/TESTSYMREF $a $b
 	EOF
 	git update-ref --stdin <stdin &&
-	git rev-parse TESTSYMREF >expect &&
+	git rev-parse refs/TESTSYMREF >expect &&
 	git rev-parse $a >actual &&
 	test_cmp expect actual &&
 	git rev-parse $m~1 >expect &&
@@ -623,13 +623,13 @@ test_expect_success 'stdin update symref works option no-deref' '
 '
 
 test_expect_success 'stdin delete symref works option no-deref' '
-	git symbolic-ref TESTSYMREF $b &&
+	git symbolic-ref refs/TESTSYMREF $b &&
 	cat >stdin <<-EOF &&
 	option no-deref
-	delete TESTSYMREF $b
+	delete refs/TESTSYMREF $b
 	EOF
 	git update-ref --stdin <stdin &&
-	test_must_fail git rev-parse --verify -q TESTSYMREF &&
+	test_must_fail git rev-parse --verify -q refs/TESTSYMREF &&
 	git rev-parse $m~1 >expect &&
 	git rev-parse $b >actual &&
 	test_cmp expect actual
@@ -983,10 +983,10 @@ test_expect_success 'stdin -z delete ref fails with zero old value' '
 '
 
 test_expect_success 'stdin -z update symref works option no-deref' '
-	git symbolic-ref TESTSYMREF $b &&
-	printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
+	git symbolic-ref refs/TESTSYMREF $b &&
+	printf $F "option no-deref" "update refs/TESTSYMREF" "$a" "$b" >stdin &&
 	git update-ref -z --stdin <stdin &&
-	git rev-parse TESTSYMREF >expect &&
+	git rev-parse refs/TESTSYMREF >expect &&
 	git rev-parse $a >actual &&
 	test_cmp expect actual &&
 	git rev-parse $m~1 >expect &&
@@ -995,10 +995,10 @@ test_expect_success 'stdin -z update symref works option no-deref' '
 '
 
 test_expect_success 'stdin -z delete symref works option no-deref' '
-	git symbolic-ref TESTSYMREF $b &&
-	printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
+	git symbolic-ref refs/TESTSYMREF $b &&
+	printf $F "option no-deref" "delete refs/TESTSYMREF" "$b" >stdin &&
 	git update-ref -z --stdin <stdin &&
-	test_must_fail git rev-parse --verify -q TESTSYMREF &&
+	test_must_fail git rev-parse --verify -q refs/TESTSYMREF &&
 	git rev-parse $m~1 >expect &&
 	git rev-parse $b >actual &&
 	test_cmp expect actual
-- 
2.0.4.315.gad8727a-twtrsrc
Previous: David TurnerNext: Michael Haggerty
Message 19 of 20 in “Pseudorefs”
  1. 0/9 PseudorefsDavid Turner, Jul 24, 2015
  2. 1/9 refs: Introduce pseudoref and per-worktree ref conceptsDavid Turner, Jul 24, 2015
  3. Eric SunshineJul 24, 2015
  4. Junio C HamanoJul 24, 2015
  5. David TurnerJul 24, 2015
  6. Junio C HamanoJul 24, 2015
  7. Philip OakleyJul 24, 2015
  8. David TurnerJul 24, 2015
  9. 2/9 notes: replace pseudorefs with real refsDavid Turner, Jul 24, 2015
  10. 3/9 bisect: do not use update-ref for BISECT_HEADDavid Turner, Jul 24, 2015
  11. 4/9 tests: treat FETCH_HEAD as a pseudorefDavid Turner, Jul 24, 2015
  12. 5/9 tests: use --create-reflog option to git update-refDavid Turner, Jul 24, 2015
  13. 6/9 pseudorefs: create and use pseudoref update and delete functionsDavid Turner, Jul 24, 2015
  14. Junio C HamanoJul 24, 2015
  15. David TurnerJul 24, 2015
  16. Junio C HamanoJul 24, 2015
  17. 7/9 am/rebase: update pseudorefs by writing filesDavid Turner, Jul 24, 2015
  18. 8/9 rebase: use write_pseudorefDavid Turner, Jul 24, 2015
  19. 9/9 refs: forbid pseudoref updates through ref update APIDavid Turner, Jul 24, 2015
  20. Michael HaggertyAug 2, 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.