git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Submodules: two confusing situations
@ 2016-11-01 22:13 David Turner
  2016-11-01 22:56 ` Stefan Beller
  0 siblings, 1 reply; 2+ messages in thread
From: David Turner @ 2016-11-01 22:13 UTC (permalink / raw)
  To: git@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1341 bytes --]

Consider the following two cases:

We have commit X and commit Y.  X is an ancestor of Y.

We're at X and doing get checkout Y -- or we're at Y and we're doing
git checkout X.

Case 1: Between X and Y, we have deleted a submodule.
In order to move from X to Y, git removes the submodule
from the working tree.

Case 2: Between X and Y, we have instead added a submodule.  In order
to move from Y to X (that is, the opposite direction), git *does not*
remove the submodule from the tree; instead, it gives a warning and
leaves the submodule behind.

I don't understand why these two cases are not symmetric.

-- 

Perhaps relatedly, consider the attached shell-script, which I have not yet made into a full git test because I'm not sure I understand the issues fully.

It creates three commits:

Commit 1 adds a submodule
Commit 2 removes that submodule and re-adds it into a subdirectory (sub1 to sub1/sub1).
Commit 3 adds an unrelated file.

Then it checks out commit 1 (first deinitializing the submodule to avoid case 2 above), and attempts to cherry-pick commit 3.  This seems like it ought to work, based on my understanding of cherry-pick.  But in fact it gives a conflict on the stuff from commit 2 (which is unrelated to commit 3).

This is confusing to me, and looks like a bug.  What am I missing?


[-- Attachment #2: submodule-merge.sh --]
[-- Type: application/octet-stream, Size: 1021 bytes --]

#!/bin/bash
set -euo pipefail

mkdir demo
cd demo

git init main

(
    git init sub1 &&
    cd sub1 &&
    dd if=/dev/urandom of=f bs=40 count=1 &&
    git add f &&
    git commit -m f
)

(
    cd main &&
    git submodule add ../sub1 sub1 &&
    > sub2 && git add sub2 &&
    git commit -m 'add both submodules' &&
    git tag start
)

#make a commit that replaces sub1 in a l->d transition
(
    cd main &&
    git rm sub1 &&
    mkdir sub1 &&
    git submodule add ../sub1 sub1/sub1 &&
    git commit -m 'f to d' &&

    #And another commit that just adds a random file.
    >foo &&
    git add foo &&
    git commit -m 'foo' &&

    git tag l-to-d

    # Now we want to get back to the start state
    git submodule deinit sub1/sub1 &&
    git checkout -b sub2 start &&
    # Finally, we want to cherry-pick an innocuous-looking commit from a branch
    # where we have previously made the l->d change
    # This should not fail, but does.
    git cherry-pick l-to-d
)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Submodules: two confusing situations
  2016-11-01 22:13 Submodules: two confusing situations David Turner
@ 2016-11-01 22:56 ` Stefan Beller
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Beller @ 2016-11-01 22:56 UTC (permalink / raw)
  To: David Turner; +Cc: git@vger.kernel.org

On Tue, Nov 1, 2016 at 3:13 PM, David Turner <David.Turner@twosigma.com> wrote:
> Consider the following two cases:
>
> We have commit X and commit Y.  X is an ancestor of Y.
>
> We're at X and doing get checkout Y -- or we're at Y and we're doing
> git checkout X.
>
> Case 1: Between X and Y, we have deleted a submodule.
> In order to move from X to Y, git removes the submodule
> from the working tree.
>
> Case 2: Between X and Y, we have instead added a submodule.  In order
> to move from Y to X (that is, the opposite direction), git *does not*
> remove the submodule from the tree; instead, it gives a warning and
> leaves the submodule behind.
>
> I don't understand why these two cases are not symmetric.

Because you are using git-submodule.sh that is only an approximation of
what is supposed to happen. ("git checkout [X | Y] && git submodule update"
I'd guess).

"git submodule update" only *updates* the submodules and doesn't *delete*
them at all. I think this originated from the historic behavior of
having the submodules
.git directory inside the submodule and not in the superprojects .git/module.
When having the .git dir inside the submodule, you cannot delete the submodule
as you'd potentially loose information (local commits) from the submodule.

I am currently working on implementing a flag --recurse-submodules for
git-checkout
that would be symmetrical from X -> Y and back, but that feature hasn't seen
the mailing list yet as I discovered yet another bug locally.
I think I found a reviewer though. ;)

The problem with doing a propoer checkout, i.e. update and deletion of
a submodule,
you need to be sure the submodule in its state can go away:
* no untracked files that are lost (except for gitignored files)
* clean index in the submodule and
* the submodule points at the recorded sha1 (i.e. there are no
  commits that would be dangling)

>
> Perhaps relatedly, consider the attached shell-script, which I have not yet made into a full git test because I'm not sure I understand the issues fully.
>
> It creates three commits:
>
> Commit 1 adds a submodule
> Commit 2 removes that submodule and re-adds it into a subdirectory (sub1 to sub1/sub1).
> Commit 3 adds an unrelated file.
>
> Then it checks out commit 1 (first deinitializing the submodule to avoid case 2 above), and attempts to cherry-pick commit 3.  This seems like it ought to work, based on my understanding of cherry-pick.  But in fact it gives a conflict on the stuff from commit 2 (which is unrelated to commit 3).

That sounds like a bug indeed.

>
> This is confusing to me, and looks like a bug.  What am I missing?
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-01 22:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-01 22:13 Submodules: two confusing situations David Turner
2016-11-01 22:56 ` Stefan Beller

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 NNTP newsgroup(s).