]> Kevux Git Server - rit/commit
diff --submodule=diff: do not fail on ever-initialied deleted submodules
authorDavid Turner <dturner@twosigma.com>
Tue, 31 Aug 2021 13:12:56 +0000 (09:12 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 Aug 2021 17:11:48 +0000 (10:11 -0700)
commitf1c0368da4d64f394e4c099cb3c232671040d725
tree405fc3b988ae1655abe9b97fb932a4e852f56920
parent4577d26dc0aaae3bb35c8906db96ba043716f3f7
diff --submodule=diff: do not fail on ever-initialied deleted submodules

If you have ever initialized a submodule, open_submodule will open it.
If you then delete the submodule's worktree directory (but don't
remove it from .gitmodules), git diff --submodule=diff would error out
as it attempted to chdir into the now-deleted working tree directory.

This only matters if the submodules git dir is absorbed.  If not, then
we no longer have anywhere to run the diff.  But that case does not
trigger this error, because in that case, open_submodule fails, so we
don't resolve a left commit, so we exit early, which is the only thing
we could do.

If absorbed, then we can run the diff from the submodule's absorbed
git dir (.git/modules/sm2).  In practice, that's a bit more
complicated, because `git diff` expects to be run from inside a
working directory, not a git dir.  So it looks in the config for
core.worktree, and does chdir("../../../sm2"), which is the very dir
that we're trying to avoid visiting because it's been deleted.  We
work around this by setting GIT_WORK_TREE (and GIT_DIR) to ".".  It is
little weird to set GIT_WORK_TREE to something that is not a working
tree just to avoid an unnecessary chdir, but it works.

Signed-off-by: David Turner <dturner@twosigma.com
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule.c
t/t4060-diff-submodule-option-diff-format.sh