Commit b554ca5dc1b95234589367eda269a94bdda3d6ae

Edward Thomson 2014-01-20T15:12:06

"Uninitialized" submodules are "unmodified" Extend the "unmodified" submodule workdir test to include uninitialized submodules, to prevent reporting submodules as modified when they're not in the workdir at all.

diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index 907e5a1..af08ba6 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -97,7 +97,8 @@ typedef enum {
 	(((S) & GIT_SUBMODULE_STATUS__INDEX_FLAGS) == 0)
 
 #define GIT_SUBMODULE_STATUS_IS_WD_UNMODIFIED(S) \
-	(((S) & GIT_SUBMODULE_STATUS__WD_FLAGS) == 0)
+	(((S) & (GIT_SUBMODULE_STATUS__WD_FLAGS & \
+	~GIT_SUBMODULE_STATUS_WD_UNINITIALIZED)) == 0)
 
 #define GIT_SUBMODULE_STATUS_IS_WD_DIRTY(S) \
 	(((S) & (GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED | \
diff --git a/tests/status/submodules.c b/tests/status/submodules.c
index ef2888f..dc7990c 100644
--- a/tests/status/submodules.c
+++ b/tests/status/submodules.c
@@ -221,3 +221,20 @@ void test_status_submodules__dirty_workdir_only(void)
 		git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
 	cl_assert_equal_i(6, counts.entry_count);
 }
+
+void test_status_submodules__uninitialized(void)
+{
+	git_repository *cloned_repo;
+	git_status_list *statuslist;
+
+	g_repo = cl_git_sandbox_init("submod2");
+
+	cl_git_pass(git_clone(&cloned_repo, "submod2", "submod2-clone", NULL));
+
+	cl_git_pass(git_status_list_new(&statuslist, cloned_repo, NULL));
+	cl_assert_equal_i(0, git_status_list_entrycount(statuslist));
+
+	git_status_list_free(statuslist);
+	git_repository_free(cloned_repo);
+	cl_git_sandbox_cleanup();
+}