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

Re: [PATCH v3 2/5] builtin/refs: add "delete" subcommand

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 3, 2026, 12:38 UTC
Message-ID
<aketWqvDbsJ1VyXe@pks.im>
In-Reply-To
<87tsqg2vja.fsf@emacs.iotcl.com>
On Fri, Jul 03, 2026 at 12:54:17PM +0200, Toon Claes wrote:
Show 27 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/builtin/refs.c b/builtin/refs.c
> > index f0faabf45a..edb7d61663 100644
> > --- a/builtin/refs.c
> > +++ b/builtin/refs.c
> > @@ -175,6 +178,52 @@ static int cmd_refs_optimize(int argc, const char **argv, const char *prefix,
> >  	return pack_refs_core(argc, argv, prefix, repo, refs_optimize_usage);
> >  }
> >  
> > +static int cmd_refs_delete(int argc, const char **argv, const char *prefix,
> > +			   struct repository *repo)
> > +{
> > +	static char const * const refs_delete_usage[] = {
> > +		REFS_DELETE_USAGE,
> > +		NULL
> > +	};
> > +	const char *message = NULL;
> > +	unsigned flags = 0;
> > +	struct option opts[] = {
> > +		OPT_STRING(0, "message", &message, N_("reason"),
> > +			   N_("reason of the update")),
> > +		OPT_BIT(0 ,"no-deref", &flags,
> > +			N_("update <refname> not the one it points to"),
> > +			REF_NO_DEREF),
> 
> Would it make sense to allow both --deref and --no-deref? (and --deref
> being the default)

Our "parse-options.h" subsystem is clever enough to make this work already :)

Show 28 quoted lines
> > diff --git a/t/t1464-refs-delete.sh b/t/t1464-refs-delete.sh
> > new file mode 100755
> > index 0000000000..efff7d0574
> > --- /dev/null
> > +++ b/t/t1464-refs-delete.sh
> > @@ -0,0 +1,130 @@
> > +#!/bin/sh
> > +
> > +test_description='git refs delete'
> > +
> > +. ./test-lib.sh
> > +
> > +setup_repo () {
> > +	git init "$1" &&
> > +	test_commit -C "$1" A &&
> > +	test_commit -C "$1" B
> > +}
> > +
> > +test_expect_success 'delete without oldvalue verification' '
> > +	test_when_finished "rm -rf repo" &&
> > +	setup_repo repo &&
> > +	A=$(git -C repo rev-parse A) &&
> > +	git -C repo update-ref refs/heads/foo $A &&
> > +	git -C repo refs delete refs/heads/foo &&
> > +	test_must_fail git -C repo show-ref --verify -q refs/heads/foo
> 
> Why not use `git refs exists` here? And why use `git -C repo` in this
> test, and `cd repo` in the other?
Yeah, there isn't really a good reason.
[snip]
Show 14 quoted lines
> > +test_expect_success 'delete symref with --no-deref leaves target intact' '
> > +	test_when_finished "rm -rf repo" &&
> > +	setup_repo repo &&
> > +	(
> > +		cd repo &&
> > +		A=$(git rev-parse A) &&
> > +		git update-ref refs/heads/foo $A &&
> > +		git symbolic-ref refs/heads/symref refs/heads/foo &&
> > +		git refs delete --no-deref refs/heads/symref &&
> > +		test_must_fail git refs exists refs/heads/symref &&
> > +		git refs exists refs/heads/foo
> > +	)
> 
> What happens if you delete a symref and provide an <old-value>?

That's a good question indeed. It verifies that the symref target resolves to <old-value>. That's the exact same behaviour as `git update-ref -d`, even though it may be a bit on the funny side.

I've fixed up the above test and added another test for this behaviour, but I'm not sure whether it makes sense to send another reroll for this.

Thanks!
Patrick
Previous: Toon ClaesNext: Patrick Steinhardt
Message 29 of 47 in “builtin/refs: add ability to write references”
  1. 0/4 builtin/refs: add ability to write referencesPatrick Steinhardt, Jun 16, 2026
  2. 1/4 builtin/refs: drop `the_repository`Patrick Steinhardt, Jun 16, 2026
  3. 2/4 builtin/refs: add "delete" subcommandPatrick Steinhardt, Jun 16, 2026
  4. 3/4 builtin/refs: add "update" subcommandPatrick Steinhardt, Jun 16, 2026
  5. Junio C HamanoJun 16, 2026
  6. Patrick SteinhardtJun 17, 2026
  7. Junio C HamanoJun 17, 2026
  8. Junio C HamanoJun 16, 2026
  9. Patrick SteinhardtJun 17, 2026
  10. 4/4 builtin/refs: add "rename" subcommandPatrick Steinhardt, Jun 16, 2026
  11. Junio C HamanoJun 16, 2026
  12. Patrick SteinhardtJun 17, 2026
  13. Junio C HamanoJun 17, 2026
  14. 0/5 builtin/refs: add ability to write referencesPatrick Steinhardt, Jun 17, 2026
  15. 1/5 builtin/refs: drop `the_repository`Patrick Steinhardt, Jun 17, 2026
  16. 2/5 builtin/refs: add "delete" subcommandPatrick Steinhardt, Jun 17, 2026
  17. 3/5 builtin/refs: add "update" subcommandPatrick Steinhardt, Jun 17, 2026
  18. 4/5 builtin/refs: add "create" subcommandPatrick Steinhardt, Jun 17, 2026
  19. Junio C HamanoJun 29, 2026
  20. Patrick SteinhardtJun 30, 2026
  21. 5/5 builtin/refs: add "rename" subcommandPatrick Steinhardt, Jun 17, 2026
  22. Junio C HamanoJun 17, 2026
  23. Junio C HamanoJun 29, 2026
  24. Patrick SteinhardtJun 30, 2026
  25. 0/5 builtin/refs: add ability to write referencesPatrick Steinhardt, Jun 30, 2026
  26. 1/5 builtin/refs: drop `the_repository`Patrick Steinhardt, Jun 30, 2026
  27. 2/5 builtin/refs: add "delete" subcommandPatrick Steinhardt, Jun 30, 2026
  28. Toon ClaesJul 3, 2026
  29. Patrick SteinhardtJul 3, 2026
  30. 3/5 builtin/refs: add "update" subcommandPatrick Steinhardt, Jun 30, 2026
  31. 4/5 builtin/refs: add "create" subcommandPatrick Steinhardt, Jun 30, 2026
  32. Toon ClaesJul 3, 2026
  33. Patrick SteinhardtJul 6, 2026
  34. Toon ClaesJul 9, 2026
  35. Toon ClaesJul 9, 2026
  36. 5/5 builtin/refs: add "rename" subcommandPatrick Steinhardt, Jun 30, 2026
  37. Toon ClaesJul 3, 2026
  38. Patrick SteinhardtJul 6, 2026
  39. Junio C HamanoJun 30, 2026
  40. 0/5 builtin/refs: add ability to write referencesPatrick Steinhardt, Jul 6, 2026
  41. 1/5 builtin/refs: drop `the_repository`Patrick Steinhardt, Jul 6, 2026
  42. 2/5 builtin/refs: add "delete" subcommandPatrick Steinhardt, Jul 6, 2026
  43. Toon ClaesJul 9, 2026
  44. 3/5 builtin/refs: add "update" subcommandPatrick Steinhardt, Jul 6, 2026
  45. 4/5 builtin/refs: add "create" subcommandPatrick Steinhardt, Jul 6, 2026
  46. 5/5 builtin/refs: add "rename" subcommandPatrick Steinhardt, Jul 6, 2026
  47. Junio C HamanoJul 6, 2026

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.