summaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2019-04-09 19:07:35 -0400
committerJunio C Hamano <gitster@pobox.com>2019-04-10 12:52:48 +0900
commite13811189bbd6b8672e3359f25c1e10f0c9b3c20 (patch)
treee61568c6e9e0bdce7c3897599bae2a1e8513e923 /git-submodule.sh
parentaeb582a98374c094361cba1bd756dc6307432c42 (diff)
downloadgit-e13811189bbd6b8672e3359f25c1e10f0c9b3c20.tar.gz
submodule: refuse to add repository with no commits
When the path given to 'git submodule add' is an existing repository that is not in the index, the repository is passed to 'git add'. If this repository doesn't have a commit checked out, we don't get a useful result: there is no subproject OID to track, and any untracked files in the sub-repository are added as blobs in the top-level repository. To avoid getting into this state, abort if the path is a repository that doesn't have a commit checked out. Note that this check must come before the 'git add --dry-run' check because the next commit will make 'git add' fail when given a repository that doesn't have a commit checked out. Signed-off-by: Kyle Meyer <kyle@kyleam.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh7
1 files changed, 7 insertions, 0 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index b5f2beee60..16b49f1419 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -230,6 +230,13 @@ cmd_add()
die "$(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")"
fi
+ if test -d "$sm_path" &&
+ test -z $(git -C "$sm_path" rev-parse --show-cdup 2>/dev/null)
+ then
+ git -C "$sm_path" rev-parse --verify -q HEAD >/dev/null ||
+ die "$(eval_gettext "'\$sm_path' does not have a commit checked out")"
+ fi
+
if test -z "$force" &&
! git add --dry-run --ignore-missing --no-warn-embedded-repo "$sm_path" > /dev/null 2>&1
then