Skip to content

Commit 5a52214

Browse files
stefanbellergitster
authored andcommitted
diff: recurse into nested submodules for inline diff
When fd47ae6 (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>
1 parent 98985c6 commit 5a52214

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

submodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ void show_submodule_inline_diff(FILE *f, const char *path,
475475
cp.no_stdin = 1;
476476

477477
/* TODO: other options may need to be passed here. */
478-
argv_array_push(&cp.args, "diff");
478+
argv_array_pushl(&cp.args, "diff", "--submodule=diff", NULL);
479+
479480
argv_array_pushf(&cp.args, "--line-prefix=%s", line_prefix);
480481
if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
481482
argv_array_pushf(&cp.args, "--src-prefix=%s%s/",

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

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

749+
test_expect_success 'diff --submodule=diff recurses into nested submodules' '
750+
cat >expected <<-EOF &&
751+
Submodule sm2 contains modified content
752+
Submodule sm2 a5a65c9..280969a:
753+
diff --git a/sm2/.gitmodules b/sm2/.gitmodules
754+
new file mode 100644
755+
index 0000000..3a816b8
756+
--- /dev/null
757+
+++ b/sm2/.gitmodules
758+
@@ -0,0 +1,3 @@
759+
+[submodule "nested"]
760+
+ path = nested
761+
+ url = ../sm2
762+
Submodule nested 0000000...b55928c (new submodule)
763+
diff --git a/sm2/nested/file b/sm2/nested/file
764+
new file mode 100644
765+
index 0000000..ca281f5
766+
--- /dev/null
767+
+++ b/sm2/nested/file
768+
@@ -0,0 +1 @@
769+
+nested content
770+
diff --git a/sm2/nested/foo8 b/sm2/nested/foo8
771+
new file mode 100644
772+
index 0000000..db9916b
773+
--- /dev/null
774+
+++ b/sm2/nested/foo8
775+
@@ -0,0 +1 @@
776+
+foo8
777+
diff --git a/sm2/nested/foo9 b/sm2/nested/foo9
778+
new file mode 100644
779+
index 0000000..9c3b4f6
780+
--- /dev/null
781+
+++ b/sm2/nested/foo9
782+
@@ -0,0 +1 @@
783+
+foo9
784+
EOF
785+
git diff --submodule=diff >actual 2>err &&
786+
test_must_be_empty err &&
787+
test_cmp expected actual
788+
'
789+
749790
test_done

0 commit comments

Comments
 (0)