diff: recurse into nested submodules for inline diff
authorStefan Beller <sbeller@google.com>
Thu, 4 May 2017 21:43:55 +0000 (14:43 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 May 2017 00:44:54 +0000 (09:44 +0900)
When fd47ae6a5b (diff: teach diff to display submodule difference with an
inline diff, 2016-08-31) was introduced, we did not think of recursing
into nested submodules.

When showing the inline diff for submodules, automatically recurse
into nested submodules as well with inline submodule diffs.

Signed-off-by: Stefan Beller <sbeller@google.com>
Acked-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule.c
t/t4060-diff-submodule-option-diff-format.sh
index 5a62aa29609855a6c985be0ad55bf68193be0626..be29b3471a3a2ae136a33870f3e6299c85049b73 100644 (file)
@@ -475,7 +475,8 @@ void show_submodule_inline_diff(FILE *f, const char *path,
        cp.no_stdin = 1;
 
        /* TODO: other options may need to be passed here. */
-       argv_array_push(&cp.args, "diff");
+       argv_array_pushl(&cp.args, "diff", "--submodule=diff", NULL);
+
        argv_array_pushf(&cp.args, "--line-prefix=%s", line_prefix);
        if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
                argv_array_pushf(&cp.args, "--src-prefix=%s%s/",
index 7e23b55ea4c5d8ddc11e74381083a1757c4553f8..33b661140d18083c7c721afc702c5b45beb584d1 100755 (executable)
@@ -746,4 +746,45 @@ test_expect_success 'diff --submodule=diff with .git file' '
        test_cmp expected actual
 '
 
+test_expect_success 'diff --submodule=diff recurses into nested submodules' '
+       cat >expected <<-EOF &&
+       Submodule sm2 contains modified content
+       Submodule sm2 a5a65c9..280969a:
+       diff --git a/sm2/.gitmodules b/sm2/.gitmodules
+       new file mode 100644
+       index 0000000..3a816b8
+       --- /dev/null
+       +++ b/sm2/.gitmodules
+       @@ -0,0 +1,3 @@
+       +[submodule "nested"]
+       +       path = nested
+       +       url = ../sm2
+       Submodule nested 0000000...b55928c (new submodule)
+       diff --git a/sm2/nested/file b/sm2/nested/file
+       new file mode 100644
+       index 0000000..ca281f5
+       --- /dev/null
+       +++ b/sm2/nested/file
+       @@ -0,0 +1 @@
+       +nested content
+       diff --git a/sm2/nested/foo8 b/sm2/nested/foo8
+       new file mode 100644
+       index 0000000..db9916b
+       --- /dev/null
+       +++ b/sm2/nested/foo8
+       @@ -0,0 +1 @@
+       +foo8
+       diff --git a/sm2/nested/foo9 b/sm2/nested/foo9
+       new file mode 100644
+       index 0000000..9c3b4f6
+       --- /dev/null
+       +++ b/sm2/nested/foo9
+       @@ -0,0 +1 @@
+       +foo9
+       EOF
+       git diff --submodule=diff >actual 2>err &&
+       test_must_be_empty err &&
+       test_cmp expected actual
+'
+
 test_done