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

Re: [PATCHv2 4/5] ok_to_remove_submodule: absorb the submodule git dir

From
Stefan Beller <sbeller@google.com>
Date
Dec 14, 2016, 18:52 UTC
Message-ID
<CAGZ79kZ=PqTKt5xDobnR5oqwz84i10ZobmQb6QqeA3aSkbrd8Q@mail.gmail.com>
In-Reply-To
<xmqqbmwexs9x.fsf@gitster.mtv.corp.google.com>
On Wed, Dec 14, 2016 at 10:46 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 44 quoted lines
> Stefan Beller <sbeller@google.com> writes:
>
>> It is a major reason to say no, when deciding if a submodule can be
>> deleted, if the git directory of the submodule being contained in the
>> submodule's working directory.
>>
>> Migrate the git directory into the superproject instead of failing,
>> and proceed with the other checks.
>>
>> Signed-off-by: Stefan Beller <sbeller@google.com>
>> ---
>>  submodule.c | 15 +++++++++++++--
>>  1 file changed, 13 insertions(+), 2 deletions(-)
>>
>> diff --git a/submodule.c b/submodule.c
>> index 2d13744b06..e42efa2337 100644
>> --- a/submodule.c
>> +++ b/submodule.c
>> @@ -1026,11 +1026,22 @@ int ok_to_remove_submodule(const char *path, unsigned flags)
>>       struct strbuf buf = STRBUF_INIT;
>>       int ok_to_remove = 1;
>>
>> +     /* Is it there? */
>>       if (!file_exists(path) || is_empty_dir(path))
>>               return 1;
>>
>> -     if (!submodule_uses_gitfile(path))
>> -             return 0;
>> +     /* Does it have a .git directory? */
>> +     if (!submodule_uses_gitfile(path)) {
>> +             absorb_git_dir_into_superproject("", path,
>> +                     ABSORB_GITDIR_RECURSE_SUBMODULES);
>> +
>> +             /*
>> +              * We should be using a gitfile by now. Let's double
>> +              * check as losing the git dir would be fatal.
>> +              */
>> +             if (!submodule_uses_gitfile(path))
>> +                     return 0;
>> +     }
>
> It feels a bit funny for a function that answers yes/no question to
> actually have a side effect, but probably it is OK.  It feels dirty,
> but I dunno.

Another approach would be to return more than yes/no but the reason why it is a no. And then the caller would call absorb_git_dir_into_superproject.

> A brief reading of the above makes us wonder what should happen if
> the absorb_git_dir_into_superproject() call fails, but a separate
> "submodule_uses_gitfile()" is needed to see if it failed?  Perhaps
> the function needs to tell the caller if it succeeded?

I don't know about the double check as I think we should really be sure before deleting that repo, but absorb_git_dir_into_superproject would fail/die if it would not actually absorb it, so maybe it is too much caution.

So I'd omit the double check in a reroll.
>
>>
>>       argv_array_pushl(&cp.args, "status", "--porcelain",
>>                                  "--ignore-submodules=none", NULL);
Previous: Junio C HamanoNext: Stefan Beller
Message 7 of 10 in “[PATCHv2 0/5] git-rm absorbs submodule git directory before deletion”
  1. Stefan BellerDec 13, 2016
  2. 1/5 submodule.h: add extern keyword to functionsStefan Beller, Dec 13, 2016
  3. 2/5 submodule: modernize ok_to_remove_submodule to use argv_arrayStefan Beller, Dec 13, 2016
  4. Junio C HamanoDec 14, 2016
  5. 4/5 ok_to_remove_submodule: absorb the submodule git dirStefan Beller, Dec 13, 2016
  6. Junio C HamanoDec 14, 2016
  7. Stefan BellerDec 14, 2016
  8. 5/5 rm: add absorb a submodules git dir before deletionStefan Beller, Dec 13, 2016
  9. Junio C HamanoDec 14, 2016
  10. 3/5 submodule: add flags to ok_to_remove_submoduleStefan Beller, Dec 13, 2016

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.