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

Re: [PATCH v2 3/4] Make die_if_checked_out() prune missing checkouts of unlocked worktrees.

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 21, 2019, 02:09 UTC
Message-ID
<xmqqimoin92j.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20191018194542.1316981-3-pjones@redhat.com>
Peter Jones <pjones@redhat.com> writes:
[jc: won't repeat comments on the title]
> @@ -360,6 +360,12 @@ void die_if_checked_out(const char *branch, int ignore_current_worktree)
>  	wt = find_shared_symref("HEAD", branch);
>  	if (!wt || (ignore_current_worktree && wt->is_current))
>  		return;

die-if-checked-out is called from callers that expect to be stopped before they do any harm, so it feels dirty to make a side effect like this.

If the user tries to check out a branch that used to be checked out in an already removed worktree, doesn't that indicate that an earlier worktree removal was done incorrectly, which is something worth reporting to the user and give the user a chance to think and choose what corrective action(s) need to be taken?

For that, instead of automatically losing information like this patch does, it may make more sense to fail the checkout and stop at giving diagnosis (e.g. "our record shows that the branch is checked out in that worktree, but you seem to have lost it. if you forgot to prune it, then here is the command you can give to do so.") without actually touching the filesystem.

Thanks.
Show 9 quoted lines
> +
> +	if (prune_worktree_if_missing(wt) >= 0) {
> +		delete_worktrees_dir_if_empty();
> +		return;
> +	}
> +
>  	skip_prefix(branch, "refs/heads/", &branch);
>  	die(_("'%s' is already checked out at '%s'"),
>  	    branch, wt->path);
Previous: Peter JonesNext: Junio C Hamano
Message 10 of 15 in “Make die_if_checked_out() ignore missing worktree checkouts.”
  1. 1/2 Make die_if_checked_out() ignore missing worktree checkouts.Peter Jones, Oct 17, 2019
  2. 2/2 Make "git branch -d" prune missing worktrees automatically.Peter Jones, Oct 17, 2019
  3. Eric SunshineOct 17, 2019
  4. Peter JonesOct 18, 2019
  5. 1/4 libgit: Add a read-only helper to test the worktree lockPeter Jones, Oct 18, 2019
  6. 2/4 libgit: Expose more worktree functionality.Peter Jones, Oct 18, 2019
  7. Junio C HamanoOct 21, 2019
  8. 4/4 Make "git branch -d" prune missing worktrees automatically.Peter Jones, Oct 18, 2019
  9. 3/4 Make die_if_checked_out() prune missing checkouts of unlocked worktrees.Peter Jones, Oct 18, 2019
  10. Junio C HamanoOct 21, 2019
  11. Junio C HamanoOct 21, 2019
  12. Eric SunshineNov 8, 2019
  13. Phillip WoodNov 8, 2019
  14. Eric SunshineNov 9, 2019
  15. SZEDER GáborOct 17, 2019

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.