Re: [PATCH v4 6/6] log: fix --follow following an edit on a side the merge did not take
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Nov 6, 2026, 14:14 UTC
- Message-ID
- <au3guSIBfekx7gNL@pks.im>
- In-Reply-To
- <7be8cfb3ba58a4d4dc040fb2f229524599524b78.1793298331.git.vmiklos@collabora.com>
On Fri, Oct 30, 2026 at 09:10:14PM +0100, Miklos Vajna wrote:
Show 19 quoted lines
> Take a history where F is renamed to G on master, F is edited on a side > branch, and the side branch is merged with '-s ours', so the merge keeps > G and drops F. Here 'git log --follow G' doesn't show the edit of F on > the side branch, while it did before the previous commit. > > The problem is that follow_needs_renames() only searches for renames in > a parent without the path if the merge base still has the path, which > covers the case when the parent renamed the path. Here the other side > of the merge did the rename, so the merge base only has the old name. > The parent is then told to follow G, which it doesn't have, and the > history of F on its side is lost. Searching for renames in each parent > that lacks the path would fix this, but that is the expensive search > that the previous commit avoids, e.g. 148 merges hit this case for > include/linux/rsc_table.h in linux.git. > > Fix the problem by also searching for renames when the merge base > doesn't have the path, but the parent changed a file since the merge > base that the merge no longer has: only such a file can be the old name > of the path that still needs to be followed in the parent.
This isn't true though in the case where you copy a file though, is it? E.g. the following test case is exactly the same as the one you add in this commit, but instead of using a rename we use a copy:
diff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh index a85fb78ca28..c67d9481ab5 100755 --- a/t/t4219-log-follow-merge.sh +++ b/t/t4219-log-follow-merge.sh @@ -297,4 +297,36 @@ test_expect_success '--follow follows an edit on the side the merge did not take 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 This test passes on master, but fails with your patch series. Patrick