Skip to content

Commit 0dec322

Browse files
newrengitster
authored andcommitted
diff-merges: avoid history simplifications when diffing merges
Doing diffs for merges are special; they should typically avoid history simplification. For example, with git log --diff-merges=first-parent -- path the default history simplification would remove merge commits from consideration if the file "path" matched the second parent. That is counter to what the user wants when looking for first-parent diffs. Similar comments can be made for --diff-merges=separate (which diffs against both parents) and --diff-merges=remerge (which diffs against a remerge of the merge commit). However, history simplification still makes sense if not doing diffing merges, and it also makes sense for the combined and dense-combined forms of diffing merges (because both of those are defined to only show a diff when the merge result at the relevant paths differs from *both* parents). So, for separate, first-parent, and remerge styles of diff-merges, turn off history simplification. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d83d82 commit 0dec322

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

diff-merges.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static void set_separate(struct rev_info *revs)
2424
{
2525
suppress(revs);
2626
revs->separate_merges = 1;
27+
revs->simplify_history = 0;
2728
}
2829

2930
static void set_first_parent(struct rev_info *revs)
@@ -50,6 +51,7 @@ static void set_remerge_diff(struct rev_info *revs)
5051
{
5152
suppress(revs);
5253
revs->remerge_diff = 1;
54+
revs->simplify_history = 0;
5355
}
5456

5557
static diff_merges_setup_func_t func_by_opt(const char *optarg)

t/t4069-remerge-diff.sh

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,63 @@ test_expect_success 'remerge-diff w/ pathspec: limits to relevant file including
227227
# with sha256
228228
sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
229229
230-
git show --oneline --remerge-diff --full-history resolution -- "letters*" >tmp &&
230+
git show --oneline --remerge-diff resolution -- "letters*" >tmp &&
231+
sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
232+
test_cmp expect actual
233+
'
234+
235+
test_expect_success 'setup non-content conflicts' '
236+
git switch --orphan newbase &&
237+
238+
test_write_lines 1 2 3 4 5 6 7 8 9 >numbers &&
239+
git add numbers &&
240+
git commit -m base &&
241+
242+
git branch newside1 &&
243+
git branch newside2 &&
244+
245+
git checkout newside1 &&
246+
test_write_lines 1 2 three 4 5 6 7 8 9 >numbers &&
247+
git add numbers &&
248+
git commit -m side1 &&
249+
250+
git checkout newside2 &&
251+
test_write_lines 1 2 drei 4 5 6 7 8 9 >numbers &&
252+
git add numbers &&
253+
git commit -m side2 &&
254+
255+
git checkout -b newresolution newside1 &&
256+
test_must_fail git merge newside2 &&
257+
git checkout --theirs numbers &&
258+
git add -u numbers &&
259+
git commit -m resolved
260+
'
261+
262+
test_expect_success 'remerge-diff turns off history simplification' '
263+
git log -1 --oneline newresolution >tmp &&
264+
cat <<-EOF >>tmp &&
265+
diff --git a/numbers b/numbers
266+
remerge CONFLICT (content): Merge conflict in numbers
267+
index 070e9e7..5335e78 100644
268+
--- a/numbers
269+
+++ b/numbers
270+
@@ -1,10 +1,6 @@
271+
1
272+
2
273+
-<<<<<<< 96f1e45 (side1)
274+
-three
275+
-=======
276+
drei
277+
->>>>>>> 4fd522f (side2)
278+
4
279+
5
280+
6
281+
EOF
282+
# We still have some sha1 hashes above; rip them out so test works
283+
# with sha256
284+
sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
285+
286+
git show --oneline --remerge-diff newresolution -- numbers >tmp &&
231287
sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
232288
test_cmp expect actual
233289
'

0 commit comments

Comments
 (0)