Skip to content

Improve UX around missing submodules and '--recurse-submodules' for clone and checkout #752

Open
@phil-blain

Description

@phil-blain

When a user clones a repo with --recurse-submodules, clone writes the pathspec . to the config submodule.active.

If this repo at some point in its history had a submodule, but this submodule was then removed, then checking out an older commit where the submodule is still present fails if the checkout uses --recurse-submodules.

Reproducer:

git init checkout-removed-submodule &&
cd checkout-removed-submodule/ &&
echo "Hello, world" >foo &&
git add foo && git commit -m "Initial commit" &&
git init ../submodule &&
cd ../submodule/ &&
echo "Foo bar" >foobar.txt &&
git add foobar.txt && git commit -m "Foo bar baz" &&
cd ../checkout-removed-submodule/ &&
git submodule add ../submodule/ foobar &&
git commit -m "Add foobar submodule" &&
git rm foobar/ &&
git commit -m "Remove foobar submodule" &&
cd ../ &&
git clone --recurse-submodules checkout-removed-submodule cloned-repo  &&
cd cloned-repo && 
git co --recurse-submodules HEAD~
  fatal: not a git repository: ../.git/modules/foobar
  fatal: could not reset submodule index

Cf:
https://lore.kernel.org/git/20200501005432.h62dnpkx7feb7rto@glandium.org/T/#u
https://lore.kernel.org/git/CAE5ih78zCR0ZdHAjoxguUb3Y6KFkZcoxJjhS7rkbtZpr+d1n=g@mail.gmail.com/

A lot of improvements could be made here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions