Skip to content

Add Merge Support for octopus Strategy#7129

Open
jar-of-salt wants to merge 34 commits intolibgit2:mainfrom
jar-of-salt:merge-octopus
Open

Add Merge Support for octopus Strategy#7129
jar-of-salt wants to merge 34 commits intolibgit2:mainfrom
jar-of-salt:merge-octopus

Conversation

@jar-of-salt
Copy link
Contributor

@jar-of-salt jar-of-salt commented Sep 15, 2025

Motivation

Resolves #5047

Implement the logic found in git-merge-octopus.sh as originally implemented by Junio C Hamano.

Changes

  • merge.c
    • git_merge now supports merging multiple branches using the octopus strategy
    • add compute_base_octopus to verify an initial base exists
    • add git_merge__octopus_fastforward to perform the possible fastforward for the first branch in an octopus
    • add git_merge__octopus_simple to perform the simple merge of each branch in an octopus
    • add merge_annotated_commits_octopus as the octopus variant of merge_annotated_commits

Tests

  • All tests use the tests/resources/merge-octopus repository, and start with t as the HEAD branch
  • Simple case:
    • merge 4 unrelated branches into a target branch
    • verify expected index post-merge
    • command: git merge branch1 branch1-b branch2 branch3
  • Failure case:
    • merge 3 unrelated branches with conflicts
    • verify merge fails with GIT_EMERGECONFLICT aka -24
    • command: git merge f1 f2 f3
  • Complex case:
    • merge several branches with complex history
    • verify expected index post-merge
    • command: git merge 1 1a 1b 2 2a 3 t1 t2
  • Fastforward and Skip case:
    • merge several branches, with the first admitting a fastforward and the second being skippable
    • verify expected index post-merge
    • command: git merge ff skippable 1

Miscellania

This is my first contribution! It was a lot of fun to work through this and see how the project works. Any and all feedback is appreciated!

I am also not sure I credited the original author correctly, so please take a look at that.

PS, sorry for triggering so many CI build actions; next time I will open the PR once I am no longer making as many pushes.

@jar-of-salt jar-of-salt marked this pull request as ready for review September 16, 2025 21:17
…fail.c -> conflict.c to more clearly indicate what the test is for
@jar-of-salt jar-of-salt changed the title Merge octopus Add Merge Support for octopus Strategy Sep 16, 2025
@ethomson ethomson added the v.next label Dec 6, 2025
@ethomson
Copy link
Member

ethomson commented Dec 6, 2025

Wow! This is an exciting PR. It's also very large so I'll need a bit of time to review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git_merge() multiple branches

2 participants