git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Git Submodule Problem - Bug?
@ 2011-11-28 17:13 Manuel Koller
  2011-11-29  9:24 ` Thomas Rast
  0 siblings, 1 reply; 11+ messages in thread
From: Manuel Koller @ 2011-11-28 17:13 UTC (permalink / raw)
  To: git; +Cc: Jens Lehmann, Heiko Voigt

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

Hi

I've encountered strange behavior of git submodule and I cannot think about a way to avoid the problem. I've added a small script that reproduces the problem in the current version of git (1.7.7.3, git-osx-installer).

The problem arises when I pull a commit that switches a submodule with another one and then run git submodule update. Say I have a repo "super" that has one submodule "sub1" in the folder "sub" and a clone "super2". Now I remove the submodule in "super2" and add another one ("sub2") again named "sub", commit this and push it. Now after pulling the commit to "super", I need to run git submodule sync and then git submodule update. 

I expect to end up with the submodule "sub2" in sub. But the log clearly shows that the commits from "sub1" are still there (the master branch belongs to "sub1" while origin/master comes from "sub2").  I get the following output:

> ...
> commit 77d8d11fed3b07e1d4e47b3df9fc44c278694a39
> Author: Manuel Koller <koller@stat.math.ethz.ch>
> Date:   Mon Nov 28 17:46:45 2011 +0100
> 
>     initial commit sub1
> commit 346fe6bd9e7957f10c5e833bb1155153379da41c
> Author: Manuel Koller <koller@stat.math.ethz.ch>
> Date:   Mon Nov 28 17:46:45 2011 +0100
> 
>     initial commit sub2

I think it should be twice the same, and "sub2". I checked also with Charon, on his machine, the two log messages reported are "sub1" which completely baffles me.

Best regards,

Manuel


[-- Attachment #2: submodule-bug-minimal-example.bash --]
[-- Type: application/octet-stream, Size: 1491 bytes --]

#/bin/bash

## set -e explicitly
set -e

## set current directory as working directory
wd=`pwd`

## create repositories to be used as submodules
mkdir sub1 sub2 remote
(cd sub1
    git init
    echo "test sub1" >> file
    git add file
    git commit -m "initial commit sub1"
)
git clone --bare sub1 remote/sub1.git
(cd sub2
    git init
    echo "test sub2" >> file
    git add file
    git commit -m "initial commit sub2"
)
git clone --bare sub2 remote/sub2.git

## create super repository
git init --bare remote/super.git
git clone remote/super.git super
(cd super
    git submodule add $wd/remote/sub1.git sub
    git commit -m "Added submodule sub1 as sub"
    git push -u origin master
)

## clone super repository again
## and switch submodule sub1 by sub2
git clone --recursive remote/super.git super2
(cd super2
    ## remote submodule sub
    git config --remove-section submodule.sub
    git rm .gitmodules
    rm -rf sub
    git rm sub
    git commit -m "Removed submodule sub"
    ## add submodule sub2 as sub
    git submodule add $wd/remote/sub2.git sub
    git commit -m "Added submodule sub2 as sub"
    git push
)

## now pull super
(cd super
    git pull
    ## this will fail
    git submodule update --init || echo "submodule update fails, that's ok"
    ## so sync first und update again
    git submodule sync
    git submodule update --init
    ## now sub is corrupt
    (cd sub
	git log master ## this is from sub1
	git log origin/master ## this is from sub2
    )
)

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

end of thread, other threads:[~2011-12-07 21:57 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-28 17:13 Git Submodule Problem - Bug? Manuel Koller
2011-11-29  9:24 ` Thomas Rast
2011-11-29 10:15   ` Fredrik Gustafsson
2011-11-29 10:25     ` Thomas Rast
2011-11-29 10:41       ` Fredrik Gustafsson
2011-11-29 17:42         ` Jens Lehmann
2011-11-29 18:15           ` Manuel Koller
2011-11-29 19:21             ` Junio C Hamano
2011-11-29 22:03           ` Heiko Voigt
2011-12-07  8:21             ` Manuel Koller
2011-12-07 21:56               ` Jens Lehmann

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).