Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
merge: add --no-ff flag for merge commit (semi-linear history) (#1438)
Sirio Balmelli799aab0eb9c8
diff --git a/dev/config.example.toml b/dev/config.example.tomlindex 87ba4212a..a48aaf0c1 100644--- a/dev/config.example.toml+++ b/dev/config.example.toml@@ -91,7 +91,7 @@## ### Merge#-# All flags are on by default. Set to false to change default behavior.+# Most flags are on by default. Set to false to change default behavior.## [merge]# squash = true # Squash commits into one (--no-squash to preserve history)@@ -99,6 +99,7 @@# rebase = true # Rebase onto target before merge (--no-rebase to skip)# remove = true # Remove worktree after merge (--no-remove to keep)# verify = true # Run project hooks (--no-verify to skip)+# no-ff = false # Create a merge commit even when fast-forward is possible (--no-ff)## ### Switch#diff --git a/docs/content/config.md b/docs/content/config.mdindex c21c543f9..36485d5fd 100644--- a/docs/content/config.md+++ b/docs/content/config.md@@ -177,7 +177,7 @@ stage = "all" # What to stage before commit: "all", "tracked", or "none"### Merge-All flags are on by default. Set to false to change default behavior.+Most flags are on by default. Set to false to change default behavior.```toml[merge]@@ -186,6 +186,7 @@ commit = true # Commit uncommitted changes first (--no-commit to skip)rebase = true # Rebase onto target before merge (--no-rebase to skip)remove = true # Remove worktree after merge (--no-remove to keep)verify = true # Run project hooks (--no-verify to skip)+no-ff = false # Create a merge commit even when fast-forward is possible (--no-ff)```### Switchdiff --git a/docs/content/merge.md b/docs/content/merge.mdindex 853ab382b..64161da9a 100644--- a/docs/content/merge.md+++ b/docs/content/merge.md@@ -46,6 +46,12 @@ Preserve commit history (no squash):wt merge --no-squash```+Create a merge commit (semi-linear history):++```bash+wt merge --no-ff+```+Skip committing/squashing (rebase still runs unless --no-rebase):```bash@@ -59,7 +65,7 @@ wt merge --no-commit1. **Squash** — Stages uncommitted changes, then combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. A backup ref is saved to `refs/wt-backup/<branch>`. With `--no-squash`, uncommitted changes become a separate commit and individual commits are preserved.2. **Rebase** — Rebases onto target if behind. Skipped if already up-to-date. Conflicts abort immediately.3. **Pre-merge hooks** — Hooks run after rebase, before merge. Failures abort. See [`wt hook`](@/hook.md).-4. **Merge** — Fast-forward merge to the target branch. Non-fast-forward merges are rejected.+4. **Merge** — Fast-forward merge to the target branch. With `--no-ff`, a merge commit is created instead (semi-linear history: rebased commits plus a merge commit). Non-fast-forward merges are rejected.5. **Pre-remove hooks** — Hooks run before removing worktree. Failures abort.6. **Cleanup** — Removes the worktree and branch. Use `--no-remove` to keep the worktree. When already on the target branch or in the main worktree, the worktree is preserved.7. **Post-merge hooks** — Hooks run after cleanup. Failures are logged but don't abort.@@ -114,6 +120,9 @@ Usage: <b><span class=c>wt merge</span></b> <span class=c>[OPTIONS]</span> <span<b><span class=c>--no-remove</span></b>Keep worktree after merge+ <b><span class=c>--no-ff</span></b>+ Create a merge commit (no fast-forward)+<b><span class=c>--stage</span></b><span class=c> <STAGE></span>What to stage before committing [default: all]diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.mdindex 440fb642b..652e396fd 100644--- a/skills/worktrunk/reference/config.md+++ b/skills/worktrunk/reference/config.md@@ -168,7 +168,7 @@ stage = "all" # What to stage before commit: "all", "tracked", or "none"### Merge-All flags are on by default. Set to false to change default behavior.+Most flags are on by default. Set to false to change default behavior.```toml[merge]@@ -177,6 +177,7 @@ commit = true # Commit uncommitted changes first (--no-commit to skip)rebase = true # Rebase onto target before merge (--no-rebase to skip)remove = true # Remove worktree after merge (--no-remove to keep)verify = true # Run project hooks (--no-verify to skip)+no-ff = false # Create a merge commit even when fast-forward is possible (--no-ff)```### Switchdiff --git a/skills/worktrunk/reference/merge.md b/skills/worktrunk/reference/merge.mdindex 01a47354a..fd2540b2c 100644--- a/skills/worktrunk/reference/merge.md+++ b/skills/worktrunk/reference/merge.md@@ -30,6 +30,12 @@ Preserve commit history (no squash):wt merge --no-squash```+Create a merge commit (semi-linear history):++```bash+wt merge --no-ff+```+Skip committing/squashing (rebase still runs unless --no-rebase):```bash@@ -43,7 +49,7 @@ wt merge --no-commit1. **Squash** — Stages uncommitted changes, then combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. A backup ref is saved to `refs/wt-backup/<branch>`. With `--no-squash`, uncommitted changes become a separate commit and individual commits are preserved.2. **Rebase** — Rebases onto target if behind. Skipped if already up-to-date. Conflicts abort immediately.3. **Pre-merge hooks** — Hooks run after rebase, before merge. Failures abort. See [`wt hook`](https://worktrunk.dev/hook/).-4. **Merge** — Fast-forward merge to the target branch. Non-fast-forward merges are rejected.+4. **Merge** — Fast-forward merge to the target branch. With `--no-ff`, a merge commit is created instead (semi-linear history: rebased commits plus a merge commit). Non-fast-forward merges are rejected.5. **Pre-remove hooks** — Hooks run before removing worktree. Failures abort.6. **Cleanup** — Removes the worktree and branch. Use `--no-remove` to keep the worktree. When already on the target branch or in the main worktree, the worktree is preserved.7. **Post-merge hooks** — Hooks run after cleanup. Failures are logged but don't abort.@@ -91,6 +97,9 @@ Usage: <b><span class=c>wt merge</span></b> <span class=c>[OPTIONS]</span> <span<b><span class=c>--no-remove</span></b>Keep worktree after merge+ <b><span class=c>--no-ff</span></b>+ Create a merge commit (no fast-forward)+<b><span class=c>--stage</span></b><span class=c> <STAGE></span>What to stage before committing [default: all]diff --git a/src/cli/mod.rs b/src/cli/mod.rsindex f6df4a890..93de92eee 100644--- a/src/cli/mod.rs+++ b/src/cli/mod.rs@@ -889,6 +889,12 @@ Preserve commit history (no squash):wt merge --no-squash```+Create a merge commit (semi-linear history):++```console+wt merge --no-ff+```+Skip committing/squashing (rebase still runs unless --no-rebase):```console@@ -902,7 +908,7 @@ wt merge --no-commit1. **Squash** — Stages uncommitted changes, then combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. A backup ref is saved to `refs/wt-backup/<branch>`. With `--no-squash`, uncommitted changes become a separate commit and individual commits are preserved.2. **Rebase** — Rebases onto target if behind. Skipped if already up-to-date. Conflicts abort immediately.3. **Pre-merge hooks** — Hooks run after rebase, before merge. Failures abort. See [`wt hook`](@/hook.md).-4. **Merge** — Fast-forward merge to the target branch. Non-fast-forward merges are rejected.+4. **Merge** — Fast-forward merge to the target branch. With `--no-ff`, a merge commit is created instead (semi-linear history: rebased commits plus a merge commit). Non-fast-forward merges are rejected.5. **Pre-remove hooks** — Hooks run before removing worktree. Failures abort.6. **Cleanup** — Removes the worktree and branch. Use `--no-remove` to keep the worktree. When already on the target branch or in the main worktree, the worktree is preserved.7. **Post-merge hooks** — Hooks run after cleanup. Failures are logged but don't abort.@@ -969,6 +975,14 @@ lint = "cargo clippy"#[arg(long = "no-remove", overrides_with = "remove")]no_remove: bool,+ /// Create a merge commit (no fast-forward)+ #[arg(long = "no-ff", overrides_with = "ff")]+ no_ff: bool,++ /// Allow fast-forward (default)+ #[arg(long, overrides_with = "no_ff", hide = true)]+ ff: bool,+/// Skip approval prompts#[arg(short, long, help_heading = "Automation")]yes: bool,@@ -1688,7 +1702,7 @@ stage = "all" # What to stage before commit: "all", "tracked", or "none"### Merge-All flags are on by default. Set to false to change default behavior.+Most flags are on by default. Set to false to change default behavior.```toml[merge]@@ -1697,6 +1711,7 @@ commit = true # Commit uncommitted changes first (--no-commit to skip)rebase = true # Rebase onto target before merge (--no-rebase to skip)remove = true # Remove worktree after merge (--no-remove to keep)verify = true # Run project hooks (--no-verify to skip)+no-ff = false # Create a merge commit even when fast-forward is possible (--no-ff)```### Switchdiff --git a/src/commands/merge.rs b/src/commands/merge.rsindex ca376263d..dab88a230 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -12,7 +12,8 @@ use super::hooks::{HookFailureStrategy, execute_hook};use super::project_config::{ApprovableCommand, collect_commands_for_hooks};use super::repository_ext::RepositoryCliExt;use super::worktree::{- BranchDeletionMode, MergeOperations, RemoveResult, get_path_mismatch, handle_push,+ BranchDeletionMode, MergeOperations, RemoveResult, get_path_mismatch, handle_no_ff_merge,+ handle_push,};/// Options for the merge command@@ -29,6 +30,8 @@ pub struct MergeOptions<'a> {pub rebase: Option<bool>,/// CLI override for remove. None = use effective config default.pub remove: Option<bool>,+ /// CLI override for no-ff. None = use effective config default.+ pub no_ff: Option<bool>,/// CLI override for verify. None = use effective config default.pub verify: Option<bool>,pub yes: bool,@@ -83,6 +86,7 @@ pub fn handle_merge(opts: MergeOptions<'_>) -> anyhow::Result<()> {commit: commit_opt,rebase: rebase_opt,remove: remove_opt,+ no_ff: no_ff_opt,verify: verify_opt,yes,stage,@@ -109,6 +113,7 @@ pub fn handle_merge(opts: MergeOptions<'_>) -> anyhow::Result<()> {let commit = commit_opt.unwrap_or(resolved.merge.commit());let rebase = rebase_opt.unwrap_or(resolved.merge.rebase());let remove = remove_opt.unwrap_or(resolved.merge.remove());+ let no_ff = no_ff_opt.unwrap_or(resolved.merge.no_ff());let verify = verify_opt.unwrap_or(resolved.merge.verify());let stage_mode = stage.unwrap_or(resolved.commit.stage());@@ -219,16 +224,19 @@ pub fn handle_merge(opts: MergeOptions<'_>) -> anyhow::Result<()> {)?;}- // Fast-forward push to target branch with commit/squash/rebase info for consolidated message- handle_push(- Some(&target_branch),- "Merged to",- Some(MergeOperations {- committed,- squashed,- rebased,- }),- )?;+ // Merge to target branch+ let operations = Some(MergeOperations {+ committed,+ squashed,+ rebased,+ });+ if no_ff {+ // Create a merge commit on the target branch via commit-tree + update-ref+ handle_no_ff_merge(Some(&target_branch), operations, ¤t_branch)?;+ } else {+ // Fast-forward push to target branch+ handle_push(Some(&target_branch), "Merged to", operations)?;+ }// Destination: prefer the target branch's worktree; fall back to home path.let destination_path = match target_worktree_path {diff --git a/src/commands/worktree/mod.rs b/src/commands/worktree/mod.rsindex 8d17cacc2..b5769a002 100644--- a/src/commands/worktree/mod.rs+++ b/src/commands/worktree/mod.rs@@ -86,7 +86,7 @@ mod switch;mod types;// Re-export public types and functions-pub use push::handle_push;+pub use push::{handle_no_ff_merge, handle_push};pub use remove::{handle_remove, handle_remove_current};pub(crate) use resolve::paths_match;pub use resolve::{diff --git a/src/commands/worktree/push.rs b/src/commands/worktree/push.rsindex fa574f729..1af5b0342 100644--- a/src/commands/worktree/push.rs+++ b/src/commands/worktree/push.rs@@ -1,211 +1,484 @@//! Worktree push operations.//!-//! Push changes to target branch with safety checks.+//! Push changes to target branch with safety checks. Both fast-forward push and+//! `--no-ff` merge share common scaffolding (target resolution, fast-forward check,+//! stash guard, progress/success output) extracted into [`MergeContext`].+use std::path::PathBuf;++use anyhow::Context;use color_print::cformat;use worktrunk::git::{GitError, Repository};use worktrunk::styling::{- eprintln, format_with_gutter, info_message, progress_message, success_message,+ eprintln, format_with_gutter, info_message, progress_message, success_message, warning_message,};use super::types::MergeOperations;-use crate::commands::repository_ext::RepositoryCliExt;+use crate::commands::repository_ext::{RepositoryCliExt, TargetWorktreeStash};-/// Push changes to target branch-///-/// The `operations` parameter indicates which merge operations occurred (commit, squash, rebase).-/// Pass `None` for standalone push operations where these concepts don't apply.+// ---------------------------------------------------------------------------+// Shared scaffolding+// ---------------------------------------------------------------------------++/// Pre-computed state shared by both fast-forward push and `--no-ff` merge.///-/// During the push stage we temporarily `git stash` non-overlapping changes in the-/// target worktree (if present) so that concurrent edits there do not block the-/// fast-forward. The stash is restored afterward and we bail out early if any file-/// overlaps with the push range.-pub fn handle_push(- target: Option<&str>,- verb: &str,- operations: Option<MergeOperations>,-) -> anyhow::Result<()> {- let repo = Repository::current()?;-- // Get and validate target branch (must be a branch since we're updating it)- let target_branch = repo.require_target_branch(target)?;-- // A worktree for the target branch is optional for push:- // - If present, we use it to check for overlapping dirty files.- // - If absent, we skip that safety step but still allow the push (git itself is fine).- let target_worktree_path = repo.worktree_for_branch(&target_branch)?;-- // Check if it's a fast-forward- if !repo.is_ancestor(&target_branch, "HEAD")? {- // Get formatted commit log (commits in target that we don't have)- let commits_formatted = repo- .run_command(&[- "log",- "--color=always",- "--graph",- "--oneline",- &format!("HEAD..{}", target_branch),- ])?+/// Created by [`MergeContext::prepare`], which resolves the target branch,+/// verifies fast-forward, sets up the stash guard, counts commits, and captures+/// diff statistics — all steps that are identical between the two strategies.+struct MergeContext {+ repo: Repository,+ target_branch: String,+ target_worktree_path: Option<PathBuf>,+ /// Snapshotted target SHA for TOCTOU-safe ref updates.+ target_tip: String,+ stash_guard: Option<TargetWorktreeStash>,+ commit_count: usize,+ stats_summary: Vec<String>,+}++impl MergeContext {+ /// Resolve target, verify fast-forward, stash guard, count commits, capture stats.+ fn prepare(target: Option<&str>, operations: Option<MergeOperations>) -> anyhow::Result<Self> {+ let repo = Repository::current()?;++ let target_branch = repo.require_target_branch(target)?;+ let target_worktree_path = repo.worktree_for_branch(&target_branch)?;++ // Snapshot target SHA early for TOCTOU safety (used by both strategies+ // for the fast-forward check; --no-ff also uses it for update-ref).+ let target_ref = format!("refs/heads/{}", target_branch);+ let target_tip = repo+ .run_command(&["rev-parse", &target_ref])?.trim().to_string();- return Err(GitError::NotFastForward {- target_branch: target_branch.clone(),- commits_formatted,- in_merge_context: operations.is_some(),- }- .into());- }+ // Fast-forward check (target must be ancestor of HEAD)+ if !repo.is_ancestor(&target_tip, "HEAD")? {+ let commits_formatted = repo+ .run_command(&[+ "log",+ "--color=always",+ "--graph",+ "--oneline",+ &format!("HEAD..{}", target_tip),+ ])?+ .trim()+ .to_string();- // Check for conflicting changes in target worktree (auto-stash safe changes)- // The stash guard auto-restores on drop (error paths), or explicitly via restore_now()- let mut stash_guard =- repo.prepare_target_worktree(target_worktree_path.as_ref(), &target_branch)?;+ return Err(GitError::NotFastForward {+ target_branch: target_branch.clone(),+ commits_formatted,+ in_merge_context: operations.is_some(),+ }+ .into());+ }- // Count commits and show what will be pushed- let commit_count = repo.count_commits(&target_branch, "HEAD")?;+ // Auto-stash non-overlapping changes in target worktree+ let stash_guard =+ repo.prepare_target_worktree(target_worktree_path.as_ref(), &target_branch)?;- // Get diff statistics BEFORE push (will be needed for success message later)- let stats_summary = if commit_count > 0 {- repo.diff_stats_summary(&["diff", "--shortstat", &format!("{}..HEAD", target_branch)])- } else {- Vec::new()- };-- // Build and show consolidated message with squash/rebase info- if commit_count > 0 {- let commit_text = if commit_count == 1 {- "commit"- } else {- "commits"- };- let head_sha = repo.run_command(&["rev-parse", "--short", "HEAD"])?;- let head_sha = head_sha.trim();+ let commit_count = repo.count_commits(&target_branch, "HEAD")?;- let verb_ing = if verb.starts_with("Merged") {- "Merging"+ let stats_summary = if commit_count > 0 {+ repo.diff_stats_summary(&["diff", "--shortstat", &format!("{}..HEAD", target_branch)])} else {- "Pushing"+ Vec::new()};- // Build parenthetical showing which operations didn't happen and flags used- let mut notes = Vec::new();+ Ok(Self {+ repo,+ target_branch,+ target_worktree_path,+ target_tip,+ stash_guard,+ commit_count,+ stats_summary,+ })+ }- // Skipped operations - only include if we're in merge workflow context- if let Some(ops) = operations {- let mut skipped_ops = Vec::new();- if !ops.committed && !ops.squashed {- // Neither commit nor squash happened - combine them- skipped_ops.push("commit/squash");- }- if !ops.rebased {- skipped_ops.push("rebase");- }- if !skipped_ops.is_empty() {- notes.push(format!("no {} needed", skipped_ops.join("/")));- }+ /// Print progress message, commit graph, and diff statistics.+ ///+ /// `verb_ing` is the gerund shown in the progress line (e.g. "Merging", "Pushing").+ /// `extra_note` is appended after the SHA (e.g. " (--no-ff)").+ fn show_progress(+ &self,+ verb_ing: &str,+ extra_note: &str,+ operations: Option<MergeOperations>,+ ) -> anyhow::Result<()> {+ if self.commit_count == 0 {+ return Ok(());}- let operations_note = if notes.is_empty() {- String::new()+ let commit_text = if self.commit_count == 1 {+ "commit"} else {- format!(" ({})", notes.join(", "))+ "commits"};+ let head_sha = self.repo.run_command(&["rev-parse", "--short", "HEAD"])?;+ let head_sha = head_sha.trim();++ let operations_note = format_operations_note(operations);eprintln!("{}",progress_message(cformat!(- "{verb_ing} {commit_count} {commit_text} to <bold>{target_branch}</> @ <dim>{head_sha}</>{operations_note}"+ "{verb_ing} {} {commit_text} to <bold>{}</> @ <dim>{head_sha}</>{extra_note}{operations_note}",+ self.commit_count,+ self.target_branch,)));- // Show the commit graph with color- let log_output = repo.run_command(&[+ // Commit graph+ let log_output = self.repo.run_command(&["log","--color=always","--graph","--oneline",- &format!("{}..HEAD", target_branch),+ &format!("{}..HEAD", self.target_branch),])?;eprintln!("{}", format_with_gutter(&log_output, None));- // Show diff statistics- crate::commands::show_diffstat(&repo, &format!("{}..HEAD", target_branch))?;- }+ // Diff statistics+ crate::commands::show_diffstat(&self.repo, &format!("{}..HEAD", self.target_branch))?;- // Get git common dir for the push- let git_common_dir = repo.git_common_dir();- let git_common_dir_str = git_common_dir.to_string_lossy();+ Ok(())+ }- // Perform the push - stash guard will auto-restore on any exit path- // Use --receive-pack to pass config to the receiving end without permanently mutating repo config- let push_target = format!("HEAD:{}", target_branch);- repo.run_command(&[- "push",- "--receive-pack=git -c receive.denyCurrentBranch=updateInstead receive-pack",- git_common_dir_str.as_ref(),- &push_target,- ])- .map_err(|e| {- // CommandFailed contains raw git output, wrap in PushFailed for proper formatting- GitError::PushFailed {- target_branch: target_branch.clone(),- error: e.to_string(),+ /// Print "Already up to date" info message and return `true` if commit_count == 0.+ fn show_up_to_date_if_needed(&self, operations: Option<MergeOperations>) -> bool {+ if self.commit_count > 0 {+ return false;}- })?;- // Restore stash before success message (Drop handles error paths automatically)- if let Some(guard) = stash_guard.as_mut() {- guard.restore_now();+ let context = format_up_to_date_context(operations);+ eprintln!(+ "{}",+ info_message(cformat!(+ "Already up to date with <bold>{}</>{context}",+ self.target_branch,+ ))+ );+ true+ }++ /// Explicitly restore the stash guard (before success message).+ fn restore_stash(&mut self) {+ if let Some(guard) = self.stash_guard.as_mut() {+ guard.restore_now();+ }}- // Show success message after push completes- if commit_count > 0 {- // Use the diff statistics captured earlier (before push)+ /// Print success message with commit/file stats.+ ///+ /// `verb` is the past-tense action (e.g. "Merged to", "Pushed to").+ /// `sha_suffix` is an optional pre-formatted ANSI string shown after the branch+ /// (e.g. ` @ <dim>a1b2c3d</>`). Use `cformat!` at the call site.+ /// `extra_stats` are appended inside the stats parentheses (e.g. ", --no-ff").+ fn show_success(&self, verb: &str, sha_suffix: &str, extra_stats: &str) {let mut summary_parts = vec![format!("{} commit{}",- commit_count,- if commit_count == 1 { "" } else { "s" }+ self.commit_count,+ if self.commit_count == 1 { "" } else { "s" })];- summary_parts.extend(stats_summary);+ summary_parts.extend(self.stats_summary.clone());- // Re-apply bright-black after stats (which end with a reset) so ) is also graylet stats_str = summary_parts.join(", ");+ let target_branch = &self.target_branch;let paren_close = cformat!("<bright-black>)</>"); // Separate to avoid cformat optimizationeprintln!("{}",success_message(cformat!(- "{verb} <bold>{target_branch}</> <bright-black>({stats_str}</>{}",- paren_close+ "{verb} <bold>{target_branch}</>{sha_suffix} <bright-black>({stats_str}{extra_stats}</>{paren_close}",)));+ }+}++/// Format the "(no commit/squash/rebase needed)" parenthetical for progress messages.+fn format_operations_note(operations: Option<MergeOperations>) -> String {+ let Some(ops) = operations else {+ return String::new();+ };+ let mut skipped = Vec::new();+ if !ops.committed && !ops.squashed {+ skipped.push("commit/squash");+ }+ if !ops.rebased {+ skipped.push("rebase");+ }+ if skipped.is_empty() {+ String::new()} else {- // For merge workflow context, explain why nothing was pushed- let context = if let Some(ops) = operations {- let mut notes = Vec::new();- if !ops.committed && !ops.squashed {- notes.push("no new commits");- }- if !ops.rebased {- notes.push("no rebase needed");- }- if notes.is_empty() {- String::new()- } else {- format!(" ({})", notes.join(", "))- }- } else {- String::new()- };+ format!(" (no {} needed)", skipped.join("/"))+ }+}- // No action: nothing was pushed, just acknowledging state- eprintln!(- "{}",- info_message(cformat!(- "Already up to date with <bold>{target_branch}</>{context}"- ))- );+/// Format the context string for "Already up to date" messages.+fn format_up_to_date_context(operations: Option<MergeOperations>) -> String {+ let Some(ops) = operations else {+ return String::new();+ };+ let mut notes = Vec::new();+ if !ops.committed && !ops.squashed {+ notes.push("no new commits");+ }+ if !ops.rebased {+ notes.push("no rebase needed");+ }+ if notes.is_empty() {+ String::new()+ } else {+ format!(" ({})", notes.join(", "))+ }+}++// ---------------------------------------------------------------------------+// Fast-forward push+// ---------------------------------------------------------------------------++/// Push changes to target branch+///+/// The `operations` parameter indicates which merge operations occurred (commit, squash, rebase).+/// Pass `None` for standalone push operations where these concepts don't apply.+///+/// During the push stage we temporarily `git stash` non-overlapping changes in the+/// target worktree (if present) so that concurrent edits there do not block the+/// fast-forward. The stash is restored afterward and we bail out early if any file+/// overlaps with the push range.+pub fn handle_push(+ target: Option<&str>,+ verb: &str,+ operations: Option<MergeOperations>,+) -> anyhow::Result<()> {+ let mut ctx = MergeContext::prepare(target, operations)?;++ let verb_ing = if verb.starts_with("Merged") {+ "Merging"+ } else {+ "Pushing"+ };+ ctx.show_progress(verb_ing, "", operations)?;++ // Perform the push via --receive-pack (atomically updates ref + working tree)+ let git_common_dir = ctx.repo.git_common_dir();+ let git_common_dir_str = git_common_dir.to_string_lossy();+ let push_target = format!("HEAD:{}", ctx.target_branch);++ ctx.repo+ .run_command(&[+ "push",+ "--receive-pack=git -c receive.denyCurrentBranch=updateInstead receive-pack",+ git_common_dir_str.as_ref(),+ &push_target,+ ])+ .map_err(|e| GitError::PushFailed {+ target_branch: ctx.target_branch.clone(),+ error: e.to_string(),+ })?;++ ctx.restore_stash();++ if ctx.commit_count > 0 {+ ctx.show_success(verb, "", "");+ } else {+ ctx.show_up_to_date_if_needed(operations);+ }++ Ok(())+}++// ---------------------------------------------------------------------------+// No-fast-forward merge+// ---------------------------------------------------------------------------++/// Merge to target branch using `--no-ff` (creates a merge commit).+///+/// Uses git plumbing (`commit-tree` + `update-ref`) to create a merge commit+/// on the target branch without needing to check it out. This is safe because+/// rebase has already run, so the feature branch tree IS the correct merge result.+///+/// If the target branch has a checked-out worktree, its working tree is synced+/// via `reset --hard` after the ref update. The stash guard pattern from+/// `handle_push` is reused for dirty target worktrees.+pub fn handle_no_ff_merge(+ target: Option<&str>,+ operations: Option<MergeOperations>,+ feature_branch: &str,+) -> anyhow::Result<()> {+ let mut ctx = MergeContext::prepare(target, operations)?;++ ctx.show_progress("Merging", " (--no-ff)", operations)?;++ if ctx.show_up_to_date_if_needed(operations) {+ return Ok(());}+ // Create the merge commit using git plumbing.+ // Since rebase has already run, HEAD's tree is the correct merge result.+ let tree = ctx+ .repo+ .run_command(&["rev-parse", "HEAD^{tree}"])?+ .trim()+ .to_string();++ let feature_tip = ctx+ .repo+ .run_command(&["rev-parse", "HEAD"])?+ .trim()+ .to_string();++ let merge_message = format!(+ "Merge branch '{}' into {}",+ feature_branch, ctx.target_branch+ );++ let merge_sha = ctx+ .repo+ .run_command(&[+ "commit-tree",+ &tree,+ "-p",+ &ctx.target_tip,+ "-p",+ &feature_tip,+ "-m",+ &merge_message,+ ])+ .context("Failed to create merge commit")?+ .trim()+ .to_string();++ // Atomically update the target branch ref (with old-value check for safety)+ let target_ref = format!("refs/heads/{}", ctx.target_branch);+ ctx.repo+ .run_command(&["update-ref", &target_ref, &merge_sha, &ctx.target_tip])+ .map_err(|e| GitError::PushFailed {+ target_branch: ctx.target_branch.clone(),+ error: format!("Failed to update ref: {e}"),+ })?;++ // Sync the target worktree's working tree if it exists.+ // The merge is already done (ref updated), so treat sync failure as a warning.+ if let Some(wt_path) = &ctx.target_worktree_path+ && wt_path.exists()+ {+ let target_wt = ctx.repo.worktree_at(wt_path);+ if let Err(e) = target_wt.run_command(&["reset", "--hard", "HEAD"]) {+ eprintln!(+ "{}",+ warning_message(cformat!(+ "Failed to sync target worktree; run <bold>git -C {} reset --hard HEAD</> manually",+ worktrunk::path::format_path_for_display(wt_path)+ ))+ );+ log::warn!("Failed to sync target worktree: {e}");+ }+ }++ ctx.restore_stash();++ let merge_sha_short = &merge_sha[..merge_sha.len().min(7)];+ let sha_suffix = cformat!(" @ <dim>{merge_sha_short}</>");+ ctx.show_success("Merged to", &sha_suffix, ", --no-ff");+Ok(())}++#[cfg(test)]+mod tests {+ use super::*;+ use crate::commands::worktree::types::MergeOperations;++ #[test]+ fn test_format_operations_note() {+ // None → empty+ assert_eq!(format_operations_note(None), "");++ // All operations happened → empty (nothing skipped)+ assert_eq!(+ format_operations_note(Some(MergeOperations {+ committed: true,+ squashed: true,+ rebased: true,+ })),+ ""+ );++ // Nothing happened → both skipped+ assert_eq!(+ format_operations_note(Some(MergeOperations {+ committed: false,+ squashed: false,+ rebased: false,+ })),+ " (no commit/squash/rebase needed)"+ );++ // Only rebase skipped+ assert_eq!(+ format_operations_note(Some(MergeOperations {+ committed: true,+ squashed: false,+ rebased: false,+ })),+ " (no rebase needed)"+ );++ // Only commit/squash skipped+ assert_eq!(+ format_operations_note(Some(MergeOperations {+ committed: false,+ squashed: false,+ rebased: true,+ })),+ " (no commit/squash needed)"+ );+ }++ #[test]+ fn test_format_up_to_date_context() {+ // None → empty+ assert_eq!(format_up_to_date_context(None), "");++ // All operations happened → empty+ assert_eq!(+ format_up_to_date_context(Some(MergeOperations {+ committed: true,+ squashed: true,+ rebased: true,+ })),+ ""+ );++ // Nothing happened → both noted+ assert_eq!(+ format_up_to_date_context(Some(MergeOperations {+ committed: false,+ squashed: false,+ rebased: false,+ })),+ " (no new commits, no rebase needed)"+ );++ // Only rebase not needed+ assert_eq!(+ format_up_to_date_context(Some(MergeOperations {+ committed: true,+ squashed: false,+ rebased: false,+ })),+ " (no rebase needed)"+ );++ // Only no new commits+ assert_eq!(+ format_up_to_date_context(Some(MergeOperations {+ committed: false,+ squashed: false,+ rebased: true,+ })),+ " (no new commits)"+ );+ }+}diff --git a/src/config/user/sections.rs b/src/config/user/sections.rsindex 868871bab..457ac5af5 100644--- a/src/config/user/sections.rs+++ b/src/config/user/sections.rs@@ -265,6 +265,10 @@ pub struct MergeConfig {/// Run project hooks (default: true)#[serde(skip_serializing_if = "Option::is_none")]pub verify: Option<bool>,++ /// Create a merge commit instead of fast-forwarding (default: false)+ #[serde(rename = "no-ff", skip_serializing_if = "Option::is_none")]+ pub no_ff: Option<bool>,}impl MergeConfig {@@ -292,6 +296,11 @@ impl MergeConfig {pub fn verify(&self) -> bool {self.verify.unwrap_or(true)}++ /// Create a merge commit instead of fast-forwarding (default: false)+ pub fn no_ff(&self) -> bool {+ self.no_ff.unwrap_or(false)+ }}impl Merge for MergeConfig {@@ -302,6 +311,7 @@ impl Merge for MergeConfig {rebase: other.rebase.or(self.rebase),remove: other.remove.or(self.remove),verify: other.verify.or(self.verify),+ no_ff: other.no_ff.or(self.no_ff),}}}diff --git a/src/config/user/tests.rs b/src/config/user/tests.rsindex a6ecc39dd..cdb7a6fb4 100644--- a/src/config/user/tests.rs+++ b/src/config/user/tests.rs@@ -458,6 +458,7 @@ fn test_merge_config_serde() {rebase: Some(false),remove: Some(true),verify: Some(true),+ no_ff: None,};let json = serde_json::to_string(&config).unwrap();let parsed: MergeConfig = serde_json::from_str(&json).unwrap();@@ -639,6 +640,7 @@ fn test_merge_merge_config() {rebase: Some(true),remove: Some(true),verify: Some(true),+ no_ff: Some(false),};let override_config = MergeConfig {squash: Some(false), // Override@@ -646,6 +648,7 @@ fn test_merge_merge_config() {rebase: None, // Fall back to baseremove: Some(false), // Overrideverify: None, // Fall back to base+ no_ff: Some(true), // Override};let merged = base.merge_with(&override_config);@@ -654,6 +657,7 @@ fn test_merge_merge_config() {assert_eq!(merged.rebase, Some(true));assert_eq!(merged.remove, Some(false));assert_eq!(merged.verify, Some(true));+ assert_eq!(merged.no_ff, Some(true));}#[test]@@ -837,6 +841,7 @@ fn test_effective_merge_with_partial_override() {rebase: Some(true),remove: Some(true),verify: Some(true),+ no_ff: Some(false),}),..Default::default()},@@ -853,6 +858,7 @@ fn test_effective_merge_with_partial_override() {rebase: None,remove: None,verify: None,+ no_ff: None,}),..Default::default()},@@ -992,12 +998,13 @@ fn test_list_config_accessor_methods_with_values() {#[test]fn test_merge_config_accessor_methods_defaults() {let config = MergeConfig::default();- // MergeConfig defaults are all true+ // MergeConfig defaults are all true except no_ff (false)assert!(config.squash());assert!(config.commit());assert!(config.rebase());assert!(config.remove());assert!(config.verify());+ assert!(!config.no_ff());}#[test]@@ -1008,12 +1015,14 @@ fn test_merge_config_accessor_methods_with_values() {rebase: Some(false),remove: Some(false),verify: Some(false),+ no_ff: Some(true),};assert!(!config.squash());assert!(!config.commit());assert!(!config.rebase());assert!(!config.remove());assert!(!config.verify());+ assert!(config.no_ff());}#[test]diff --git a/src/main.rs b/src/main.rsindex 8a779be54..548f050cf 100644--- a/src/main.rs+++ b/src/main.rs@@ -961,6 +961,8 @@ fn main() {no_rebase,remove,no_remove,+ no_ff,+ ff,verify,no_verify,yes,@@ -971,6 +973,7 @@ fn main() {commit: flag_pair(commit, no_commit),rebase: flag_pair(rebase, no_rebase),remove: flag_pair(remove, no_remove),+ no_ff: flag_pair(no_ff, ff),verify: flag_pair(verify, no_verify),yes,stage,diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 438fd7a8a..73ea8cde2 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -2685,8 +2685,14 @@ fn setup_snapshot_settings_for_paths_with_home(r"/var/folders/[^/]+/[^/]+/T/\.[^/]+/[^)'\s\x1b]+","[PROJECT_ID]",);+ // macOS nix-shell: /private/tmp/nix-shell.XXX/.tmpYYY/path -> [PROJECT_ID]+ settings.add_filter(+ r"/private/tmp/(?:[^/]+/)*\.tmp[^/]+/[^)'\s\x1b]+",+ "[PROJECT_ID]",+ );// Linux: /tmp/.tmpXXXXXX/path -> [PROJECT_ID]- settings.add_filter(r"/tmp/\.tmp[^/]+/[^)'\s\x1b]+", "[PROJECT_ID]");+ // Also handles nix-shell: /tmp/nix-shell.XXX/.tmpYYY/path+ settings.add_filter(r"/tmp/(?:[^/]+/)*\.tmp[^/]+/[^)'\s\x1b]+", "[PROJECT_ID]");// Windows: C:/Users/user/AppData/Local/Temp/.tmpXXXXXX/path -> [PROJECT_ID]// Handles Windows temp paths with drive letters (after backslash normalization)settings.add_filter(@@ -2756,7 +2762,7 @@ fn setup_snapshot_settings_for_paths_with_home(// - Linux (dash): "sh: 1: nonexistent-command: not found"// Normalize to a consistent formatsettings.add_filter(- r"(?:/usr/bin/bash: line \d+|sh|bash)(?:: \d+)?: ([^:]+): (?:command )?not found",+ r"(?:/usr/bin/bash: line \d+|sh(?:: line \d+)?|bash)(?:: \d+)?: ([^:]+): (?:command )?not found","sh: $1: command not found",);diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex 087a68366..1c12836d5 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -2089,3 +2089,416 @@ fn test_merge_squash_ignored_with_no_commit(repo_with_multi_commit_feature: TestSome(feature_wt)));}++// =============================================================================+// --no-ff merge (creates merge commit via commit-tree)+// =============================================================================++/// Basic --no-ff merge: single commit on feature, creates a merge commit on target.+#[rstest]+fn test_merge_no_ff_basic(merge_scenario: (TestRepo, PathBuf)) {+ let (repo, feature_wt) = merge_scenario;++ // Merge with --no-ff and --no-remove so we can inspect the result+ assert_cmd_snapshot!(make_snapshot_cmd(+ &repo,+ "merge",+ &["main", "--no-ff", "--no-remove"],+ Some(&feature_wt)+ ));++ // Verify a merge commit was created (HEAD on main should have 2 parents)+ let parent_count = repo.git_output(&["cat-file", "-p", "main"]);+ let parents: Vec<&str> = parent_count+ .lines()+ .filter(|l| l.starts_with("parent "))+ .collect();+ assert_eq!(+ parents.len(),+ 2,+ "Merge commit should have exactly 2 parents"+ );++ // Verify the merge commit message+ let commit_msg = repo.git_output(&["log", "-1", "--format=%s", "main"]);+ assert_eq!(commit_msg, "Merge branch 'feature' into main");+}++/// --no-ff merge with multiple commits (no squash): all commits preserved plus merge commit.+#[rstest]+fn test_merge_no_ff_multi_commit(repo_with_multi_commit_feature: TestRepo) {+ let repo = &repo_with_multi_commit_feature;+ let feature_wt = &repo.worktrees["feature"];++ assert_cmd_snapshot!(make_snapshot_cmd(+ repo,+ "merge",+ &["main", "--no-ff", "--no-squash", "--no-remove"],+ Some(feature_wt)+ ));++ // Verify merge commit has 2 parents+ let parent_count = repo.git_output(&["cat-file", "-p", "main"]);+ let parents: Vec<&str> = parent_count+ .lines()+ .filter(|l| l.starts_with("parent "))+ .collect();+ assert_eq!(+ parents.len(),+ 2,+ "Merge commit should have exactly 2 parents"+ );++ // Verify individual commits are preserved (3 commits on main: initial + merge,+ // with 2 feature commits reachable via second parent)+ let log = repo.git_output(&["log", "--oneline", "--graph", "main"]);+ assert!(log.contains("Merge branch"), "Should contain merge commit");+}++/// --no-ff merge with squash: squash first, then merge commit wrapping single squashed commit.+#[rstest]+fn test_merge_no_ff_with_squash(repo_with_multi_commit_feature: TestRepo) {+ let repo = &repo_with_multi_commit_feature;+ let feature_wt = &repo.worktrees["feature"];++ assert_cmd_snapshot!(make_snapshot_cmd(+ repo,+ "merge",+ &["main", "--no-ff", "--no-remove"],+ Some(feature_wt)+ ));++ // Verify merge commit has 2 parents+ let parent_count = repo.git_output(&["cat-file", "-p", "main"]);+ let parents: Vec<&str> = parent_count+ .lines()+ .filter(|l| l.starts_with("parent "))+ .collect();+ assert_eq!(+ parents.len(),+ 2,+ "Merge commit should have exactly 2 parents"+ );+}++/// --no-ff via user config (no CLI flag needed).+#[rstest]+fn test_merge_no_ff_from_config(merge_scenario: (TestRepo, PathBuf)) {+ let (repo, feature_wt) = merge_scenario;++ // Write user config with no-ff = true+ fs::write(repo.test_config_path(), "[merge]\nno-ff = true\n").unwrap();++ assert_cmd_snapshot!(make_snapshot_cmd(+ &repo,+ "merge",+ &["main", "--no-remove"],+ Some(&feature_wt)+ ));++ // Verify merge commit was created+ let parent_count = repo.git_output(&["cat-file", "-p", "main"]);+ let parents: Vec<&str> = parent_count+ .lines()+ .filter(|l| l.starts_with("parent "))+ .collect();+ assert_eq!(+ parents.len(),+ 2,+ "Config-driven --no-ff should create merge commit"+ );+}++/// --ff CLI flag overrides config no-ff = true.+#[rstest]+fn test_merge_ff_flag_overrides_config(merge_scenario: (TestRepo, PathBuf)) {+ let (repo, feature_wt) = merge_scenario;++ // Write user config with no-ff = true+ fs::write(repo.test_config_path(), "[merge]\nno-ff = true\n").unwrap();++ // --ff should override config and do a fast-forward+ assert_cmd_snapshot!(make_snapshot_cmd(+ &repo,+ "merge",+ &["main", "--ff", "--no-remove"],+ Some(&feature_wt)+ ));++ // Verify NO merge commit (fast-forward: HEAD on main should have 1 parent)+ let parent_count = repo.git_output(&["cat-file", "-p", "main"]);+ let parents: Vec<&str> = parent_count+ .lines()+ .filter(|l| l.starts_with("parent "))+ .collect();+ assert_eq!(+ parents.len(),+ 1,+ "--ff should override config and fast-forward"+ );+}++/// --no-ff with diverged branches: rebase first, then merge commit.+#[rstest]+fn test_merge_no_ff_with_rebase(mut repo_with_main_worktree: TestRepo) {+ let repo = &mut repo_with_main_worktree;+ let main_wt = repo.root_path().to_path_buf();+ let feature_wt = repo.add_worktree("feature");++ // Make a commit on feature+ repo.commit_in_worktree(&feature_wt, "feature.txt", "feature content", "Add feature");++ // Make a commit on main (diverge)+ repo.commit_in_worktree(&main_wt, "main.txt", "main content", "Advance main");++ // Merge with --no-ff: should rebase first, then create merge commit+ assert_cmd_snapshot!(make_snapshot_cmd(+ repo,+ "merge",+ &["main", "--no-ff", "--no-squash", "--no-remove"],+ Some(&feature_wt)+ ));++ // Verify merge commit has 2 parents+ let parent_count = repo.git_output(&["cat-file", "-p", "main"]);+ let parents: Vec<&str> = parent_count+ .lines()+ .filter(|l| l.starts_with("parent "))+ .collect();+ assert_eq!(parents.len(), 2, "Should create merge commit after rebase");+}++/// --no-ff when already up to date (no commits to merge).+#[rstest]+fn test_merge_no_ff_already_up_to_date(mut repo_with_main_worktree: TestRepo) {+ let repo = &mut repo_with_main_worktree;+ let feature_wt = repo.add_worktree("feature");++ // Don't make any commits on feature - it's at the same point as main+ assert_cmd_snapshot!(make_snapshot_cmd(+ repo,+ "merge",+ &["main", "--no-ff", "--no-remove"],+ Some(&feature_wt)+ ));+}++/// --no-ff with diverged branches and --no-rebase: fails because rebase is required.+///+/// When branches have diverged and --no-rebase is set, the merge cannot proceed+/// because --no-ff still requires a fast-forward relationship (rebase first, then+/// merge commit). This verifies the error path.+#[rstest]+fn test_merge_no_ff_diverged_no_rebase(mut repo_with_main_worktree: TestRepo) {+ let repo = &mut repo_with_main_worktree;+ let main_wt = repo.root_path().to_path_buf();+ let feature_wt = repo.add_worktree("feature");++ // Make a commit on feature+ repo.commit_in_worktree(&feature_wt, "feature.txt", "feature content", "Add feature");++ // Make a commit on main (diverge)+ repo.commit_in_worktree(&main_wt, "main.txt", "main content", "Advance main");++ // With --no-rebase, the merge fails because branches have diverged+ assert_cmd_snapshot!(make_snapshot_cmd(+ repo,+ "merge",+ &["main", "--no-ff", "--no-rebase", "--no-remove"],+ Some(&feature_wt)+ ));+}++/// --no-ff merge succeeds and syncs target worktree via reset --hard.+///+/// Verifies that after a --no-ff merge, the target worktree's working tree+/// reflects the merge commit (not the old HEAD).+#[rstest]+fn test_merge_no_ff_syncs_target_worktree(mut repo_with_main_worktree: TestRepo) {+ let repo = &mut repo_with_main_worktree;+ let main_wt = repo.root_path().to_path_buf();+ let feature_wt = repo.add_worktree("feature");++ // Make a commit on feature that adds a new file+ repo.commit_in_worktree(+ &feature_wt,+ "feature.txt",+ "feature content",+ "Add feature file",+ );++ // Merge with --no-ff+ let output = repo+ .wt_command()+ .args(["merge", "main", "--no-ff", "--no-remove"])+ .current_dir(&feature_wt)+ .output()+ .unwrap();+ assert!(+ output.status.success(),+ "merge should succeed: {}",+ String::from_utf8_lossy(&output.stderr)+ );++ // Verify the feature file exists in the main worktree (reset --hard synced it)+ assert!(+ main_wt.join("feature.txt").exists(),+ "Target worktree should contain the merged file after reset --hard"+ );++ // Verify the merge commit is on main+ let commit_msg = repo.git_output(&["log", "-1", "--format=%s", "main"]);+ assert_eq!(commit_msg, "Merge branch 'feature' into main");++ // Verify the target worktree HEAD matches the main branch tip+ let main_tip = repo.git_output(&["rev-parse", "main"]);+ let wt_head_output = repo+ .git_command()+ .args(["rev-parse", "HEAD"])+ .current_dir(&main_wt)+ .output()+ .unwrap();+ let wt_head = String::from_utf8_lossy(&wt_head_output.stdout)+ .trim()+ .to_string();+ assert_eq!(+ main_tip, wt_head,+ "Target worktree HEAD should match main after reset --hard"+ );+}++/// --no-ff merge with non-overlapping dirty files in the target worktree.+///+/// The target worktree has uncommitted changes to a file that doesn't overlap+/// with the merge. These should be auto-stashed, the merge commit created,+/// and the stash restored afterward.+#[rstest]+fn test_merge_no_ff_dirty_target_autostash(mut repo_with_main_worktree: TestRepo) {+ let repo = &mut repo_with_main_worktree;+ let main_wt = repo.root_path().to_path_buf();++ // Make main worktree dirty with a non-conflicting file+ fs::write(main_wt.join("notes.txt"), "temporary notes").unwrap();++ let feature_wt = repo.add_worktree("feature");+ repo.commit_in_worktree(&feature_wt, "feature.txt", "feature content", "Add feature");++ assert_cmd_snapshot!(make_snapshot_cmd(+ repo,+ "merge",+ &["main", "--no-ff", "--no-remove"],+ Some(&feature_wt)+ ));++ // Verify dirty file was restored after autostash+ let notes = fs::read_to_string(main_wt.join("notes.txt")).unwrap();+ assert_eq!(+ notes, "temporary notes",+ "Autostash should restore dirty file"+ );++ // Verify autostash cleaned up (no leftover stash entries)+ let stash_list = repo.git_command().args(["stash", "list"]).output().unwrap();+ assert!(+ String::from_utf8_lossy(&stash_list.stdout)+ .trim()+ .is_empty(),+ "Autostash should clean up after itself"+ );++ // Verify merge commit was created+ let parent_count = repo.git_output(&["cat-file", "-p", "main"]);+ let parents: Vec<&str> = parent_count+ .lines()+ .filter(|l| l.starts_with("parent "))+ .collect();+ assert_eq!(parents.len(), 2, "Should create merge commit");+}++/// --no-ff merge with overlapping dirty files in the target worktree.+///+/// The target worktree has uncommitted changes to a file that overlaps with+/// the merge range. The merge should fail safely without creating a merge+/// commit or losing the dirty changes.+#[rstest]+fn test_merge_no_ff_dirty_target_conflict(mut repo_with_main_worktree: TestRepo) {+ let repo = &mut repo_with_main_worktree;+ let main_wt = repo.root_path().to_path_buf();++ // Make main worktree dirty with a file that will conflict+ fs::write(main_wt.join("conflict.txt"), "old content").unwrap();++ let feature_wt =+ repo.add_worktree_with_commit("feature", "conflict.txt", "new content", "Add conflict");++ // Should fail due to conflicting uncommitted changes in target+ assert_cmd_snapshot!(make_snapshot_cmd(+ repo,+ "merge",+ &["main", "--no-ff", "--no-remove"],+ Some(&feature_wt)+ ));++ // Verify target worktree file is untouched+ let contents = fs::read_to_string(main_wt.join("conflict.txt")).unwrap();+ assert_eq!(+ contents, "old content",+ "Target dirty file should be untouched"+ );++ // Verify no stash was created+ let stash_list = repo.git_command().args(["stash", "list"]).output().unwrap();+ assert!(+ String::from_utf8_lossy(&stash_list.stdout)+ .trim()+ .is_empty(),+ "No stash should be created on conflict"+ );++ // Verify no merge commit was created (main should not have 2 parents)+ let parent_count = repo.git_output(&["cat-file", "-p", "main"]);+ let parents: Vec<&str> = parent_count+ .lines()+ .filter(|l| l.starts_with("parent "))+ .collect();+ assert!(+ parents.len() < 2,+ "No merge commit should be created on conflict"+ );+}++/// --no-ff merge when the target branch has no checked-out worktree.+///+/// The merge should succeed without attempting reset --hard (no worktree to sync).+#[rstest]+fn test_merge_no_ff_target_without_worktree(repo: TestRepo) {+ // Move primary off main so main has no worktree+ repo.switch_primary_to("develop");++ // Make a commit on develop so there's something to merge+ repo.commit_in_worktree(+ repo.root_path(),+ "feature.txt",+ "feature content",+ "Add feature",+ );++ assert_cmd_snapshot!(make_snapshot_cmd(+ &repo,+ "merge",+ &["main", "--no-ff"],+ None+ ));++ // Verify merge commit was created+ let parent_count = repo.git_output(&["cat-file", "-p", "main"]);+ let parents: Vec<&str> = parent_count+ .lines()+ .filter(|l| l.starts_with("parent "))+ .collect();+ assert_eq!(+ parents.len(),+ 2,+ "Should create merge commit even without target worktree"+ );+}diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snapindex 1a1d6637f..5e2e6f05b 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap@@ -1,5 +1,6 @@---source: tests/integration_tests/help.rs+assertion_line: 40info:program: wtargs:@@ -9,7 +10,6 @@ info:env:CLICOLOR_FORCE: "1"COLUMNS: "500"- GIT_EDITOR: ""LANG: CLC_ALL: CNO_COLOR: ""@@ -150,7 +150,7 @@ Creates [2m~/.config/worktrunk/config.toml[0m with the following content:[107m [0m [2m#[0m[107m [0m [2m# ### Merge[0m[107m [0m [2m#[0m-[107m [0m [2m# All flags are on by default. Set to false to change default behavior.[0m+[107m [0m [2m# Most flags are on by default. Set to false to change default behavior.[0m[107m [0m [2m#[0m[107m [0m [2m# [merge][0m[107m [0m [2m# squash = true # Squash commits into one (--no-squash to preserve history)[0m@@ -158,6 +158,7 @@ Creates [2m~/.config/worktrunk/config.toml[0m with the following content:[107m [0m [2m# rebase = true # Rebase onto target before merge (--no-rebase to skip)[0m[107m [0m [2m# remove = true # Remove worktree after merge (--no-remove to keep)[0m[107m [0m [2m# verify = true # Run project hooks (--no-verify to skip)[0m+[107m [0m [2m# no-ff = false # Create a merge commit even when fast-forward is possible (--no-ff)[0m[107m [0m [2m#[0m[107m [0m [2m# ### Switch[0m[107m [0m [2m#[0mdiff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snapindex 361409fc5..dea703aa1 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap@@ -1,5 +1,6 @@---source: tests/integration_tests/help.rs+assertion_line: 40info:program: wtargs:@@ -8,7 +9,6 @@ info:env:CLICOLOR_FORCE: "1"COLUMNS: "500"- GIT_EDITOR: ""LANG: CLC_ALL: CNO_COLOR: ""@@ -195,7 +195,7 @@ Shared by [2mwt step commit[0m, [2mwt step squash[0m, and [2mwt merge[0m.[32mMerge[0m-All flags are on by default. Set to false to change default behavior.+Most flags are on by default. Set to false to change default behavior.[107m [0m [2m[36m[merge][0m[107m [0m [2msquash = [0m[2m[33mtrue[0m[2m [0m[2m# Squash commits into one (--no-squash to preserve history)[0m@@ -203,6 +203,7 @@ All flags are on by default. Set to false to change default behavior.[107m [0m [2mrebase = [0m[2m[33mtrue[0m[2m [0m[2m# Rebase onto target before merge (--no-rebase to skip)[0m[107m [0m [2mremove = [0m[2m[33mtrue[0m[2m [0m[2m# Remove worktree after merge (--no-remove to keep)[0m[107m [0m [2mverify = [0m[2m[33mtrue[0m[2m [0m[2m# Run project hooks (--no-verify to skip)[0m+[107m [0m [2mno-ff = [0m[2m[33mfalse[0m[2m [0m[2m# Create a merge commit even when fast-forward is possible (--no-ff)[0m[32mSwitch[0mdiff --git a/tests/snapshots/integration__integration_tests__help__help_md_merge.snap b/tests/snapshots/integration__integration_tests__help__help_md_merge.snapindex 72218a7db..5ba3f0a4e 100644--- a/tests/snapshots/integration__integration_tests__help__help_md_merge.snap+++ b/tests/snapshots/integration__integration_tests__help__help_md_merge.snap@@ -1,5 +1,6 @@---source: tests/integration_tests/help.rs+assertion_line: 131info:program: wtargs:@@ -8,7 +9,6 @@ info:env:CLICOLOR_FORCE: "1"COLUMNS: "500"- GIT_EDITOR: ""LANG: CLC_ALL: CNO_COLOR: ""@@ -54,6 +54,9 @@ Options:--no-removeKeep worktree after merge+ --no-ff+ Create a merge commit (no fast-forward)+--stage <STAGE>What to stage before committing [default: all]@@ -111,6 +114,12 @@ Preserve commit history (no squash):wt merge --no-squash```+Create a merge commit (semi-linear history):++```bash+wt merge --no-ff+```+Skip committing/squashing (rebase still runs unless --no-rebase):```bash@@ -124,7 +133,7 @@ wt merge --no-commit1. **Squash** — Stages uncommitted changes, then combines all commits since target into one (like GitHub's "Squash and merge"). Use `--stage` to control what gets staged: `all` (default), `tracked`, or `none`. A backup ref is saved to `refs/wt-backup/<branch>`. With `--no-squash`, uncommitted changes become a separate commit and individual commits are preserved.2. **Rebase** — Rebases onto target if behind. Skipped if already up-to-date. Conflicts abort immediately.3. **Pre-merge hooks** — Hooks run after rebase, before merge. Failures abort. See [`wt hook`](@/hook.md).-4. **Merge** — Fast-forward merge to the target branch. Non-fast-forward merges are rejected.+4. **Merge** — Fast-forward merge to the target branch. With `--no-ff`, a merge commit is created instead (semi-linear history: rebased commits plus a merge commit). Non-fast-forward merges are rejected.5. **Pre-remove hooks** — Hooks run before removing worktree. Failures abort.6. **Cleanup** — Removes the worktree and branch. Use `--no-remove` to keep the worktree. When already on the target branch or in the main worktree, the worktree is preserved.7. **Post-merge hooks** — Hooks run after cleanup. Failures are logged but don't abort.diff --git a/tests/snapshots/integration__integration_tests__help__help_merge_long.snap b/tests/snapshots/integration__integration_tests__help__help_merge_long.snapindex 0a967f4a4..8e696b9d7 100644--- a/tests/snapshots/integration__integration_tests__help__help_merge_long.snap+++ b/tests/snapshots/integration__integration_tests__help__help_merge_long.snap@@ -1,5 +1,6 @@---source: tests/integration_tests/help.rs+assertion_line: 40info:program: wtargs:@@ -8,7 +9,6 @@ info:env:CLICOLOR_FORCE: "1"COLUMNS: "500"- GIT_EDITOR: ""LANG: CLC_ALL: CNO_COLOR: ""@@ -56,6 +56,9 @@ Usage: [1m[36mwt merge[0m [36m[OPTIONS][0m [36m[TARGET][0m[1m[36m--no-remove[0mKeep worktree after merge+ [1m[36m--no-ff[0m+ Create a merge commit (no fast-forward)+[1m[36m--stage[0m[36m [0m[36m<STAGE>[0mWhat to stage before committing [default: all]@@ -104,6 +107,10 @@ Preserve commit history (no squash):[107m [0m [2m[0m[2m[34mwt[0m[2m merge [0m[2m[36m--no-squash[0m[2m[0m+Create a merge commit (semi-linear history):++[107m [0m [2m[0m[2m[34mwt[0m[2m merge [0m[2m[36m--no-ff[0m[2m[0m+Skip committing/squashing (rebase still runs unless --no-rebase):[107m [0m [2m[0m[2m[34mwt[0m[2m merge [0m[2m[36m--no-commit[0m[2m[0m@@ -115,7 +122,7 @@ Skip committing/squashing (rebase still runs unless --no-rebase):1. [1mSquash[0m — Stages uncommitted changes, then combines all commits since target into one (like GitHub's "Squash and merge"). Use [2m--stage[0m to control what gets staged: [2mall[0m (default), [2mtracked[0m, or [2mnone[0m. A backup ref is saved to [2mrefs/wt-backup/<branch>[0m. With [2m--no-squash[0m, uncommitted changes become a separate commit and individual commits are preserved.2. [1mRebase[0m — Rebases onto target if behind. Skipped if already up-to-date. Conflicts abort immediately.3. [1mPre-merge hooks[0m — Hooks run after rebase, before merge. Failures abort. See [2mwt hook[0m.-4. [1mMerge[0m — Fast-forward merge to the target branch. Non-fast-forward merges are rejected.+4. [1mMerge[0m — Fast-forward merge to the target branch. With [2m--no-ff[0m, a merge commit is created instead (semi-linear history: rebased commits plus a merge commit). Non-fast-forward merges are rejected.5. [1mPre-remove hooks[0m — Hooks run before removing worktree. Failures abort.6. [1mCleanup[0m — Removes the worktree and branch. Use [2m--no-remove[0m to keep the worktree. When already on the target branch or in the main worktree, the worktree is preserved.7. [1mPost-merge hooks[0m — Hooks run after cleanup. Failures are logged but don't abort.diff --git a/tests/snapshots/integration__integration_tests__help__help_merge_short.snap b/tests/snapshots/integration__integration_tests__help__help_merge_short.snapindex b696378f8..7961f4038 100644--- a/tests/snapshots/integration__integration_tests__help__help_merge_short.snap+++ b/tests/snapshots/integration__integration_tests__help__help_merge_short.snap@@ -1,5 +1,6 @@---source: tests/integration_tests/help.rs+assertion_line: 40info:program: wtargs:@@ -8,7 +9,6 @@ info:env:CLICOLOR_FORCE: "1"COLUMNS: "500"- GIT_EDITOR: ""LANG: CLC_ALL: CNO_COLOR: ""@@ -43,6 +43,7 @@ Usage: [1m[36mwt merge[0m [36m[OPTIONS][0m [36m[TARGET][0m[1m[36m--no-commit[0m Skip commit and squash[1m[36m--no-rebase[0m Skip rebase (fail if not already rebased)[1m[36m--no-remove[0m Keep worktree after merge+ [1m[36m--no-ff[0m Create a merge commit (no fast-forward)[1m[36m--stage[0m[36m [0m[36m<STAGE>[0m What to stage before committing [default: all] [possible values: all, tracked, none][1m[36m-h[0m, [1m[36m--help[0m Print help (see more with '--help')diff --git a/tests/snapshots/integration__integration_tests__merge__merge_ff_flag_overrides_config.snap b/tests/snapshots/integration__integration_tests__merge__merge_ff_flag_overrides_config.snapnew file mode 100644index 000000000..0503610b5--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_ff_flag_overrides_config.snap@@ -0,0 +1,52 @@+---+source: tests/integration_tests/merge.rs+assertion_line: 2221+info:+ program: wt+ args:+ - merge+ - main+ - "--ff"+ - "--no-remove"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mMerging 1 commit to [1mmain[22m @ [2m[HASH][22m (no commit/squash/rebase needed)[39m+[107m [0m * [33m[HASH][m Add feature file+[107m [0m feature.txt | 1 [32m+[m+[107m [0m 1 file changed, 1 insertion(+)+[32m✓[39m [32mMerged to [1mmain[22m [90m(1 commit, 1 file, [32m+1[39m[39m[90m)[39m[39m+[2m○[22m Worktree preserved (--no-remove)diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_ff_already_up_to_date.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_already_up_to_date.snapnew file mode 100644index 000000000..6259abcce--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_already_up_to_date.snap@@ -0,0 +1,48 @@+---+source: tests/integration_tests/merge.rs+assertion_line: 2278+info:+ program: wt+ args:+ - merge+ - main+ - "--no-ff"+ - "--no-remove"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[2m○[22m Already up to date with [1mmain[22m (no new commits, no rebase needed)+[2m○[22m Worktree preserved (--no-remove)diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_ff_basic.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_basic.snapnew file mode 100644index 000000000..6f46c9fcf--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_basic.snap@@ -0,0 +1,52 @@+---+source: tests/integration_tests/merge.rs+assertion_line: 2103+info:+ program: wt+ args:+ - merge+ - main+ - "--no-ff"+ - "--no-remove"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mMerging 1 commit to [1mmain[22m @ [2m[HASH][22m (--no-ff) (no commit/squash/rebase needed)[39m+[107m [0m * [33m[HASH][m Add feature file+[107m [0m feature.txt | 1 [32m+[m+[107m [0m 1 file changed, 1 insertion(+)+[32m✓[39m [32mMerged to [1mmain[22m @ [2m[HASH][22m [90m(1 commit, 1 file, [32m+1[39m, --no-ff[39m[90m)[39m[39m+[2m○[22m Worktree preserved (--no-remove)diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_ff_dirty_target_autostash.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_dirty_target_autostash.snapnew file mode 100644index 000000000..01142ff76--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_dirty_target_autostash.snap@@ -0,0 +1,54 @@+---+source: tests/integration_tests/merge.rs+assertion_line: 2386+info:+ program: wt+ args:+ - merge+ - main+ - "--no-ff"+ - "--no-remove"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mStashing changes in [1m_REPO_[22m...[39m+[36m◎[39m [36mMerging 1 commit to [1mmain[22m @ [2m[HASH][22m (--no-ff) (no commit/squash/rebase needed)[39m+[107m [0m * [33m[HASH][m Add feature+[107m [0m feature.txt | 1 [32m+[m+[107m [0m 1 file changed, 1 insertion(+)+[36m◎[39m [36mRestoring stashed changes in [1m_REPO_[22m...[39m+[32m✓[39m [32mMerged to [1mmain[22m @ [2m[HASH][22m [90m(1 commit, 1 file, [32m+1[39m, --no-ff[39m[90m)[39m[39m+[2m○[22m Worktree preserved (--no-remove)diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_ff_dirty_target_conflict.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_dirty_target_conflict.snapnew file mode 100644index 000000000..2a7bc8413--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_dirty_target_conflict.snap@@ -0,0 +1,49 @@+---+source: tests/integration_tests/merge.rs+assertion_line: 2435+info:+ program: wt+ args:+ - merge+ - main+ - "--no-ff"+ - "--no-remove"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: false+exit_code: 1+----- stdout -----++----- stderr -----+[31m✗[39m [31mCan't push to local [1mmain[22m branch: conflicting uncommitted changes[39m+[107m [0m conflict.txt+[2m↳[22m [2mCommit or stash these changes in _REPO_ first[22mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_ff_diverged_no_rebase.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_diverged_no_rebase.snapnew file mode 100644index 000000000..3da11b907--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_diverged_no_rebase.snap@@ -0,0 +1,49 @@+---+source: tests/integration_tests/merge.rs+assertion_line: 2302+info:+ program: wt+ args:+ - merge+ - main+ - "--no-ff"+ - "--no-rebase"+ - "--no-remove"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: false+exit_code: 1+----- stdout -----++----- stderr -----+[31m✗[39m [31mBranch not rebased onto [1mmain[22m[39m+[2m↳[22m [2mTo rebase first, run [4mwt step rebase main[24m; or remove [4m--no-rebase[24m[22mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_ff_from_config.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_from_config.snapnew file mode 100644index 000000000..ea3c72019--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_from_config.snap@@ -0,0 +1,51 @@+---+source: tests/integration_tests/merge.rs+assertion_line: 2192+info:+ program: wt+ args:+ - merge+ - main+ - "--no-remove"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mMerging 1 commit to [1mmain[22m @ [2m[HASH][22m (--no-ff) (no commit/squash/rebase needed)[39m+[107m [0m * [33m[HASH][m Add feature file+[107m [0m feature.txt | 1 [32m+[m+[107m [0m 1 file changed, 1 insertion(+)+[32m✓[39m [32mMerged to [1mmain[22m @ [2m[HASH][22m [90m(1 commit, 1 file, [32m+1[39m, --no-ff[39m[90m)[39m[39m+[2m○[22m Worktree preserved (--no-remove)diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_ff_multi_commit.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_multi_commit.snapnew file mode 100644index 000000000..a72237f25--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_multi_commit.snap@@ -0,0 +1,55 @@+---+source: tests/integration_tests/merge.rs+assertion_line: 2133+info:+ program: wt+ args:+ - merge+ - main+ - "--no-ff"+ - "--no-squash"+ - "--no-remove"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mMerging 2 commits to [1mmain[22m @ [2m[HASH][22m (--no-ff) (no commit/squash/rebase needed)[39m+[107m [0m * [33m[HASH][m feat: add file 2+[107m [0m * [33m[HASH][m feat: add file 1+[107m [0m file1.txt | 1 [32m+[m+[107m [0m file2.txt | 1 [32m+[m+[107m [0m 2 files changed, 2 insertions(+)+[32m✓[39m [32mMerged to [1mmain[22m @ [2m[HASH][22m [90m(2 commits, 2 files, [32m+2[39m, --no-ff[39m[90m)[39m[39m+[2m○[22m Worktree preserved (--no-remove)diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_ff_target_without_worktree.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_target_without_worktree.snapnew file mode 100644index 000000000..5a11ab208--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_target_without_worktree.snap@@ -0,0 +1,51 @@+---+source: tests/integration_tests/merge.rs+assertion_line: 2487+info:+ program: wt+ args:+ - merge+ - main+ - "--no-ff"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mMerging 1 commit to [1mmain[22m @ [2m[HASH][22m (--no-ff) (no commit/squash/rebase needed)[39m+[107m [0m * [33m[HASH][m Add feature+[107m [0m feature.txt | 1 [32m+[m+[107m [0m 1 file changed, 1 insertion(+)+[32m✓[39m [32mMerged to [1mmain[22m @ [2m[HASH][22m [90m(1 commit, 1 file, [32m+1[39m, --no-ff[39m[90m)[39m[39m+[2m○[22m Worktree preserved (main worktree)diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_ff_with_rebase.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_with_rebase.snapnew file mode 100644index 000000000..edc0cbd34--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_with_rebase.snap@@ -0,0 +1,55 @@+---+source: tests/integration_tests/merge.rs+assertion_line: 2255+info:+ program: wt+ args:+ - merge+ - main+ - "--no-ff"+ - "--no-squash"+ - "--no-remove"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mRebasing onto [1mmain[22m...[39m+[32m✓[39m [32mRebased onto [1mmain[22m[39m+[36m◎[39m [36mMerging 1 commit to [1mmain[22m @ [2m[HASH][22m (--no-ff) (no commit/squash needed)[39m+[107m [0m * [33m[HASH][m Add feature+[107m [0m feature.txt | 1 [32m+[m+[107m [0m 1 file changed, 1 insertion(+)+[32m✓[39m [32mMerged to [1mmain[22m @ [2m[HASH][22m [90m(1 commit, 1 file, [32m+1[39m, --no-ff[39m[90m)[39m[39m+[2m○[22m Worktree preserved (--no-remove)diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_ff_with_squash.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_with_squash.snapnew file mode 100644index 000000000..857ed060e--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_ff_with_squash.snap@@ -0,0 +1,62 @@+---+source: tests/integration_tests/merge.rs+assertion_line: 2164+info:+ program: wt+ args:+ - merge+ - main+ - "--no-ff"+ - "--no-remove"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mSquashing 2 commits into a single commit [90m(2 files, [32m+2[39m[39m[90m)[39m...[39m+[36m◎[39m [36mGenerating squash commit message...[39m+[2m↳[22m [2mUsing fallback commit message. For LLM setup guide, run [4mwt config --help[24m[22m+[107m [0m [1mSquash commits from feature[22m+[107m [0m+[107m [0m Combined commits:+[107m [0m - feat: add file 1+[107m [0m - feat: add file 2+[32m✓[39m [32mSquashed @ [HASH][39m+[36m◎[39m [36mMerging 1 commit to [1mmain[22m @ [2m[HASH][22m (--no-ff) (no rebase needed)[39m+[107m [0m * [33m[HASH][m Squash commits from feature+[107m [0m file1.txt | 1 [32m+[m+[107m [0m file2.txt | 1 [32m+[m+[107m [0m 2 files changed, 2 insertions(+)+[32m✓[39m [32mMerged to [1mmain[22m @ [2m[HASH][22m [90m(1 commit, 2 files, [32m+2[39m, --no-ff[39m[90m)[39m[39m+[2m○[22m Worktree preserved (--no-remove)diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_command_not_found.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_command_not_found.snapindex 6fd1b7f16..debd654aa 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_command_not_found.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_command_not_found.snap@@ -1,5 +1,6 @@---source: tests/integration_tests/merge.rs+assertion_line: 346info:program: wtargs:@@ -13,23 +14,26 @@ info:GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"GIT_CONFIG_SYSTEM: /dev/null- GIT_EDITOR: ""GIT_TERMINAL_PROMPT: "0"HOME: "[TEST_HOME]"LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warnSHELL: ""TERM: alacrittyUSERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"WORKTRUNK_COMMIT__GENERATION__COMMAND: nonexistent-llm-commandWORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"