Bug with "git mv" and submodules, and with "git submodule add something --force"

3 messages, 3 authors, 2018-10-19 · open the first message on its own page

Bug with "git mv" and submodules, and with "git submodule add something --force"

From: Juergen Vogl <hidden>
Date: 2018-10-19 12:43:17

Hi there,

tested on both, git 2.18 and git 2.19.1:

moving a file with `git mv` from a project to a submodule results in an
**undefined state** of the local repository.

It breaks up the submodule (it's still in .gitmodules, but not
accessable via `git submodule`), and is not reversible on local repository.

Either `git mv submodule/file .` nor deleting the folder works. For the
locale repo the submodule is gone. But: trying to add it with `git
submodule add` also do not work and results in an error message (with
and without `--force` flag):

$ git submodule add git@github.com:-----------/wiki-public.git public
--force
A git directory for 'public' is found locally with remote(s):
  origin        git@github.com:-----------/wiki-public.git
If you want to reuse this local git directory instead of cloning again from
  git@github.com:-----------/wiki-public.git
use the '--force' option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the '--name'
option.

Therefore, it's in a undefined, broken state.


Another bug I've got by testing upper line:
* --force will be used as folder name * when used in `git submodule add
git@github.com:someone/some.git --force`:

$ git submodule add git@github.com:---/wiki-public.git --force
Cloning into '/home/---/---/---/---/wiki-internal.wiki/--force'...
remote: Enumerating objects: 29, done.
remote: Counting objects: 100% (29/29), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 29 (delta 5), reused 20 (delta 2), pack-reused 0
Receiving objects: 100% (29/29), 37.03 KiB | 421.00 KiB/s, done.
Resolving deltas: 100% (5/5), done.
/usr/libexec/git-core/git-submodule: line 273: cd: --: invalid option
cd: usage: cd [-L|-P] [dir]
Unable to checkout submodule '--force'

but it creates the `--force` folder:

$ tree
.
├── --force

Best,

Jürgen Vogl

Re: Bug with "git mv" and submodules, and with "git submodule add something --force"

From: Stefan Beller <hidden>
Date: 2018-10-19 20:40:28

On Fri, Oct 19, 2018 at 5:43 AM Juergen Vogl [off-list ref] wrote:
Hi there,

tested on both, git 2.18 and git 2.19.1:

moving a file with `git mv` from a project to a submodule results in an
**undefined state** of the local repository.
Luckily we do have a submodule in git.git itself, so we can
try it out here as well (I'll use a separate worktree to not
hose my main repo):

  git worktree add ../testgit && cd ../testgit
  git checkout v2.19.1 && make install
  git --version
  git version 2.19.1
  git submodule update --init
  Cloning into '/home/sbeller/testgit/sha1collisiondetection'...
  Submodule path 'sha1collisiondetection': checked out
'232357eb2ea0397388254a4b188333a227bf5b10'
  git mv cache.h sha1collisiondetection/
  git status
HEAD detached at v2.19.1
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

deleted:    sha1collisiondetection
renamed:    cache.h -> sha1collisiondetection/cache.h

Untracked files:
  (use "git add <file>..." to include in what will be committed)

sha1collisiondetection/.gitignore
sha1collisiondetection/.travis.yml
sha1collisiondetection/LICENSE.txt
sha1collisiondetection/Makefile
sha1collisiondetection/README.md
sha1collisiondetection/lib/
sha1collisiondetection/src/
sha1collisiondetection/test/
sha1collisiondetection/vs2015/
It breaks up the submodule (it's still in .gitmodules, but not
accessable via `git submodule`), and is not reversible on local repository.
This seems like what I just did. However reversing can be done via:

  git checkout -f
  git status
HEAD detached at v2.19.1
nothing to commit, working tree clean
  git submodule status
232357eb2ea0397388254a4b188333a227bf5b10 sha1collisiondetection
(stable-v1.0.3-31-g232357e)

So I think it's just "git-mv" that doesn't respect submodule
boundaries, which we would want to address.

The man page of git mv
(https://git-scm.com/docs/git-mv)
actually has a short note about submodules, but that is about
moving *a* submodule not about moving things in and out.

Maybe for now we can do with just an update of the documentation/bugs
section and say we cannot move files in and out of submodules?


Either `git mv submodule/file .`
which is just running the command in reverse, (i.e. swapping
destination and target),
  git mv cache.h sha1collisiondetection/
  git mv sha1collisiondetection/cache.h cache.h
  git status
HEAD detached at v2.19.1
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

deleted:    sha1collisiondetection

Untracked files:
  (use "git add <file>..." to include in what will be committed)

sha1collisiondetection/

which seems like the submodule is gone,
nor deleting the folder works. For the
locale repo the submodule is gone.
Yup, that seems to be the case.
But: trying to add it with `git
submodule add` also do not work and results in an error message (with
and without `--force` flag):
Would checkout out a state where the submodule still exists
(such as HEAD) and then running "git submodule update --init"
fix it instead?
$ git submodule add git@github.com:-----------/wiki-public.git public
--force
A git directory for 'public' is found locally with remote(s):
  origin        git@github.com:-----------/wiki-public.git
If you want to reuse this local git directory instead of cloning again from
  git@github.com:-----------/wiki-public.git
use the '--force' option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the '--name'
option.

Therefore, it's in a undefined, broken state.


Another bug I've got by testing upper line:
* --force will be used as folder name * when used in `git submodule add
git@github.com:someone/some.git --force`:
Yes, the order of arguments is important, the options
(such as --force) goes before the URL and path.
/usr/libexec/git-core/git-submodule: line 273: cd: --: invalid option
cd: usage: cd [-L|-P] [dir]
Unable to checkout submodule '--force'
Gah! We'd need to escape the path after the options,
i.e. cd -- --force
would cd into that directory, but I am unsure if that
is accepted by all shells.

Thanks,
Stefan

Re: Bug with "git mv" and submodules, and with "git submodule add something --force"

From: Jonathan Nieder <hidden>
Date: 2018-10-19 20:58:41

Stefan Beller wrote:
Maybe for now we can do with just an update of the documentation/bugs
section and say we cannot move files in and out of submodules?
I think we have some existing logic to prevent "git add"-ing a file
within a submodule to the superproject, for example.

So "git mv" should learn the same trick.  And perhaps the trick needs
to be moved down a layer (e.g. into the index API).  Hints?

Thanks,
Jonathan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help