diff: submodule inline diff to initialize env array.
authorStefan Beller <sbeller@google.com>
Fri, 31 Mar 2017 23:17:32 +0000 (16:17 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 2 Apr 2017 16:51:03 +0000 (09:51 -0700)
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 fd47ae6a5b (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 <daveparrish@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule.c
t/t4060-diff-submodule-option-diff-format.sh
index ece17315d671cf182f21c261d879c58f193cde09..17de8e83588538ce5cc51dcb992e224742643d78 100644 (file)
@@ -476,6 +476,7 @@ void show_submodule_inline_diff(FILE *f, const char *path,
        if (!(dirty_submodule & DIRTY_SUBMODULE_MODIFIED))
                argv_array_push(&cp.args, oid_to_hex(new));
 
+       prepare_submodule_repo_env(&cp.env_array);
        if (run_command(&cp))
                fprintf(f, "(diff failed)\n");
 
index 7e23b55ea4c5d8ddc11e74381083a1757c4553f8..d4a3ffa69cd2e88b19e05149d2e752bec89ee57c 100755 (executable)
@@ -746,4 +746,33 @@ test_expect_success 'diff --submodule=diff with .git file' '
        test_cmp expected actual
 '
 
+test_expect_success 'setup nested submodule' '
+       git submodule add -f ./sm2 &&
+       git commit -a -m "add sm2" &&
+       git -C sm2 submodule add ../sm2 nested &&
+       git -C sm2 commit -a -m "nested sub"
+'
+
+test_expect_success 'move nested submodule HEAD' '
+       echo "nested content" >sm2/nested/file &&
+       git -C sm2/nested add file &&
+       git -C sm2/nested commit --allow-empty -m "new HEAD"
+'
+
+test_expect_success 'diff --submodule=diff with moved nested submodule HEAD' '
+       cat >expected <<-EOF &&
+       Submodule nested a5a65c9..b55928c:
+       diff --git a/nested/file b/nested/file
+       new file mode 100644
+       index 0000000..ca281f5
+       --- /dev/null
+       +++ b/nested/file
+       @@ -0,0 +1 @@
+       +nested content
+       EOF
+       git -C sm2 diff --submodule=diff >actual 2>err &&
+       test_must_be_empty err &&
+       test_cmp expected actual
+'
+
 test_done