submodules: add helper to determine if a submodule is populated
[gitweb.git] / submodule.c
index 6f7d883de950af8ba6427537d09e021a4bed36bd..ee3198dc245a31ca47f143a6016b978b251c2ed7 100644 (file)
@@ -198,6 +198,21 @@ void gitmodules_config(void)
        }
 }
 
+/*
+ * Determine if a submodule has been populated at a given 'path'
+ */
+int is_submodule_populated(const char *path)
+{
+       int ret = 0;
+       char *gitdir = xstrfmt("%s/.git", path);
+
+       if (resolve_gitdir(gitdir))
+               ret = 1;
+
+       free(gitdir);
+       return ret;
+}
+
 int parse_submodule_update_strategy(const char *value,
                struct submodule_update_strategy *dst)
 {
@@ -1227,7 +1242,7 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 {
        struct strbuf file_name = STRBUF_INIT;
        struct strbuf rel_path = STRBUF_INIT;
-       const char *real_work_tree = xstrdup(real_path(work_tree));
+       const char *real_work_tree = real_pathdup(work_tree);
 
        /* Update gitfile */
        strbuf_addf(&file_name, "%s/.git", work_tree);