submodule: refuse to add repository with no commits
[gitweb.git] / git-submodule.sh
index b5f2beee60ab59a04b5b236da8df39403009db1b..16b49f1419f8431725edd841893753c4fddeb78d 100755 (executable)
@@ -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