Repository navigation
merge: add --no-ff flag for merge commit (semi-linear history) - #1438
Conversation
cfb14b3 to
9f83e51
Compare
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI is failing on all platforms with 3 lint issues:
- clippy::collapsible_if —
push.rs:363: the nestedif let Some(wt_path)+if wt_path.exists()should be collapsed intoif let Some(wt_path) = ... && wt_path.exists() - clippy::unnecessary_to_owned —
merge.rs:2480:repo.root_path().to_path_buf()→repo.root_path() - no-manual-ansi pre-commit hook —
push.rs:176: raw\x1bescapes in the doc comment. Rephrase to avoid literal ANSI codes. - cargo fmt — formatting differences
All mechanical fixes. The implementation itself looks good — clean MergeContext refactoring, correct use of commit-tree + update-ref plumbing, TOCTOU-safe ref updates, and thorough test coverage.
|
|
||
| // Make a commit on develop so there's something to merge | ||
| repo.commit_in_worktree( | ||
| &repo.root_path().to_path_buf(), |
There was a problem hiding this comment.
Clippy unnecessary_to_owned: .to_path_buf() is redundant here.
| &repo.root_path().to_path_buf(), | |
| repo.root_path(), |
CI failed — clippy and pre-commit lint errors
|
how much do folks want this? if there is a broad support then OK. but otherwise I would claim that the use case for ...and we want to avoid collecting all the git options in ...and when there's a special circumstance, the plain git commands are there... |
9f83e51 to
cecfa11
Compare
worktrunk-bot
left a comment
There was a problem hiding this comment.
The implementation is solid — clean MergeContext refactoring, correct use of git plumbing (commit-tree + update-ref), TOCTOU-safe ref updates via old-value check, proper stash guard handling on all failure paths, and thorough test coverage across 11 scenarios.
One documentation gap: the [merge] config example in wt config --help (src/cli/mod.rs L1662–1668) lists all merge flags but doesn't mention the new no-ff option. It should include:
no-ff = false # Create a merge commit instead of fast-forwarding (--no-ff)This is outside the diff, so I can push a fix commit if you'd like.
Those are valid concerns. I can't speak for other devs/teams, in my org this is unfortunately a non-negotiable workflow contract. To me, the high appeal of The approach I'm proposing is that this is entirely opt-in: unless the user looks for I'm happy to go the extra mile and make sure this is easy to merge and very maintainable, or otherwise if an issue comes up later I'll still be here and willing to find fixes. I'm also driving adoption into nixpkgs (NixOS/nixpkgs#496607) and am volunteering to maintain it there too. In the meantime, I've reworked the PR to fix test issues and improve testing, will to another run to see if something can be done about the slight drop in coverage. |
07f053e to
5a44fa3
Compare
worktrunk-bot
left a comment
There was a problem hiding this comment.
Clean refactoring and solid implementation. The MergeContext extraction eliminates duplication between the two merge strategies well. The plumbing approach (commit-tree + update-ref with old-value check) is correct — it avoids checking out the target branch and provides TOCTOU safety via the snapshotted target_tip. Parent ordering (target first, feature second) follows git convention, so --first-parent log works as expected. Stash guard auto-restore on error paths is preserved through the Drop impl.
The one prior suggestion (adding no-ff to the [merge] config example in wt config --help) has been addressed in this revision.
In run 22941561692 reviewing PR #1438, the bot approved the PR with a verbose confirmatory review body despite the maintainer having posted a comment questioning whether the feature belongs in the project. The bot should have deferred to human judgment instead of approving. Two issues addressed: 1. Add "maintainer design concerns" as a confidence-decreasing factor 2. Add explicit rule: active maintainer discussion overrides code quality for approval decisions — use +1 reaction instead Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@siriobalmelli OK, I appreciate that, and also would like to reciprocate your contribution to the project... one quick idea (not saying this would be better, but exploring in pursuit of avoiding more config options) — @worktrunk-bot can you assess the idea of a |
|
Interesting idea — I looked at this from a few angles. Why
|
| Option | Applies to | Notes |
|---|---|---|
--signoff / -s |
commits | Adds Signed-off-by trailer. Could apply to squash commit and/or merge commit |
--gpg-sign / -S |
commits | Sign commits. Same scope question as signoff |
--strategy=ort |
rebase | Merge strategy for rebase conflicts. Niche — ort is already the default |
--no-rerere-autoupdate |
rebase | Disable rerere during rebase. Very niche |
The useful ones (--signoff, --gpg-sign) are commit-level options, not merge-level. They'd need routing logic ("apply this to the squash commit, the merge commit, or both?"), which negates the simplicity benefit of a passthrough.
Assessment
A generic git-options config would add complexity (parsing, routing, validation, error messages for invalid combinations) without much payoff — --no-ff can't use it, and the options that could use it are better served as dedicated flags if/when they're needed. The current approach of dedicated flags with config defaults is consistent with how squash/rebase/remove/verify already work, and keeps behavior predictable.
That said, a -- passthrough for the rebase step specifically (wt merge -- --strategy=recursive) could be useful someday, though I'm not aware of demand for it.
I appreciate that. Ironically, this was also my first instinct: let's just honor git options passed by the caller. On closer inspection, my thinking is that the exact value add of BTW I'm running my branch on multiple machines and it's working great. |
|
Agreed — the analysis and @siriobalmelli's point converge on the same conclusion: CI is green across all platforms and codecov passes. The PR is ready whenever you'd like to move forward, @max-sixty. |
|
OK! I notice it's a big diff! Is this because we can't use the "internal" |
|
The diff is ~1500 lines, but the bulk is tests and auto-generated content:
The implementation change in Refactoring: The existing New
This can't use the existing |
Adds the no-ff option to the [merge] config section so users can set no-ff = true in wt.toml to always create merge commits without passing --no-ff on every invocation. Signed-off-by: Sirio Balmelli <sirio@b-ad.ch>
Both fast-forward push and --no-ff merge share the same scaffolding: target resolution, fast-forward check, stash guard, commit counting, and diff stats. Extract this into MergeContext so the two strategies share a single prepare() path and avoid duplicating ~80 lines. handle_no_ff_merge uses git plumbing (commit-tree + update-ref) to create a merge commit on the target branch without checking it out. Since rebase has already run, HEAD's tree is the correct merge result. The target worktree is synced via reset --hard after the ref update. Signed-off-by: Sirio Balmelli <sirio@b-ad.ch>
Adds --no-ff (and hidden --ff override) to the merge subcommand. MergeOptions gains a no_ff field that overrides the config default, following the same flag_pair pattern used by --rebase/--no-rebase. Signed-off-by: Sirio Balmelli <sirio@b-ad.ch>
Covers: basic single-commit --no-ff, multi-commit with --no-squash, squash+no-ff, config-driven no-ff, --ff overriding config, diverged branches with rebase, already-up-to-date, diverged+--no-rebase error path, and target worktree sync after reset --hard. Signed-off-by: Sirio Balmelli <sirio@b-ad.ch>
Signed-off-by: Sirio Balmelli <sirio@b-ad.ch>
…tree Cover three scenarios not exercised by the initial --no-ff test suite: - autostash: non-conflicting dirty files in the target worktree are stashed before the merge commit and restored afterward, with no leftover stash entries - conflict: overlapping dirty files cause a clean failure with no merge commit created and the target file left untouched - no worktree: merge succeeds when the target branch has no checked-out worktree (skips the reset --hard sync step) Signed-off-by: Sirio Balmelli <sirio@b-ad.ch>
…to_date_context Signed-off-by: Sirio Balmelli <sirio@b-ad.ch>
5a44fa3 to
281197d
Compare
|
Rebased onto latest All 1668 tests pass locally (466 unit + 1202 integration). CI should be green once it runs. Happy to address any remaining concerns — is there anything else you'd like changed before merging? @max-sixty |
worktrunk-bot
left a comment
There was a problem hiding this comment.
Solid implementation. The MergeContext refactoring cleanly separates shared scaffolding from the two merge strategies, and the plumbing approach (commit-tree + update-ref with old-value check) is correct. One observation on user-visible error handling.
log::warn! is only visible with RUST_LOG enabled. When reset --hard fails after a --no-ff merge, the user needs to know and act — emit a styled warning_message to stderr so it's always visible. Signed-off-by: Sirio Balmelli <sirio@b-ad.ch>
|
Fixed in the latest commit (
Addresses the review at #1438 (comment). |
|
@max-sixty I'm confident this is ready to merge and will work fine in the long term. All of my workflows internally have been using this for over a week with no trouble. |
|
thanks @siriobalmelli ! |
|
This has already been merged, so maybe you don't need any more feedback, but I have two primary use cases:
So, thank you for merging this. I was afraid my workflow was going to have to entail managing all of this outside of worktrunk. That workflow is scriptable, but I'm glad I don't have to do that. |
Summary
--no-ff/--ffCLI flags towt merge[merge] no-ffconfig option (project and user config)handle_pushinto a reusableMergeContextstruct, eliminating duplication between fast-forward and merge-commit pathscommit-tree+update-ref) without checking out the target branchMotivation
I prefer rebased commits on the feature branch, plus a merge commit on the target.
This is equivalent to GitLab's "Merge commit with semi-linear history" strategy and GitHub's "Create a merge commit" option (after rebasing).
Pipeline behaviour with
--no-ffThe merge pipeline runs identically up through rebase and pre-merge hooks. At the merge step, instead of fast-forwarding the target ref, a merge commit is created:
The target worktree (if present) is then synced via
reset --hard.Config
Override per-invocation with
--ffto force fast-forward even when config saysno-ff = true.Test coverage
11 integration tests covering:
--no-ff--no-ff(no squash)--no-ffwith squash (squash first, then merge commit)--no-fffrom config, with--ffCLI override--no-ffwith rebase (diverged branches)--no-ffalready up to date--no-ffwith diverged branches and--no-rebase(error path)--no-ffsyncs target worktree viareset --hard--no-ffwith non-overlapping dirty target (autostash/restore)--no-ffwith overlapping dirty target (safe failure, no data loss)--no-ffwhen target has no checked-out worktreeNotes
I developed this PR with assistance from AI.