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

Re: [PATCHv5 4/4] rm: absorb a submodules git dir before deletion

From
Stefan Beller <sbeller@google.com>
Date
Dec 27, 2016, 18:26 UTC
Message-ID
<CAGZ79kZLk2bNj2Z_PFfo9KzODn8nSihDLdLuKvpSPodR9Eg-4w@mail.gmail.com>
In-Reply-To
<CAGZ79kaRY0x+31-UiiBU1iBXGKAgeTRSSjvN0isd7jdg-Y7_rQ@mail.gmail.com>
On Tue, Dec 27, 2016 at 10:17 AM, Stefan Beller <sbeller@google.com> wrote:
Show 68 quoted lines
> On Mon, Dec 26, 2016 at 5:10 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Stefan Beller <sbeller@google.com> writes:
>>
>>> @@ -342,6 +313,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
>>>                       exit(0);
>>>       }
>>>
>>> +     submodules_absorb_gitdir_if_needed(prefix);
>>> +
>>>       /*
>>>        * If not forced, the file, the index and the HEAD (if exists)
>>>        * must match; but the file can already been removed, since
>>> @@ -358,9 +331,6 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
>>>                       oidclr(&oid);
>>>               if (check_local_mod(&oid, index_only))
>>>                       exit(1);
>>> -     } else if (!index_only) {
>>> -             if (check_submodules_use_gitfiles())
>>> -                     exit(1);
>>>       }
>>>
>>
>> Hmph.  It may be a bit strange to see an "index-only" remove to
>> touch working tree, no?  Yet submodules_absorb_gitdir_if_needed() is
>> unconditionally called above, which feels somewhat unexpected.
>
> I agree. In a reroll I'll protect the call with
>
>     if (!index_only)
>         submodules_absorb_gitdir_if_needed(prefix);
>
>>
>>> @@ -389,32 +359,20 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
>>>        */
>>>       if (!index_only) {
>>>               int removed = 0, gitmodules_modified = 0;
>>>               for (i = 0; i < list.nr; i++) {
>>>                       const char *path = list.entry[i].name;
>>>                       if (list.entry[i].is_submodule) {
>>> +                             struct strbuf buf = STRBUF_INIT;
>>> +
>>> +                             strbuf_addstr(&buf, path);
>>> +                             if (remove_dir_recursively(&buf, 0))
>>> +                                     die(_("could not remove '%s'"), path);
>>> +                             strbuf_release(&buf);
>>> +
>>> +                             removed = 1;
>>> +                             if (!remove_path_from_gitmodules(path))
>>> +                                     gitmodules_modified = 1;
>>> +                             continue;
>>>                       }
>>
>> I do not see any behaviour change from the original (not quoted
>> here), but it is somewhat surprising that "git rm ./submodule" does
>> not really check if the submodule has local modifications and files
>> that are not even added before remove_dir_recursively() is called.
>>
>> Or perhaps I am reading the code incorrectly and such a check is
>> done elsewhere?
>
> When determining if the entry is a submodule (i.e. setting
> the is_submodule bit) we have
>
>     list.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode);
>     if (list.entry[list.nr++].is_submodule &&
>       !is_staging_gitmodules_ok())
>         die (_("Please stage ..."));
>

Well scratch that. is_staging_gitmodules_ok only checks for the .gitmodules file and not for the submodule itself (the submodule is not an argument to that function)

The actual answer is found in check_local_mod called via
    if (!force) {
        struct object_id oid;
        if (get_oid("HEAD", &oid))
            oidclr(&oid);
        if (check_local_mod(&oid, index_only))
            exit(1);
    }
check_local_mod was touched in the previous patch as it has:
    /*
    * Is the index different from the file in the work tree?
    * If it's a submodule, is its work tree modified?
    */
    if (ce_match_stat(ce, &st, 0) ||
      (S_ISGITLINK(ce->ce_mode) &&
       bad_to_remove_submodule(ce->name,
            SUBMODULE_REMOVAL_DIE_ON_ERROR |
            SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED)))
                local_changes = 1;
Previous: Stefan BellerNext: Junio C Hamano
Message 12 of 13 in “[PATCHv5 0/4] git-rm absorbs submodule git directory before deletion”
  1. Stefan BellerDec 20, 2016
  2. 1/4 submodule.h: add extern keyword to functionsStefan Beller, Dec 20, 2016
  3. Junio C HamanoDec 27, 2016
  4. Stefan BellerDec 27, 2016
  5. 2/4 submodule: modernize ok_to_remove_submodule to use argv_arrayStefan Beller, Dec 20, 2016
  6. 3/4 submodule: rename and add flags to ok_to_remove_submoduleStefan Beller, Dec 20, 2016
  7. Junio C HamanoDec 27, 2016
  8. Stefan BellerDec 27, 2016
  9. 4/4 rm: absorb a submodules git dir before deletionStefan Beller, Dec 20, 2016
  10. Junio C HamanoDec 27, 2016
  11. Stefan BellerDec 27, 2016
  12. Stefan BellerDec 27, 2016
  13. Junio C HamanoDec 27, 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.