]> git.ipfire.org Git - thirdparty/git.git/commit
contrib/subtree: fix split with squashed subtrees
authorColin Stagner <ask+git@howdoi.land>
Wed, 10 Sep 2025 03:11:24 +0000 (22:11 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Sep 2025 16:01:15 +0000 (09:01 -0700)
commit83f9dad7d6fb5988b68f80b25bd87c68693195dd
tree1a1293d75c7ae64f706dfb6c2eb4d1455fdea177
parent954d33a9757fcfab723a824116902f1eb16e05f7
contrib/subtree: fix split with squashed subtrees

98ba49ccc2 (subtree: fix split processing with multiple subtrees
present, 2023-12-01) increases the performance of

    git subtree split --prefix=subA

by ignoring subtree merges which are outside of `subA/`. It also
introduces a regression. Subtree merges that should be retained
are incorrectly ignored if they:

1. are nested under `subA/`; and
2. are merged with `--squash`.

For example, a subtree merged like:

    git subtree merge --squash --prefix=subA/subB "$rev"
    #                 ^^^^^^^^          ^^^^

is erroneously ignored during a split of `subA`. This causes
missing tree files and different commit hashes starting in
git v2.44.0-rc0.

The method:

    should_ignore_subtree_split_commit REV

should test only a single commit REV, but the combination of

    git log -1 --grep=...

actually searches all *parent* commits until a `--grep` match is
discovered.

Rewrite this method to test only one REV at a time. Extract commit
information with a single `git` call as opposed to three. The
`test` conditions for rejecting a commit remain unchanged.

Unit tests now cover nested subtrees.

Signed-off-by: Colin Stagner <ask+git@howdoi.land>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/subtree/git-subtree.sh
contrib/subtree/t/t7900-subtree.sh