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

Re: [PATCH 1/5] worktree: add skeleton "repair" command

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 27, 2020, 16:08 UTC
Message-ID
<xmqqr1rsqdga.fsf@gitster.c.googlers.com>
In-Reply-To
<20200827082129.56149-2-sunshine@sunshineco.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 13 quoted lines
> Worktree administrative files can become corrupted or outdated due to
> external factors. Although, it is often possible to recover from such
> situations by hand-tweaking these files, doing so requires intimate
> knowledge of worktree internals. While information necessary to make
> such repairs manually can be obtained from git-worktree.txt and
> gitrepository-layout.txt, we can assist users more directly by teaching
> git-worktree how to repair its administrative files itself (at least to
> some extent). Therefore, add a "git worktree repair" command which
> attempts to correct common problems which may arise due to factors
> beyond Git's control.
>
> At this stage, the "repair" command is a mere skeleton; subsequent
> commits will flesh out the functionality.

Sounds good. It looked a bit odd to have skeleton test script only to reserve its test number, but it is just odd and not wrong.

Let's read on.
Show 81 quoted lines
> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
> ---
>  Documentation/git-worktree.txt |  6 ++++++
>  builtin/worktree.c             | 15 +++++++++++++++
>  t/t2406-worktree-repair.sh     | 11 +++++++++++
>  3 files changed, 32 insertions(+)
>  create mode 100755 t/t2406-worktree-repair.sh
>
> diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
> index 6ee6ec7982..ae432d39a8 100644
> --- a/Documentation/git-worktree.txt
> +++ b/Documentation/git-worktree.txt
> @@ -15,6 +15,7 @@ SYNOPSIS
>  'git worktree move' <worktree> <new-path>
>  'git worktree prune' [-n] [-v] [--expire <expire>]
>  'git worktree remove' [-f] <worktree>
> +'git worktree repair'
>  'git worktree unlock' <worktree>
>  
>  DESCRIPTION
> @@ -110,6 +111,11 @@ and no modification in tracked files) can be removed. Unclean working
>  trees or ones with submodules can be removed with `--force`. The main
>  working tree cannot be removed.
>  
> +repair::
> +
> +Repair working tree administrative files, if possible, if they have
> +become corrupted or outdated due to external factors.
> +
>  unlock::
>  
>  Unlock a working tree, allowing it to be pruned, moved or deleted.
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> index 378f332b5d..88af412d4f 100644
> --- a/builtin/worktree.c
> +++ b/builtin/worktree.c
> @@ -1030,6 +1030,19 @@ static int remove_worktree(int ac, const char **av, const char *prefix)
>  	return ret;
>  }
>  
> +static int repair(int ac, const char **av, const char *prefix)
> +{
> +	struct option options[] = {
> +		OPT_END()
> +	};
> +	int rc = 0;
> +
> +	ac = parse_options(ac, av, prefix, options, worktree_usage, 0);
> +	if (ac)
> +		usage_with_options(worktree_usage, options);
> +	return rc;
> +}
> +
>  int cmd_worktree(int ac, const char **av, const char *prefix)
>  {
>  	struct option options[] = {
> @@ -1056,5 +1069,7 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
>  		return move_worktree(ac - 1, av + 1, prefix);
>  	if (!strcmp(av[1], "remove"))
>  		return remove_worktree(ac - 1, av + 1, prefix);
> +	if (!strcmp(av[1], "repair"))
> +		return repair(ac - 1, av + 1, prefix);
>  	usage_with_options(worktree_usage, options);
>  }
> diff --git a/t/t2406-worktree-repair.sh b/t/t2406-worktree-repair.sh
> new file mode 100755
> index 0000000000..cc679e1a21
> --- /dev/null
> +++ b/t/t2406-worktree-repair.sh
> @@ -0,0 +1,11 @@
> +#!/bin/sh
> +
> +test_description='test git worktree repair'
> +
> +. ./test-lib.sh
> +
> +test_expect_success setup '
> +	test_commit init
> +'
> +
> +test_done
Previous: Eric SunshineNext: Eric Sunshine
Message 3 of 22 in “add "git worktree repair" command”
  1. 0/5 add "git worktree repair" commandEric Sunshine, Aug 27, 2020
  2. 1/5 worktree: add skeleton "repair" commandEric Sunshine, Aug 27, 2020
  3. Junio C HamanoAug 27, 2020
  4. Eric SunshineAug 27, 2020
  5. 5/5 init: make --separate-git-dir work from within linked worktreeEric Sunshine, Aug 27, 2020
  6. 4/5 init: teach --separate-git-dir to repair linked worktreesEric Sunshine, Aug 27, 2020
  7. 2/5 worktree: teach "repair" to fix worktree back-links to main worktreeEric Sunshine, Aug 27, 2020
  8. Junio C HamanoAug 27, 2020
  9. Eric SunshineAug 30, 2020
  10. 3/5 worktree: teach "repair" to fix outgoing links to worktreesEric Sunshine, Aug 27, 2020
  11. Junio C HamanoAug 27, 2020
  12. Eric SunshineAug 30, 2020
  13. Junio C HamanoAug 31, 2020
  14. Johannes SchindelinAug 28, 2020
  15. Eric SunshineAug 28, 2020
  16. 0/5 add "git worktree repair" commandEric Sunshine, Aug 31, 2020
  17. 1/5 worktree: add skeleton "repair" commandEric Sunshine, Aug 31, 2020
  18. 3/5 worktree: teach "repair" to fix outgoing links to worktreesEric Sunshine, Aug 31, 2020
  19. 5/5 init: make --separate-git-dir work from within linked worktreeEric Sunshine, Aug 31, 2020
  20. 2/5 worktree: teach "repair" to fix worktree back-links to main worktreeEric Sunshine, Aug 31, 2020
  21. 4/5 init: teach --separate-git-dir to repair linked worktreesEric Sunshine, Aug 31, 2020
  22. Junio C HamanoAug 31, 2020

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.