Re: [PATCH v5 1/5] t4219: test more --follow cases across merges
- From
Justin Tobler <jltobler@gmail.com>
- Date
- Nov 10, 2026, 23:06 UTC
- Message-ID
- <avOWhV09WfNsAptg@jtobler--20250820-SHC54>
- In-Reply-To
- <5512aa682f71243378c06dcb8cda2b53150d4e39.1794078554.git.vmiklos@collabora.com>
On 26/11/09 09:04AM, Miklos Vajna wrote:
Show 16 quoted lines
>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
This explains what tests we are adding, but it doesn't really provide readers with much context as do why they are the expected behaviors.
Show 32 quoted lines
> >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 >+'
Ok IIUC, this test is setting up a repository has manually copied and committed from another repository, but then later merges the unrelated history. It took me a little bit to parse what exactly was going on here. Maybe some comments would be a bit helpful here?
Show 9 quoted lines
>+ >+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 >+'
Ok and here we validate that we follow the file into the now merged unrelated history. I assume that prior to 304812ed33de (log: improve --follow following renames for non-linear history, 2026-06-22), this would not have passed? If so, it might be helpful to more directly mention this in the commit message?
Show 25 quoted lines
>+ > 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
I assume here we are validating that the merge is printed?
Show 41 quoted lines
>+
>+# 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
>+}Ok, because the walk order is based on commiter date, we have a helper function here that can create various test setups to validate we can follow a file through the history.
Show 18 quoted lines
>+ >+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
Ok, so we expect the results to be same the same and the file to be found on both sides here. I realize we are crafting very specific repository histories to validate here, but I must say the test setup here is rather complex IMO.
Show 24 quoted lines
>+ >+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 >+'
Ok, here we are creating a history where a topic modifies and renames a file, but the merge drops these changes. Some comments here might also be helpful for readers.
Show 11 quoted lines
>+ >+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 >+'
We expect that the commits from branch B are still inspected even though the merge dropped them. Makes sense.
Show 12 quoted lines
>+ >+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 >+'
hmmmm, is the expectation here that `--diff-merges=first-parent` doesn't prevent us from visiting commits from the second parent?
Show 21 quoted lines
>+ >+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 >+'
Here the merge keeps master's renamed G and discards branch B's edit to F.
Show 10 quoted lines
>+ >+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 >+'
Commits from both sides along with the original commit are expected. Makes sense.
Show 34 quoted lines
>+ >+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
Ok, these tests are similar to last set, but copied instead of renamed.
-Justin