Search code examples
gitmsysgit

Git: submodule with leading minus


I need to create a submodule with a leading minus and hence execute following command using msysgit 1.7.10:

mike@desktop /c/temp/git/repo1 (master)
$ git submodule add -- ../repo2 "- submodule"
The following path is ignored by one of your .gitignore files:
- submodule
Use -f if you really want to add it.

OK, then I try with the force-option:

mike@desktop /c/temp/git/repo1 (master)
$ git submodule add -f -- ../repo2 "- submodule"
error: unknown switch ` '
usage: git clone [options] [--] <repo> [<dir>]

    -v, --verbose         be more verbose
    -q, --quiet           be more quiet
    --progress            force progress reporting
    -n, --no-checkout     don't create a checkout
    --bare                create a bare repository
    --mirror              create a mirror repository (implies bare)
    -l, --local           to clone from a local repository
    --no-hardlinks        don't use local hardlinks, always copy
    -s, --shared          setup as shared repository
    --recursive           initialize submodules in the clone
    --recurse-submodules  initialize submodules in the clone
    --template <template-directory>
                          directory from which templates will be used
    --reference <repo>    reference repository
    -o, --origin <name>   use <name> instead of 'origin' to track upstream
    -b, --branch <branch>
                          checkout <branch> instead of the remote's HEAD
    -u, --upload-pack <path>
                          path to git-upload-pack on the remote
    --depth <depth>       create a shallow clone of that depth
    --single-branch       clone only one branch, HEAD or --branch
    --separate-git-dir <gitdir>
                          separate git dir from working tree
    -c, --config <key=value>
                          set config inside the new repository

Clone of 'c:/temp/git/repo2' into submodule path '- submodule' failed

Strange, I invoked git submodule' and get an error aboutgit clone`.


Solution

  • This looks like a bug in git-submodule.sh - it calls:

    git add $force "$sm_path"
    

    ... which will clearly fail with a path like - submodule. It would have to be:

    git add $force -- "$sm_path"
    

    ... instead. There are several other places in git-submodule.sh that will also fail if the submodule path looks like an option, however, so the fix isn't straightforward.

    I would strongly suggest that you don't try to use a submodule path that begins with -.