Skip to content

Commit 17b254c

Browse files
stefanbellergitster
authored andcommitted
diff: submodule inline diff to initialize env array.
David reported: > When I try to run `git diff --submodule=diff` in a submodule which has > it's own submodules that have changes I get the error: fatal: bad > object. This happens, because we do not properly initialize the environment in which the diff is run in the submodule. That means we inherit the environment from the main process, which sets environment variables. (Apparently we do set environment variables which we do not set when not in a submodules, i.e. the .git directory is linked) This commit, just like fd47ae6 (diff: teach diff to display submodule difference with an inline diff, 2016-08-31) introduces bad test code (i.e. hard coded hash values), which will be cleanup up in a later patch. Reported-by: David Parrish <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b9e3c2 commit 17b254c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

submodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ void show_submodule_inline_diff(FILE *f, const char *path,
476476
if (!(dirty_submodule & DIRTY_SUBMODULE_MODIFIED))
477477
argv_array_push(&cp.args, oid_to_hex(new));
478478

479+
prepare_submodule_repo_env(&cp.env_array);
479480
if (run_command(&cp))
480481
fprintf(f, "(diff failed)\n");
481482

t/t4060-diff-submodule-option-diff-format.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,4 +746,33 @@ test_expect_success 'diff --submodule=diff with .git file' '
746746
test_cmp expected actual
747747
'
748748

749+
test_expect_success 'setup nested submodule' '
750+
git submodule add -f ./sm2 &&
751+
git commit -a -m "add sm2" &&
752+
git -C sm2 submodule add ../sm2 nested &&
753+
git -C sm2 commit -a -m "nested sub"
754+
'
755+
756+
test_expect_success 'move nested submodule HEAD' '
757+
echo "nested content" >sm2/nested/file &&
758+
git -C sm2/nested add file &&
759+
git -C sm2/nested commit --allow-empty -m "new HEAD"
760+
'
761+
762+
test_expect_success 'diff --submodule=diff with moved nested submodule HEAD' '
763+
cat >expected <<-EOF &&
764+
Submodule nested a5a65c9..b55928c:
765+
diff --git a/nested/file b/nested/file
766+
new file mode 100644
767+
index 0000000..ca281f5
768+
--- /dev/null
769+
+++ b/nested/file
770+
@@ -0,0 +1 @@
771+
+nested content
772+
EOF
773+
git -C sm2 diff --submodule=diff >actual 2>err &&
774+
test_must_be_empty err &&
775+
test_cmp expected actual
776+
'
777+
749778
test_done

0 commit comments

Comments
 (0)