Skip to content

Commit 04b1f1f

Browse files
phil-blaingitster
authored andcommitted
range-diff: show submodule changes irrespective of diff.submodule
After generating diffs for each range to be compared using a 'git log' invocation, range-diff.c::read_patches looks for the "diff --git" header in those diffs to recognize the beginning of a new change. In a project with submodules, and with 'diff.submodule=log' set in the config, this header is missing for the diff of a changed submodule, so any submodule changes are quietly ignored in the range-diff. When 'diff.submodule=diff' is set in the config, the "diff --git" header is also missing for the submodule itself, but is shown for submodule content changes, which can easily confuse 'git range-diff' and lead to errors such as: error: git apply: bad git-diff - inconsistent old filename on line 1 error: could not parse git header 'diff --git path/to/submodule/and/some/file/within ' error: could not parse log for '@{u}..@{1}' Force the submodule diff format to its default ("short") when invoking 'git log' to generate the patches for each range, such that submodule changes are always detected. Add a test, including an invocation with '--creation-factor=100' to force the second commit in the range not to be considered a complete rewrite, in order to verify we do indeed get the "short" format. Signed-off-by: Philippe Blain <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2668e36 commit 04b1f1f

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

range-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static int read_patches(const char *range, struct string_list *list,
4444

4545
strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
4646
"--reverse", "--date-order", "--decorate=no",
47-
"--no-prefix",
47+
"--no-prefix", "--submodule=short",
4848
/*
4949
* Choose indicators that are not used anywhere
5050
* else in diffs, but still look reasonable

t/t3206-range-diff.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,4 +772,55 @@ test_expect_success '--left-only/--right-only' '
772772
test_cmp expect actual
773773
'
774774

775+
test_expect_success 'submodule changes are shown irrespective of diff.submodule' '
776+
git init sub-repo &&
777+
test_commit -C sub-repo sub-first &&
778+
sub_oid1=$(git -C sub-repo rev-parse HEAD) &&
779+
test_commit -C sub-repo sub-second &&
780+
sub_oid2=$(git -C sub-repo rev-parse HEAD) &&
781+
test_commit -C sub-repo sub-third &&
782+
sub_oid3=$(git -C sub-repo rev-parse HEAD) &&
783+
784+
git checkout -b main-sub topic &&
785+
git submodule add ./sub-repo sub &&
786+
git -C sub checkout --detach sub-first &&
787+
git commit -m "add sub" sub &&
788+
sup_oid1=$(git rev-parse --short HEAD) &&
789+
git checkout -b topic-sub &&
790+
git -C sub checkout sub-second &&
791+
git commit -m "change sub" sub &&
792+
sup_oid2=$(git rev-parse --short HEAD) &&
793+
git checkout -b modified-sub main-sub &&
794+
git -C sub checkout sub-third &&
795+
git commit -m "change sub" sub &&
796+
sup_oid3=$(git rev-parse --short HEAD) &&
797+
sup_oid0=$(test_oid __) &&
798+
799+
test_config diff.submodule log &&
800+
git range-diff topic topic-sub modified-sub >actual &&
801+
cat >expect <<-EOF &&
802+
1: $sup_oid1 = 1: $sup_oid1 add sub
803+
2: $sup_oid2 < -: $sup_oid0 change sub
804+
-: $sup_oid0 > 2: $sup_oid3 change sub
805+
EOF
806+
test_cmp expect actual &&
807+
test_config diff.submodule diff &&
808+
git range-diff topic topic-sub modified-sub >actual &&
809+
git range-diff --creation-factor=100 topic topic-sub modified-sub >actual &&
810+
cat >expect <<-EOF &&
811+
1: $sup_oid1 = 1: $sup_oid1 add sub
812+
2: $sup_oid2 ! 2: $sup_oid3 change sub
813+
@@ Commit message
814+
## sub ##
815+
@@
816+
-Subproject commit $sub_oid1
817+
-+Subproject commit $sub_oid2
818+
++Subproject commit $sub_oid3
819+
EOF
820+
test_cmp expect actual &&
821+
test_config diff.submodule diff &&
822+
git range-diff --creation-factor=100 topic topic-sub modified-sub >actual &&
823+
test_cmp expect actual
824+
'
825+
775826
test_done

0 commit comments

Comments
 (0)