git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
* Branch switching with submodules where the submodule replaces a folder aborts unexpectedly
@ 2017-10-09 21:29 Thomas Braun
  2017-10-09 21:59 ` Stefan Beller
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Braun @ 2017-10-09 21:29 UTC (permalink / raw)
  To: git

Hi,

I'm currently in the progress of pulling some subprojects in a git repository of mine into their own repositories and adding these subprojects back as submodules.

While doing this I enountered a potential bug as checkout complains on branch switching that a file already exists.

I've reproduced it on debian stretch with the following git versions:

master:
git version 2.15.0.rc0.39.g2f0e14e649
pu:
git version 2.15.0.rc0.245.g6d586db062

A script to trigger it is

mkdir -p test/subproject
cd test
git init
touch subproject/1
git add subproject
git commit -m "blah"
cd ..
mkdir subproject
cd subproject
git init
touch 1
git add 1
git commit -m "blubb"
cd ../test
git branch old
git rm -rf subproject
git commit -m "remove blah"
git submodule add ../subproject
git add -A
git commit -m "added subproject"
git branch new
git checkout old

and this fails with 

$LANG=C ./run.sh 
Initialized empty Git repository in /home/XXX/devel/test/.git/
[master (root-commit) 33e6607] blah
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 subproject/1
Initialized empty Git repository in /home/XXX/devel/subproject/.git/
[master (root-commit) e817644] blubb
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 1
rm 'subproject/1'
[master 9cbfd57] remove blah
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 subproject/1
Cloning into '/home/XXX/devel/test/subproject'...
done.
[master 1c67e23] added subproject
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 subproject
error: The following untracked working tree files would be overwritten by checkout:
        subproject/1
Please move or remove them before you switch branches.
Aborting

If I'm misusing git here I'm glad for any advice.

Thanks,
Thomas

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

* Re: Branch switching with submodules where the submodule replaces a folder aborts unexpectedly
  2017-10-09 21:29 Branch switching with submodules where the submodule replaces a folder aborts unexpectedly Thomas Braun
@ 2017-10-09 21:59 ` Stefan Beller
  2017-10-12 11:48   ` Thomas Braun
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Beller @ 2017-10-09 21:59 UTC (permalink / raw)
  To: Thomas Braun; +Cc: git

On Mon, Oct 9, 2017 at 2:29 PM, Thomas Braun
<thomas.braun@virtuell-zuhause.de> wrote:
> Hi,
>
> I'm currently in the progress of pulling some subprojects in a git repository of mine into their own repositories and adding these subprojects back as submodules.
>
> While doing this I enountered a potential bug as checkout complains on branch switching that a file already exists.

(And I presume you know about --recurse-submodules as a flag for git-checkout)

This is consistent with our tests, unfortunately.

git/t$ ./t2013-checkout-submodule.sh
...
not ok 15 - git checkout --recurse-submodules: replace submodule with
a directory # TODO known breakage
...

> If I'm misusing git here I'm glad for any advice.

You are not.

Apart from this bug report, would you think that such filtering of
trees into submodules (and back again) might be an interesting feature
of Git or are these cases rare and special?

Thanks,
Stefan

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

* Re: Branch switching with submodules where the submodule replaces a folder aborts unexpectedly
  2017-10-09 21:59 ` Stefan Beller
