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

Re: bug?: git reset --mixed ignores deinitialized submodules

From
Stefan Beller <sbeller@google.com>
Date
Mar 13, 2017, 17:51 UTC
Message-ID
<CAGZ79kZmWaobW9e4iPY05y0N6PLcFphGnZmDHtrGKeV0Up70vg@mail.gmail.com>
In-Reply-To
<1489180018.10192.45.camel@novalis.org>
On Fri, Mar 10, 2017 at 1:06 PM, David Turner <novalis@novalis.org> wrote:
Show 25 quoted lines
> Git reset --mixed ignores submodules which are not initialized.  I've
> attached a demo script.
>
> On one hand, this matches the documentation ("Resets the index but not
> the working tree").  But on the other hand, it kind of doesn't: "(i.e.,
> the changed files are preserved but not marked for commit)".
>
> It's hard to figure out what a mixed reset should do.  It would be
> weird for it to initialize the submodule.  Maybe it should just refuse
> to run?  Maybe there should be an option for it to initialize the
> submodule for you?  Maybe it should drop a special-purpose file that
> git understands to be a submodule change?  For instance (and this is
> insane, but, like, maybe worth considering) it could use extended
> filesystem attributes, where available.
>
> #!/bin/bash
> mkdir demo
> cd demo
>
> git init main
>
> (
>         git init sub1 &&
>         cd sub1 &&
>         dd if=/dev/urandom of=f bs=40 count=1 &&
We prefer reproducability in tests, so if we take this into
a (regression) test later we may want to
    s/dd.../echo "determinism!" >f/
Show 8 quoted lines
> # commit that change on main,  deinit the submodule and do a mixed
> reset
> (
>         cd main &&
>         git add sub1 &&
>         git commit -m 'update sub1' &&
>         git submodule deinit sub1 &&
>         git reset --mixed HEAD^ &&

As of now most commands (including reset) are unaware of submodules to begin with. They are ignored in most cases, i.e. git-status has some tack-on to (pseudo-)report changes in submodules, but it's not really builtin.

A submodule that is not initialized ( i.e. submodule.<name>.url is unset) ought to not be touched at all. This is spelled out in the man page for "submodule update" only at this point.

>         git status # change to sub1 is lost
The change is not really lost, as you can get it via
    git checkout HEAD@{1}
    git submodule update --init

This works most of the time, but it is unreliable as the submodule may have had some gc inbetween which threw away important objects.

Steping back a bit, rereading the subject line, what do you think is the bug here?

* git-status not reporting about uninitialized submodules?
* git reset --mixed not touching the submodule worktree
* lack of --recurse-submodules in git-reset? (and that not
  being default, see prior point)
* submodules being in detached HEAD all the time?

Thanks, Stefan

Previous: David TurnerNext: David Turner
Message 2 of 5 in “bug?: git reset --mixed ignores deinitialized submodules”
  1. David TurnerMar 10, 2017
  2. Stefan BellerMar 13, 2017
  3. David TurnerMar 13, 2017
  4. Stefan BellerMar 13, 2017
  5. David TurnerMar 13, 2017

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.