All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2 6/6] worktree: new command to fix up worktree's info after moving
Date: Tue, 19 Jan 2016 10:25:31 -0800	[thread overview]
Message-ID: <xmqqa8o1bf50.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <1453116094-4987-7-git-send-email-pclouds@gmail.com> ("Nguyễn	Thái Ngọc Duy"'s message of "Mon, 18 Jan 2016 18:21:34 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> This is a low-level command that can be used to correct worktree
> information after a worktree is moved. The idea is like 'index refresh'.
> In future we may do "worktree refresh" automatically to keep it from
> being pruned.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---

I cannot help but think this is backwards.

Before this step, the users were essentially forbidden from using
"mv" to move a worktree, as doing so without telling Git can make
things inconsistent.  Why not keep that prohibition, and give one
and only official supported way to move a worktree, e.g. "worktree
mv", that explicitly tells Git what is being moved from where to
where?

It is prudent to avoid having to do things automatically, especially
that you already were burned once to be overly clever by doing
things automatically, no?  And telling users not to "mv" and instead
to use "worktree mv" would be one way to avoid having to "refresh"
automatically.

>  Documentation/git-worktree.txt |  8 +++++++-
>  builtin/worktree.c             | 18 ++++++++++++++++++
>  t/t1501-worktree.sh            |  9 +++++++++
>  3 files changed, 34 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
> index 62c76c1..306aeec 100644
> --- a/Documentation/git-worktree.txt
> +++ b/Documentation/git-worktree.txt
> @@ -12,6 +12,7 @@ SYNOPSIS
>  'git worktree add' [-f] [--detach] [-b <new-branch>] <path> [<branch>]
>  'git worktree prune' [-n] [-v] [--expire <expire>]
>  'git worktree list' [--porcelain]
> +'git worktree refresh'
>  
>  DESCRIPTION
>  -----------
> @@ -65,6 +66,11 @@ each of the linked worktrees.  The output details include if the worktree is
>  bare, the revision currently checked out, and the branch currently checked out
>  (or 'detached HEAD' if none).
>  
> +refresh::
> +
> +This command is required to update worktree's information after it's moved.
> +Executed from inside the moved worktree.
> +
>  OPTIONS
>  -------
>  
> @@ -140,7 +146,7 @@ in the entry's directory. For example, if a linked working tree is moved
>  to `/newpath/test-next` and its `.git` file points to
>  `/path/main/.git/worktrees/test-next`, then update
>  `/path/main/.git/worktrees/test-next/gitdir` to reference `/newpath/test-next`
> -instead.
> +instead. Alternatively you can run "git worktree refresh".
>  
>  To prevent a $GIT_DIR/worktrees entry from being pruned (which
>  can be useful in some situations, such as when the
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> index 475b958..0183ce0 100644
> --- a/builtin/worktree.c
> +++ b/builtin/worktree.c
> @@ -445,6 +445,22 @@ static int list(int ac, const char **av, const char *prefix)
>  	return 0;
>  }
>  
> +static int refresh(int ac, const char **av, const char *prefix)
> +{
> +	const char *gitdir;
> +
> +	if (ac != 1)
> +		die(_("Arguments not expected"));
> +
> +	gitdir = git_pathdup("gitdir");
> +	if (access(gitdir, F_OK))
> +		return 0;
> +	if (!startup_info->first_gitfile)
> +		die("BUG: .git file's location not found");
> +	write_file(gitdir, "%s", startup_info->first_gitfile);
> +	return 0;
> +}
> +
>  int cmd_worktree(int ac, const char **av, const char *prefix)
>  {
>  	struct option options[] = {
> @@ -459,5 +475,7 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
>  		return prune(ac - 1, av + 1, prefix);
>  	if (!strcmp(av[1], "list"))
>  		return list(ac - 1, av + 1, prefix);
> +	if (!strcmp(av[1], "refresh"))
> +		return refresh(ac - 1, av + 1, prefix);
>  	usage_with_options(worktree_usage, options);
>  }
> diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
> index cc5b870..821831b 100755
> --- a/t/t1501-worktree.sh
> +++ b/t/t1501-worktree.sh
> @@ -423,4 +423,13 @@ test_expect_success '$GIT_WORK_TREE overrides $GIT_DIR/common' '
>  	)
>  '
>  
> +test_expect_success 'worktree refresh corrects gitdir file' '
> +	git worktree add test-refresh &&
> +	P=repo.git/worktrees/test-refresh/gitdir &&
> +	echo corrupt >$P &&
> +	git -C test-refresh worktree refresh &&
> +	echo "$TRASH_DIRECTORY/test-refresh/.git" >expected &&
> +	test_cmp expected $P
> +'
> +
>  test_done

  parent reply	other threads:[~2016-01-19 18:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-18 11:21 [PATCH v2 0/6] Kill and replace update_linked_gitdir() Nguyễn Thái Ngọc Duy
2016-01-18 11:21 ` [PATCH v2 1/6] worktree.c: fix indentation Nguyễn Thái Ngọc Duy
2016-01-18 11:21 ` [PATCH v2 2/6] worktree: stop supporting moving worktrees manually Nguyễn Thái Ngọc Duy
2016-01-18 18:24   ` Eric Sunshine
2016-01-18 11:21 ` [PATCH v2 3/6] worktree.txt: how to fix up after moving a worktree Nguyễn Thái Ngọc Duy
2016-01-18 18:30   ` Eric Sunshine
2016-01-19  5:20     ` Duy Nguyen
2016-01-18 11:21 ` [PATCH v2 4/6] abspath.c: add and use real_path_dup() Nguyễn Thái Ngọc Duy
2016-01-18 11:21 ` [PATCH v2 5/6] setup.c: record the location of .git file Nguyễn Thái Ngọc Duy
2016-01-18 11:21 ` [PATCH v2 6/6] worktree: new command to fix up worktree's info after moving Nguyễn Thái Ngọc Duy
2016-01-18 13:07   ` Philip Oakley
2016-01-19 18:25   ` Junio C Hamano [this message]
2016-01-22  8:35 ` [PATCH v3 0/2] Kill and replace update_linked_gitdir() Nguyễn Thái Ngọc Duy
2016-01-22  8:35   ` [PATCH v3 1/2] worktree.c: fix indentation Nguyễn Thái Ngọc Duy
2016-01-22  8:35   ` [PATCH v3 2/2] worktree: stop supporting moving worktrees manually Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqa8o1bf50.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.