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

Re: [PATCH v3 2/2] reflog: implement subcommand to drop reflogs

From
Karthik Nayak <karthik.188@gmail.com>
Date
Mar 19, 2025, 09:16 UTC
Message-ID
<CAOLa=ZQ-ndKuYMABLveNjLnbR181+RD9_NGHAJsZbdc9eV2nEw@mail.gmail.com>
In-Reply-To
<8734fagwn2.fsf@iotcl.com>
Toon Claes <toon@iotcl.com> writes:
> Karthik Nayak <karthik.188@gmail.com> writes:
>
[snip]
Show 28 quoted lines
>> +static int cmd_reflog_drop(int argc, const char **argv, const char *prefix,
>> +			   struct repository *repo)
>> +{
>> +	int ret = 0, do_all = 0, single_worktree = 0;
>> +	const struct option options[] = {
>> +		OPT_BOOL(0, "all", &do_all, N_("drop the reflogs of all references")),
>> +		OPT_BOOL(0, "single-worktree", &single_worktree,
>> +			 N_("drop reflogs from the current worktree only")),
>> +		OPT_END()
>> +	};
>> +
>> +	argc = parse_options(argc, argv, prefix, options, reflog_drop_usage, 0);
>> +
>> +	if (argc && do_all)
>> +		usage(_("references specified along with --all"));
>
> What is the intended behavior when both `--all` and `<refs>` are
> omitted? It seems nothing happens at the moment. And no error nor
> warning is printed, that feels a bit odd to me.
>
> Now, when you do `git reflog expire --expire=all` it also seems to be
> doing nothing at all. I also think this is weird. And I don't see any
> test coverage for `git reflog expire` without `--all`.
>
> But what is the expected behavior when you omit `--all` and `<refs>`?
> Should it give an error or warning? Should it use HEAD, just like `git
> reflog show` does?
>

As discussed in the other thread [1], ideally this should be raised as an error. I'm leaving it for now.

[snip]
Show 16 quoted lines
>> +
>> +test_expect_success 'reflog drop --all' '
>> +	test_when_finished "rm -rf repo" &&
>> +	git init repo &&
>> +	(
>> +		cd repo &&
>> +		test_commit A &&
>> +		test_commit_bulk --ref=refs/heads/branch 1 &&
>> +		git reflog exists refs/heads/main &&
>> +		git reflog exists refs/heads/branch &&
>> +		git reflog drop --all &&
>> +		test_must_fail git reflog exists refs/heads/main &&
>> +		test_must_fail git reflog exists refs/heads/branch
>
> Should we test output of `git reflog list`?
>

I don't see why, we're concerned with individual reflogs and 'exists' help check against those individual reflogs.

Show 20 quoted lines
>> +	)
>> +'
>> +
>> +test_expect_success 'reflog drop --all multiple worktrees' '
>> +	test_when_finished "rm -rf repo" &&
>> +	test_when_finished "rm -rf wt" &&
>> +	git init repo &&
>> +	(
>> +		cd repo &&
>> +		test_commit A &&
>> +		git worktree add ../wt &&
>> +		test_commit_bulk -C ../wt --ref=refs/heads/branch 1 &&
>> +		git reflog exists refs/heads/main &&
>> +		git reflog exists refs/heads/branch &&
>> +		git reflog drop --all &&
>> +		test_must_fail git reflog exists refs/heads/main &&
>> +		test_must_fail git reflog exists refs/heads/branch
>
> Shall we test HEAD in both worktrees does not exists?
>

I think it would be a good addition, but I'm not sure if its worthy of a re-roll.

Show 24 quoted lines
>> +	)
>> +'
>> +
>> +test_expect_success 'reflog drop --all --single-worktree' '
>> +	test_when_finished "rm -rf repo" &&
>> +	test_when_finished "rm -rf wt" &&
>> +	git init repo &&
>> +	(
>> +		cd repo &&
>> +		test_commit A &&
>> +		git worktree add ../wt &&
>> +		test_commit -C ../wt foobar &&
>> +		git reflog exists refs/heads/main &&
>> +		git reflog exists refs/heads/wt &&
>> +		test-tool ref-store worktree:wt reflog-exists HEAD &&
>> +		git reflog drop --all --single-worktree &&
>> +		test_must_fail git reflog exists refs/heads/main &&
>> +		test_must_fail git reflog exists refs/heads/wt &&
>> +		test_must_fail test-tool ref-store worktree:main reflog-exists HEAD &&
>> +		test-tool ref-store worktree:wt reflog-exists HEAD
>
> Naive question: why is `test-tool ref-store` used and not
> `git -C ../wt reflog exist`?
>
That should work too :)
Show 18 quoted lines
>> +	)
>> +'
>> +
>> +test_expect_success 'reflog drop --all with reference' '
>> +	test_when_finished "rm -rf repo" &&
>> +	git init repo &&
>> +	(
>> +		cd repo &&
>> +		test_commit A &&
>> +		test_must_fail git reflog drop --all refs/heads/main 2>stderr &&
>> +		test_grep "usage: references specified along with --all" stderr
>> +	)
>> +'
>> +
>>  test_done
>>
>> --
>> 2.48.1
[1]: CAOLa=ZSj11TSTs6CywSX1Q9AAfW28zssS2yrGf8PmBOgd06Etg@mail.gmail.com
Previous: Toon Claes
Message 30 of 30 in “EDITME: cover title for 493-add-command-to-purge-reflog-entries”
  1. 0/2 EDITME: cover title for 493-add-command-to-purge-reflog-entriesKarthik Nayak, Mar 7, 2025
  2. 1/2 reflog: drop usage of global variablesKarthik Nayak, Mar 7, 2025
  3. Junio C HamanoMar 7, 2025
  4. Karthik NayakMar 10, 2025
  5. Junio C HamanoMar 10, 2025
  6. Karthik NayakMar 13, 2025
  7. 2/2 reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 7, 2025
  8. Patrick SteinhardtMar 7, 2025
  9. Karthik NayakMar 7, 2025
  10. Patrick SteinhardtMar 7, 2025
  11. Karthik NayakMar 7, 2025
  12. Karthik NayakMar 7, 2025
  13. Junio C HamanoMar 7, 2025
  14. Karthik NayakMar 10, 2025
  15. Kristoffer HaugsbakkMar 10, 2025
  16. Karthik NayakMar 10, 2025
  17. Junio C HamanoMar 10, 2025
  18. reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 10, 2025
  19. Patrick SteinhardtMar 12, 2025
  20. Karthik NayakMar 13, 2025
  21. Patrick SteinhardtMar 13, 2025
  22. 0/2 reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 14, 2025
  23. 1/2 reflog: improve error for when reflog is not foundKarthik Nayak, Mar 14, 2025
  24. 2/2 reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 14, 2025
  25. Christian CouderMar 18, 2025
  26. Junio C HamanoMar 18, 2025
  27. Christian CouderMar 19, 2025
  28. Karthik NayakMar 19, 2025
  29. Toon ClaesMar 18, 2025
  30. Karthik NayakMar 19, 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.