]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff: a submodule not checked out is not modified
authorJunio C Hamano <gitster@pobox.com>
Sun, 4 May 2008 00:04:42 +0000 (17:04 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 May 2008 00:41:27 +0000 (17:41 -0700)
948dd34 (diff-index: careful when inspecting work tree items, 2008-03-30)
made the work tree check careful not to be fooled by a new directory that
exists at a place the index expects a blob.  For such a change to be a
typechange from blob to submodule, the new directory has to be a
repository.

However, if the index expects a submodule there, we should not insist the
work tree entity to be a repository --- a simple directory that is not a
full fledged repository (even an empty directory would do) should be
considered an unmodified subproject, because that is how a superproject
with a submodule is checked out sparsely by default.

This makes the function check_work_tree_entity() even more careful not to
report a submodule that is not checked out as removed.  It fixes the
recently added test in t4027.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff-lib.c
t/t4027-diff-submodule.sh

index cfd629da48526f5949124b5d9baeb52dfadd5f64..e0ebcdcf5434b3281fa81fcf1330ece2ddc94fba 100644 (file)
@@ -337,9 +337,15 @@ int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
        }
        return run_diff_files(revs, options);
 }
+
 /*
- * See if work tree has an entity that can be staged.  Return 0 if so,
- * return 1 if not and return -1 if error.
+ * Has the work tree entity been removed?
+ *
+ * Return 1 if it was removed from the work tree, 0 if an entity to be
+ * compared with the cache entry ce still exists (the latter includes
+ * the case where a directory that is not a submodule repository
+ * exists for ce that is a submodule -- it is a submodule that is not
+ * checked out).  Return negative for an error.
  */
 static int check_work_tree_entity(const struct cache_entry *ce, struct stat *st, char *symcache)
 {
@@ -352,7 +358,20 @@ static int check_work_tree_entity(const struct cache_entry *ce, struct stat *st,
                return 1;
        if (S_ISDIR(st->st_mode)) {
                unsigned char sub[20];
-               if (resolve_gitlink_ref(ce->name, "HEAD", sub))
+
+               /*
+                * If ce is already a gitlink, we can have a plain
+                * directory (i.e. the submodule is not checked out),
+                * or a checked out submodule.  Either case this is not
+                * a case where something was removed from the work tree,
+                * so we will return 0.
+                *
+                * Otherwise, if the directory is not a submodule
+                * repository, that means ce which was a blob turned into
+                * a directory --- the blob was removed!
+                */
+               if (!S_ISGITLINK(ce->ce_mode) &&
+                   resolve_gitlink_ref(ce->name, "HEAD", sub))
                        return 1;
        }
        return 0;
index 61caad0f5d4bea470226daf60780066abc99e5d3..ba6679c6e4032bb12e4206226f95770946ece8cc 100755 (executable)
@@ -50,7 +50,7 @@ test_expect_success 'git diff-files --raw' '
        test_cmp expect actual.files
 '
 
-test_expect_failure 'git diff (empty submodule dir)' '
+test_expect_success 'git diff (empty submodule dir)' '
        : >empty &&
        rm -rf sub/* sub/.git &&
        git diff > actual.empty &&