@ 2017-10-12 11:48   ` Thomas Braun
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Braun @ 2017-10-12 11:48 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git

> Stefan Beller <sbeller@google.com> hat am 9. Oktober 2017 um 23:59 geschrieben:
> 
> 
> On Mon, Oct 9, 2017 at 2:29 PM, Thomas Braun
> <thomas.braun@virtuell-zuhause.de> wrote:
> > Hi,
> >
> > I'm currently in the progress of pulling some subprojects in a git repository of mine into their
> > own repositories and adding these subprojects back as submodules.
> >
> > While doing this I enountered a potential bug as checkout complains on branch switching that a 
> > file already exists.
> 
> (And I presume you know about --recurse-submodules as a flag for git-checkout)

No I did not know about it. I tend to not know options which don't complete in my shell (patch follows for that).

> This is consistent with our tests, unfortunately.
> 
> git/t$ ./t2013-checkout-submodule.sh
> ...
> not ok 15 - git checkout --recurse-submodules: replace submodule with
> a directory # TODO known breakage
> ...
> 
> > If I'm misusing git here I'm glad for any advice.
> 
> You are not.

Glad to know that.

> Apart from this bug report, would you think that such filtering of
> trees into submodules (and back again) might be an interesting feature
> of Git or are these cases rare and special?

For me not particularly. In my case it is a one time thing going from an embedded project folder to a submodule.

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

* Re: Branch switching with submodules where the submodule replaces a folder aborts unexpectedly
@ 2018-06-19 16:03 Sam Kuper
  0 siblings, 0 replies; 4+ messages in thread
From: Sam Kuper @ 2018-06-19 16:03 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Thomas Braun

On 12 Oct 2017 at 11:48 Thomas Braun wrote:
> On 9 Oct 2017 at 23:59, Stefan Beller wrote:
>> On 9 Oct 2017 at 14:29, Thomas Braun wrote:
>>> I'm currently in the progress of pulling some subprojects in a git repository of mine into their
>>> own repositories and adding these subprojects back as submodules.
>>>
>>> While doing this I enountered a potential bug as checkout complains on branch switching that a
>>> file already exists. [...]
>>>
>>> `error: The following untracked working tree files would be overwritten by checkout:`

I am currently attempting the same thing, and experiencing the same
bug, using Git 2.17.1.


>> (And I presume you know about --recurse-submodules as a flag for git-checkout)

The behaviour seems to be the same regardless of whether I use the
--recurse-submodules flag with git-checkout.


>> This is consistent with our tests, unfortunately. [...]
>>
>>> If I'm misusing git here I'm glad for any advice.
>>
>> You are not.
>
> Glad to know that.

I was also glad to see this reassurance :)

It might have been nice if the reassurance came at an earlier stage,
however: at the CLI, rather than only after searching the mailing
list. A user who does not think to do the latter might well labour
under the misapprehension that they have done something wrong, rather
than encountered a bug. Perhaps, if the bug is not going to be fixed
terribly soon, a sentence or two could be added to the error message
explaining the situation and advising the user of a workaround?

Speaking of which, what is a good workaround in this case?

`git checkout --force <branch>`?


>> Apart from this bug report, would you think that such filtering of
>> trees into submodules (and back again) might be an interesting feature
>> of Git or are these cases rare and special?
>
> For me not particularly. In my case it is a one time thing going from an embedded project folder to a submodule.

The option to convert an existing directory into a submodule is
something that I think developers like to have available. It seems
intuitive: "Oh, I see now that what this directory holds is
effectively a separate project. Let me check out a new branch, and
replace the directory with a submodule on that branch. Assuming it
goes well, then I will afterwards merge this new branch into master."

Regardless, the bug has clearly been giving people headaches for
several years (forgive me if you were already aware of these data
points):

- https://ryansechrest.com/2014/03/git-error-switching-branch-replacing-directory-submodule/

- http://blog.dcycle.com/blog/105/gitsubmodulizing-and-gitflow/

- https://stackoverflow.com/q/9299063

- https://stackoverflow.com/a/48402543

- https://stackoverflow.com/q/24091246

- https://stackoverflow.com/q/29372450

- https://github.com/supercollider/supercollider/issues/2001

- https://github.com/supercollider/supercollider/issues/2221

Thank you to Thomas for reporting this issue to the mailing list, and
to Stefan for the helpful reply. Thanks as always to the Git
maintainers, and good luck with fixing this bug :)

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-09 21:29 Branch switching with submodules where the submodule replaces a folder aborts unexpectedly Thomas Braun
2017-10-09 21:59 ` Stefan Beller
2017-10-12 11:48   ` Thomas Braun
2018-06-19 16:03 Sam Kuper

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox