aboutsummaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2016-10-06 12:37:24 -0700
committerJunio C Hamano <gitster@pobox.com>2016-11-29 14:25:09 -0800
commit619acfc78c526bc9df17b7704e60d0512ab7a84c (patch)
treedcf2fbb2e6814b51aa4c4f05871601e3b5742294 /git-submodule.sh
parent250ab24ab3a35d5857855a2e00483dcd8867fdca (diff)
downloadgit-619acfc78c526bc9df17b7704e60d0512ab7a84c.tar.gz
git-619acfc78c526bc9df17b7704e60d0512ab7a84c.tar.xz
submodule add: extend force flag to add existing repos
Currently the force flag in `git submodule add` takes care of possibly ignored files or when a name collision occurs. However there is another situation where submodule add comes in handy: When you already have a gitlink recorded, but no configuration was done (i.e. no .gitmodules file nor any entry in .git/config) and you want to generate these config entries. For this situation allow `git submodule add` to proceed if there is already a submodule at the given path in the index. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh10
1 files changed, 8 insertions, 2 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index a024a135d..3762616b5 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -207,8 +207,14 @@ cmd_add()
tstart
s|/*$||
')
- git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
- die "$(eval_gettext "'\$sm_path' already exists in the index")"
+ 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