git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Duy Nguyen <pclouds@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>,
	Brandon Williams <bmwill@google.com>
Subject: Re: [PATCHv8 6/6] submodule: add absorb-git-dir function
Date: Mon, 19 Dec 2016 10:15:08 -0800	[thread overview]
Message-ID: <CAGZ79kYPEiUGXR-qTbbHzaeOwbHH88mdx7GP8QX2Ff1bypcrwQ@mail.gmail.com> (raw)
In-Reply-To: <20161219053507.GA2335@duynguyen.vn.dektech.internal>

On Sun, Dec 18, 2016 at 9:35 PM, Duy Nguyen <pclouds@gmail.com> wrote:
> On Mon, Dec 12, 2016 at 11:04:35AM -0800, Stefan Beller wrote:
>> diff --git a/dir.c b/dir.c
>> index e0efd3c2c3..d872cc1570 100644
>> --- a/dir.c
>> +++ b/dir.c
>> @@ -2773,3 +2773,15 @@ void connect_work_tree_and_git_dir(const char *work_tree_, const char *git_dir_)
>>       free(work_tree);
>>       free(git_dir);
>>  }
>> +
>> +/*
>> + * Migrate the git directory of the given path from old_git_dir to new_git_dir.
>> + */
>> +void relocate_gitdir(const char *path, const char *old_git_dir, const char *new_git_dir)
>> +{
>> +     if (rename(old_git_dir, new_git_dir) < 0)
>> +             die_errno(_("could not migrate git directory from '%s' to '%s'"),
>> +                     old_git_dir, new_git_dir);
>> +
>> +     connect_work_tree_and_git_dir(path, new_git_dir);
>
> Should we worry about recovering (e.g. maybe move new_git_dir back to
> old_git_dir) if this connect_work_tree_and_git_dir() fails?

What if the move back fails?

>
> Both write_file() and git_config_set_.. in this function may die(). In
> such a case the repo is in broken state and the user needs pretty good
> submodule understanding to recover from it, I think.
>
> Recovering is not easy (nor entirely safe) either, though I suppose if
> we keep original copies for modified files, then we could restore them
> after moving the directory back and pray the UNIX gods that all
> operations succeed.

There are different levels of brokenness available.
I just tried what happens if core.worktree is unset in a submodule
and that seems to not impact git operations (I only tested git-status
both in the superproject as well as in the submodule).

So I wonder why we set core.worktree at all here as it doesn't
seem to be needed.

Which means that the move of the git directory as well as the .git file
update to point at that moved directory are the important things
to get right.

So maybe:

1) rename the git dir or die
2) write the new gitlink
    If that fails remove the .git file (if it exists partially or empty)
    and undo 1) by calling rename again with swapped arguments
    and then die
3) set core.worktree
    If that fails, just warn the user

  reply	other threads:[~2016-12-19 18:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-12 19:04 [PATCHv7 0/6] submodule absorbgitdirs Stefan Beller
2016-12-12 19:04 ` [PATCHv8 1/6] submodule: use absolute path for computing relative path connecting Stefan Beller
2016-12-12 19:04 ` [PATCHv8 2/6] submodule helper: support super prefix Stefan Beller
2016-12-12 19:04 ` [PATCHv8 3/6] test-lib-functions.sh: teach test_commit -C <dir> Stefan Beller
2016-12-12 19:04 ` [PATCHv8 4/6] worktree: check if a submodule uses worktrees Stefan Beller
2016-12-12 19:04 ` [PATCHv8 5/6] move connect_work_tree_and_git_dir to dir.h Stefan Beller
2016-12-12 19:04 ` [PATCHv8 6/6] submodule: add absorb-git-dir function Stefan Beller
2016-12-19  5:35   ` Duy Nguyen
2016-12-19 18:15     ` Stefan Beller [this message]
2016-12-20  1:39       ` Duy Nguyen
2016-12-12 20:35 ` [PATCHv7 0/6] submodule absorbgitdirs Brandon Williams
2016-12-12 20:37   ` Stefan Beller

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=CAGZ79kYPEiUGXR-qTbbHzaeOwbHH88mdx7GP8QX2Ff1bypcrwQ@mail.gmail.com \
    --to=sbeller@google.com \
    --cc=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).