1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-28 12:59:41 +01:00

Merge branch 'sb/submodule-add-force'

"git submodule add" used to be confused and refused to add a
locally created repository; users can now use "--force" option
to add them.

* sb/submodule-add-force:
  submodule add: extend force flag to add existing repos
This commit is contained in:
Junio C Hamano 2017-02-02 13:36:54 -08:00
commit 1e6a89323b
2 changed files with 22 additions and 2 deletions

View file

@ -204,8 +204,14 @@ cmd_add()
tstart
s|/*$||
')
if test -z "$force"
then
git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
die "$(eval_gettext "'\$sm_path' already exists in the index")"
else
git ls-files -s "$sm_path" | sane_grep -v "^160000" > /dev/null 2>&1 &&
die "$(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")"
fi
if test -z "$force" && ! git add --dry-run --ignore-missing "$sm_path" > /dev/null 2>&1
then

View file

@ -152,6 +152,20 @@ test_expect_success 'submodule add to .gitignored path with --force' '
)
'
test_expect_success 'submodule add to reconfigure existing submodule with --force' '
(
cd addtest-ignore &&
git submodule add --force bogus-url submod &&
git submodule add -b initial "$submodurl" submod-branch &&
test "bogus-url" = "$(git config -f .gitmodules submodule.submod.url)" &&
test "bogus-url" = "$(git config submodule.submod.url)" &&
# Restore the url
git submodule add --force "$submodurl" submod
test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
test "$submodurl" = "$(git config submodule.submod.url)"
)
'
test_expect_success 'submodule add --branch' '
echo "refs/heads/initial" >expect-head &&
cat <<-\EOF >expect-heads &&