Re: [PATCH 5/7] worktree move: refuse to move worktrees with submodules
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Feb 2, 2018, 10:06 UTC
- Message-ID
- <CAPig+cSLMt_9+5-8f_MndJM0hHgp32Q1CUmaosfJcbGEV8j-zg@mail.gmail.com>
- In-Reply-To
- <20180124095357.19645-6-pclouds@gmail.com>
On Wed, Jan 24, 2018 at 4:53 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
Show 30 quoted lines
> Submodules contains .git files with relative paths. After a worktree
> move, these files need to be updated or they may point to nowhere.
>
> This is a bandage patch to make sure "worktree move" don't break
> people's worktrees by accident. When .git file update code is in
> place, this validate_no_submodules() could be removed.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> @@ -606,6 +606,27 @@ static int unlock_worktree(int ac, const char **av, const char *prefix)
> +static void validate_no_submodules(const struct worktree *wt)
> +{
> + struct index_state istate = { NULL };
> + int i, found_submodules = 0;
> +
> + if (read_index_from(&istate, worktree_git_path(wt, "index")) > 0) {
> + for (i = 0; i < istate.cache_nr; i++) {
> + struct cache_entry *ce = istate.cache[i];
> +
> + if (S_ISGITLINK(ce->ce_mode)) {
> + found_submodules = 1;
> + break;
> + }
> + }
> + }
> + discard_index(&istate);
> +
> + if (found_submodules)
> + die(_("working trees containing submodules cannot be moved"));Minor (not worth a re-roll): This could be simplified slightly by die()ing inside the loop rather than having 'found_submodules' and breaking from the loop. Doing so will leak 'istate', but it's die()ing anyhow, so should not be an issue (unless this code is someday libified).
> +}