git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Merging after directory got turned into submodule
@ 2015-08-11 13:02 Martin von Gagern
  2015-08-11 13:25 ` John Keeping
  0 siblings, 1 reply; 2+ messages in thread
From: Martin von Gagern @ 2015-08-11 13:02 UTC (permalink / raw)
  To: git

Hi!

I've noticed that if I turn a subdirectory into a submodule, I'm having
severe trouble merging branches from before that change, even if they
don't modify that subdirectory at all.

I've posted this problem on Stack Overflow and started a bounty for it.
See http://stackoverflow.com/q/31821219/1468366. So far I haven't
received an answer, so I decided to ask here as well.

Here is an example.

# Create one project, to be used as a subproject later on
git init a
cd a
echo aaa > aa
git add -A
git commit -m a1
cd ..

# Create a second project, containing a as a normal directory initially
git init b
cd b
mkdir a b
echo aaa > a/aa
echo bbb > b/bb
git add -A
git commit -m b1

# Replace directory with submodule
git rm -r a
git submodule add ../a a
git commit -m b2

# Create feature brach starting at version without submodule
git submodule deinit .  # will error if I don't do this
git checkout -b branch HEAD^
echo abc > b/bb
git commit -a -m b3

# Try to merge the feature branch
git checkout master
git merge branch

This prints an error message:

> CONFLICT (file/directory): There is a directory with name a in branch.
> Adding a as a~HEAD
> Automatic merge failed; fix conflicts and then commit the result.

I get the same error if I do a git submodule update --init before the
git merge branch. I don't see any a~HEAD anywhere, neither in my
directory tree nor in the output from git status, which reads like this:

> On branch master
> You have unmerged paths.
>   (fix conflicts and run "git commit")
>
> Changes to be committed:
>
>     modified:   b/bb
>
> Unmerged paths:
>   (use "git add <file>..." to mark resolution)
>
>     added by us:     a

If I do git add a as suggested, I get another error:

> error: unable to index file a
> fatal: updating files failed

If I do git submodules update --init just before the merge, then I can
do git add a successfully. But if I forget to do so, and then try doing
that after the merge, I receive this error message:

> Submodule 'a' (…/a) registered for path 'a'
> Skipping unmerged submodule a

How do I recover from this situation? Something other than git merge
--abort, since I'd like to use it for things like git rebase as well,
and since in some scenarios (don't know how to reproduce) I couldn't
even abort the merge cleanly, and had to do a hard reset instead.

How can I avoid it in the first place? Is there some magic setting which
makes git do the right thing with submodules vs. directories during
merges, so that I don't have to manually post-process a merge which only
modifies files unrelated to the submodules?

If there is no easy way to avoid this, do you think I should file a bug
report for this? After all, replacing a subdirectory by a submodule
shouldn't be that rare, and neither should be merges across such a
change. So in my opinion, git should be able to cope with this.

Greetings,
 Martin von Gagern

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

* Re: Merging after directory got turned into submodule
  2015-08-11 13:02 Merging after directory got turned into submodule Martin von Gagern
@ 2015-08-11 13:25 ` John Keeping
  0 siblings, 0 replies; 2+ messages in thread
From: John Keeping @ 2015-08-11 13:25 UTC (permalink / raw)
  To: Martin von Gagern; +Cc: git

On Tue, Aug 11, 2015 at 03:02:41PM +0200, Martin von Gagern wrote:
> I've noticed that if I turn a subdirectory into a submodule, I'm having
> severe trouble merging branches from before that change, even if they
> don't modify that subdirectory at all.
> 
> I've posted this problem on Stack Overflow and started a bounty for it.
> See http://stackoverflow.com/q/31821219/1468366. So far I haven't
> received an answer, so I decided to ask here as well.
> 
> Here is an example.
> 
> # Create one project, to be used as a subproject later on
> git init a
> cd a
> echo aaa > aa
> git add -A
> git commit -m a1
> cd ..
> 
> # Create a second project, containing a as a normal directory initially
> git init b
> cd b
> mkdir a b
> echo aaa > a/aa
> echo bbb > b/bb
> git add -A
> git commit -m b1
> 
> # Replace directory with submodule
> git rm -r a
> git submodule add ../a a
> git commit -m b2
> 
> # Create feature brach starting at version without submodule
> git submodule deinit .  # will error if I don't do this
> git checkout -b branch HEAD^
> echo abc > b/bb
> git commit -a -m b3
> 
> # Try to merge the feature branch
> git checkout master
> git merge branch
> 
> This prints an error message:
> 
> > CONFLICT (file/directory): There is a directory with name a in branch.
> > Adding a as a~HEAD
> > Automatic merge failed; fix conflicts and then commit the result.
> 
> I get the same error if I do a git submodule update --init before the
> git merge branch. I don't see any a~HEAD anywhere, neither in my
> directory tree nor in the output from git status, which reads like this:
> 
> > On branch master
> > You have unmerged paths.
> >   (fix conflicts and run "git commit")
> >
> > Changes to be committed:
> >
> >     modified:   b/bb
> >
> > Unmerged paths:
> >   (use "git add <file>..." to mark resolution)
> >
> >     added by us:     a
> 
> If I do git add a as suggested, I get another error:

"git reset a" works for me (i.e. set a to what it was before merging).
If you then commit and check "git ls-tree HEAD" it shows "a" is still a
submodule.

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

end of thread, other threads:[~2015-08-11 13:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-11 13:02 Merging after directory got turned into submodule Martin von Gagern
2015-08-11 13:25 ` John Keeping

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