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

Re: Integrating submodules with no side effects

From
Stefan Beller <sbeller@google.com>
Date
Oct 18, 2016, 21:17 UTC
Message-ID
<CAGZ79kaFtzQDZrSJhJZ59xvBzn+6+UVDO65Ac+T6aFxMQaM_xQ@mail.gmail.com>
In-Reply-To
<CAHd499AN2VHL66c6JWxHqS-1bQ6y4PrGjZJiR_ad6HJsCGpeDQ@mail.gmail.com>

On Tue, Oct 18, 2016 at 12:35 PM, Robert Dailey <rcdailey.lists@gmail.com> wrote:

Show 28 quoted lines
> Hello git experts,
>
> I have in the past attempted to integrate submodules into my primary
> repository using the same directory name. However, this has always
> caused headache when going to and from branches that take you between
> when this integration occurred and when it didn't. It's a bit hard to
> explain. Basically, if I have a submodule "foo", and I delete that
> submodule and physically add its files under the same directory "foo",
> when I do a pull to get this change from another clone, it fails
> saying:
>
> error: The following untracked working tree files would be overwritten
> by checkout:
>         foo/somefile.txt
> Please move or remove them before you switch branches.
> Aborting
> could not detach HEAD
>
>
> Obviously, git can't delete the submodule because the files have also
> been added directly. I don't think it is built to handle this
> scenario. Here is the series of commands I ran to "integrate" the
> submodule (replace the submodule with a directory containing the exact
> contents of the submodule itself):
>
> #!/usr/bin/env bash
> mv "$1" "${1}_"
> git submodule deinit "$1"

This removes the submodule entries from .git/config (and it would remove the contents of that submodule, but they are moved)

> git rm "$1"
Removing the git link here.

So we still have the entries in the .gitmodules file there. Maybe add:

    name=$(git submodule-helper name $1)
    git config -f .gitmodules --unset submodule.$name.*
    git add .gitmodules
? (Could be optional)
> mv "${1}_" "$1"
> git add "$1/**"
Moving back into place and adding all files in there.
Show 10 quoted lines
>
> The above script is named git-integrate-submodule, I run it like so:
>
> $ git integrate-submodule foo
>
> Then I do:
>
> $ git commit -m 'Integrated foo submodule'
>
> Is there any way to make this work nicely?

I think you can just remove the gitlink from the index and not from the working tree ("git rm --cached $1")

> The only solution I've
> found is to obviously rename the directory before adding the physical
> files, for example name it foo1. Because they're different, they never
> "clash".

Also look at the difference between plumbing and porcelain commands[1], as plumbing is more stable than the porcelain, so it will be easier to maintain this script.

I think this would be an actually reasonable feature, which Git itself could support via "git submodule [de]integrate", but then we'd also want to see the reverse, i.e. take a sub directory and make it a submodule.

[1] e.g. https://www.kernel.org/pub/software/scm/git/docs/

Thanks, Stefan

Previous: Robert DaileyNext: Robert Dailey
Message 2 of 8 in “Integrating submodules with no side effects”
  1. Robert DaileyOct 18, 2016
  2. Stefan BellerOct 18, 2016
  3. Robert DaileyOct 19, 2016
  4. Stefan BellerOct 19, 2016
  5. Robert DaileyOct 19, 2016
  6. Stefan BellerOct 19, 2016
  7. Robert DaileyOct 19, 2016
  8. Robert DaileyOct 25, 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.