[PATCH v5 1/5] t4219: test more --follow cases across merges
- From
Miklos Vajna <vmiklos@collabora.com>
- Date
- Nov 9, 2026, 08:04 UTC
- Message-ID
- <5512aa682f71243378c06dcb8cda2b53150d4e39.1794078554.git.vmiklos@collabora.com>
- In-Reply-To
- <cover.1794078554.git.vmiklos@collabora.com>
A later commit in this series will speed up 'git log --follow' for merge commits. Add tests for cases which already work, but have no test coverage, so it's easy to break them while optimizing:
- a subtree merge adding the history of a file that was copied before - --follow through a fork with renames on both sides, with -c, --cc and --remerge-diff - a --no-ff merge taking a rename from the second parent, in both commit orders, since the result could depend on the walk order - a merge keeping the path, while the other side renamed it - --diff-merges=first-parent, which diffs merges only against their first parent, but still walks all parents - a merge keeping the renamed path, while the other side edited the old one - a merge keeping the copied path, while the other side edited the original
Helped-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Miklos Vajna <vmiklos@collabora.com> --- t/t4219-log-follow-merge.sh | 214 ++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+)
diff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh index e370f82955..806ccc24bd 100755 --- a/t/t4219-log-follow-merge.sh +++ b/t/t4219-log-follow-merge.sh @@ -31,6 +31,33 @@ test_expect_success '--follow finds the pre-merge commit through a subtree merge test_cmp expect actual ' +test_expect_success 'setup subtree merge adding the history of a copied file' ' + git init graft && + echo outer >graft/outer.txt && + git -C graft add outer.txt && + test_tick && + git -C graft commit -m "outer init" && + mkdir graft/inner && + cp inner/inner.txt graft/inner/ && + git -C graft add inner && + test_tick && + git -C graft commit -m "copy inner.txt to inner/" && + + git -C graft fetch ../inner master && + test_tick && + git -C graft merge -s ours --allow-unrelated-histories \ + -m "Merge the history of inner/" FETCH_HEAD +' + +test_expect_success '--follow finds the history of a copied file through a subtree merge' ' + git -C graft log --follow --pretty=tformat:%s inner/inner.txt >actual && + cat >expect <<-\EOF && + copy inner.txt to inner/ + inner init + EOF + test_cmp expect actual +' + test_expect_success 'setup merge of two branches that both renamed a file to README' ' git init foo && mkdir foo/foo && @@ -126,4 +153,191 @@ test_expect_success '--follow follows renames through a fork in a single history test_cmp expect actual.sorted ' +for opt in -c --cc --remerge-diff +do + test_expect_success "--follow follows renames through a fork with $opt" ' + git -C diamond log --follow $opt --pretty=tformat:%s path >log && + grep "^[A-Z]: " log | sort >actual && + cat >expect <<-\EOF && + A: add path0 + B: modify path0 on upper + C: modify path0 on lower + M: merge with rename to path + X: rename path0 to path1 + Y: rename path0 to path2 + Z: modify path + EOF + test_cmp expect actual + ' +done + +# Build a merge that takes the renamed path from the second parent, while the +# first parent only has the old path. $2 decides which side is committed first, +# which decides the walk order. +setup_rename_on_second_parent () { + git init $1 && + printf "line 1\nline 2\nline 3\nline 4\nline 5\n" >$1/old && + git -C $1 add old && + test_tick && + git -C $1 commit -m "A: add old" && + printf "line 1\nline 2\nline 3 modified\nline 4\nline 5\n" >$1/old && + test_tick && + git -C $1 commit -am "B: modify old" && + git -C $1 branch topic && + + if test "$2" = topic-first + then + git -C $1 checkout topic && + git -C $1 mv old new && + test_tick && + git -C $1 commit -m "R: rename old to new" && + git -C $1 checkout master + fi && + + echo other >$1/other && + git -C $1 add other && + test_tick && + git -C $1 commit -m "M: unrelated change on master" && + + if test "$2" = master-first + then + git -C $1 checkout topic && + git -C $1 mv old new && + test_tick && + git -C $1 commit -m "R: rename old to new" && + git -C $1 checkout master + fi && + + test_tick && + git -C $1 merge --no-ff -m "merge topic" topic +} + +test_expect_success 'setup merge taking a rename from the second parent' ' + setup_rename_on_second_parent rename-master-first master-first && + setup_rename_on_second_parent rename-topic-first topic-first +' + +for order in master-first topic-first +do + test_expect_success "--follow follows a rename from the second parent ($order)" ' + git -C rename-$order log --follow --pretty=tformat:%s new >actual && + cat >expect <<-\EOF && + R: rename old to new + B: modify old + A: add old + EOF + test_cmp expect actual + ' +done + +test_expect_success 'setup merge keeping the path, other side renamed it' ' + git init keep && + printf "line 1\nline 2\nline 3\nline 4\nline 5\n" >keep/F && + git -C keep add F && + test_tick && + git -C keep commit -m "O: add F" && + git -C keep branch B && + printf "line 1\nline 2\nline 3 A\nline 4\nline 5\n" >keep/F && + test_tick && + git -C keep commit -am "A1: update F in place" && + + git -C keep checkout B && + git -C keep mv F G && + test_tick && + git -C keep commit -m "B1: rename F to G" && + printf "line 1\nline 2\nline 3\nline 4 B\nline 5\n" >keep/G && + test_tick && + git -C keep commit -am "B2: update G" && + + git -C keep checkout master && + test_tick && + git -C keep merge -s ours -m "M: merge B, keep F, drop G" B +' + +test_expect_success '--follow follows a rename on the side the merge did not take' ' + git -C keep log --follow --pretty=tformat:%s F >actual && + cat >expect <<-\EOF && + B2: update G + B1: rename F to G + A1: update F in place + O: add F + EOF + test_cmp expect actual +' + +test_expect_success '--follow with --diff-merges=first-parent follows all parents' ' + git -C keep log --follow --diff-merges=first-parent --no-patch \ + --pretty=tformat:%s F >actual && + cat >expect <<-\EOF && + B2: update G + B1: rename F to G + A1: update F in place + O: add F + EOF + test_cmp expect actual +' + +test_expect_success 'setup merge keeping the renamed path, other side edited the old one' ' + git init keep-renamed && + printf "line 1\nline 2\nline 3\nline 4\nline 5\n" >keep-renamed/F && + git -C keep-renamed add F && + test_tick && + git -C keep-renamed commit -m "O: add F" && + git -C keep-renamed branch B && + git -C keep-renamed mv F G && + test_tick && + git -C keep-renamed commit -m "A1: rename F to G on master" && + + git -C keep-renamed checkout B && + printf "line 1\nline 2\nline 3\nline 4 T\nline 5\n" >keep-renamed/F && + test_tick && + git -C keep-renamed commit -am "B2: update F on B" && + + git -C keep-renamed checkout master && + test_tick && + git -C keep-renamed merge -s ours -m "M: merge B, keep G, drop F" B +' + +test_expect_success '--follow follows an edit on the side the merge did not take' ' + git -C keep-renamed log --follow --pretty=tformat:%s G >actual && + cat >expect <<-\EOF && + B2: update F on B + A1: rename F to G on master + O: add F + EOF + test_cmp expect actual +' + +test_expect_success 'setup merge keeping the copied path, other side edited the original' ' + git init keep-copied && + printf "line 1\nline 2\nline 3\nline 4\nline 5\n" >keep-copied/F && + git -C keep-copied add F && + test_tick && + git -C keep-copied commit -m "O: add F" && + git -C keep-copied branch B && + cp keep-copied/F keep-copied/G && + git -C keep-copied add G && + test_tick && + git -C keep-copied commit -m "A1: copy F to G on master" && + + git -C keep-copied checkout B && + printf "line 1\nline 2\nline 3\nline 4 T\nline 5\n" >keep-copied/F && + test_tick && + git -C keep-copied commit -am "B2: update F on B" && + + git -C keep-copied checkout master && + test_tick && + git -C keep-copied merge -s ours -m "M: merge B, keep F and G" B +' + +test_expect_success '--follow follows an edit of the copy source on the side the merge did not take' ' + git -C keep-copied log --follow --pretty=tformat:%s G >actual && + cat >expect <<-\EOF && + B2: update F on B + A1: copy F to G on master + O: add F + EOF + test_cmp expect actual +' + test_done
-- 2.51.0