@matheusbsbs / matheus-bagliano / commits / 1392a37721
Fork 0

diff: a submodule not checked out is not modified

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>

Junio C Hamano committed May 3, 2008 at 17:04 UTC 1392a377219adfee7cc7532e3c60e51d79ab40b1
2 files changed +23 -4
diff-lib.c
+22 -3
@@ -337,9 +337,15 @@ int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
337 }
338 return run_diff_files(revs, options);
339 }
340 +
341 /*
341 - * See if work tree has an entity that can be staged. Return 0 if so,
342 - * return 1 if not and return -1 if error.
342 + * Has the work tree entity been removed?
343 + *
344 + * Return 1 if it was removed from the work tree, 0 if an entity to be
345 + * compared with the cache entry ce still exists (the latter includes
346 + * the case where a directory that is not a submodule repository
347 + * exists for ce that is a submodule -- it is a submodule that is not
348 + * checked out). Return negative for an error.
349 */
350 static int check_work_tree_entity(const struct cache_entry *ce, struct stat *st, char *symcache)
351 {
@@ -352,7 +358,20 @@ static int check_work_tree_entity(const struct cache_entry *ce, struct stat *st,
358 return 1;
359 if (S_ISDIR(st->st_mode)) {
360 unsigned char sub[20];
355 - if (resolve_gitlink_ref(ce->name, "HEAD", sub))
361 +
362 + /*
363 + * If ce is already a gitlink, we can have a plain
364 + * directory (i.e. the submodule is not checked out),
365 + * or a checked out submodule. Either case this is not
366 + * a case where something was removed from the work tree,
367 + * so we will return 0.
368 + *
369 + * Otherwise, if the directory is not a submodule
370 + * repository, that means ce which was a blob turned into
371 + * a directory --- the blob was removed!
372 + */
373 + if (!S_ISGITLINK(ce->ce_mode) &&
374 + resolve_gitlink_ref(ce->name, "HEAD", sub))
375 return 1;
376 }
377 return 0;
t/t4027-diff-submodule.sh
+1 -1
@@ -50,7 +50,7 @@ test_expect_success 'git diff-files --raw' '
50 test_cmp expect actual.files
51 '
52
53 -test_expect_failure 'git diff (empty submodule dir)' '
53 +test_expect_success 'git diff (empty submodule dir)' '
54 : >empty &&
55 rm -rf sub/* sub/.git &&
56 git diff > actual.empty &&