Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat(merge): Introduce --no-commit flag for minimal merge workflow

Maximilian Roos54dc1e8de1dd
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index 0e11a7a47..6403c7526 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -2,7 +2,7 @@ use worktrunk::HookType;
use worktrunk::config::{ProjectConfig, WorktrunkConfig};
use worktrunk::git::{GitError, GitResultExt, Repository};
use worktrunk::styling::{
- AnstyleStyle, CYAN, CYAN_BOLD, HINT, HINT_EMOJI, WARNING, WARNING_EMOJI,
+ AnstyleStyle, CYAN, CYAN_BOLD, ERROR, ERROR_EMOJI, HINT, HINT_EMOJI, WARNING, WARNING_EMOJI,
format_bash_with_gutter, format_with_gutter,
};
@@ -49,6 +49,7 @@ fn show_untracked_warning(repo: &Repository) -> Result<(), GitError> {
pub fn handle_merge(
target: Option<&str>,
squash_enabled: bool,
+ no_commit: bool,
no_remove: bool,
no_verify: bool,
force: bool,
@@ -59,6 +60,21 @@ pub fn handle_merge(
// Get current branch
let current_branch = repo.current_branch()?.ok_or(GitError::DetachedHead)?;
+ // Validate --no-commit: requires clean working tree
+ if no_commit && repo.is_dirty()? {
+ return Err(GitError::UncommittedChanges);
+ }
+
+ // Validate --no-commit flag compatibility
+ if no_commit && !no_remove {
+ return Err(GitError::CommandFailed(format!(
+ "{ERROR_EMOJI} {ERROR}--no-commit requires --no-remove{ERROR:#}\n\n{HINT_EMOJI} {HINT}Cannot remove active worktree when skipping commit/rebase{HINT:#}"
+ )));
+ }
+
+ // --no-commit implies --no-squash (validation above ensures --no-remove is already set)
+ let squash_enabled = if no_commit { false } else { squash_enabled };
+
// Get target branch (default to default branch if not provided)
let target_branch = repo.resolve_target_branch(target)?;
@@ -75,8 +91,8 @@ pub fn handle_merge(
// Load config for LLM integration
let config = WorktrunkConfig::load().git_context("Failed to load config")?;
- // Handle uncommitted changes depending on whether we're squashing
- if repo.is_dirty()? {
+ // Handle uncommitted changes (skip if --no-commit)
+ if !no_commit && repo.is_dirty()? {
if squash_enabled {
// Warn about untracked files before staging
if !tracked_only {
@@ -108,11 +124,13 @@ pub fn handle_merge(
handle_squash(&target_branch, no_verify, force)?;
}
- // Rebase onto target (delegate to atomic dev command)
- super::dev::handle_dev_rebase(Some(&target_branch))?;
+ // Rebase onto target (skip if --no-commit)
+ if !no_commit {
+ super::dev::handle_dev_rebase(Some(&target_branch))?;
+ }
// Run pre-merge checks unless --no-verify was specified
- // Do this AFTER rebase to validate the final state that will be pushed
+ // Do this after commit/squash/rebase to validate the final state that will be pushed
if !no_verify && let Ok(Some(project_config)) = ProjectConfig::load(&repo.worktree_root()?) {
let worktree_path =
std::env::current_dir().git_context("Failed to get current directory")?;
diff --git a/src/main.rs b/src/main.rs
index 994430447..49eed1ee1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -255,6 +255,10 @@ Skip pre-merge commands:
#[arg(long = "no-squash", action = ArgAction::SetFalse, default_value_t = true)]
squash_enabled: bool,
+ /// Push commits as-is without transformations (requires clean tree; implies --no-squash, --no-remove, and skips rebase)
+ #[arg(long)]
+ no_commit: bool,
+
/// Keep worktree after merging (don't remove)
#[arg(long = "no-remove")]
no_remove: bool,
@@ -515,6 +519,7 @@ fn main() {
Commands::Merge {
target,
squash_enabled,
+ no_commit,
no_remove,
no_verify,
force,
@@ -522,6 +527,7 @@ fn main() {
} => handle_merge(
target.as_deref(),
squash_enabled,
+ no_commit,
no_remove,
no_verify,
force,
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index 480a666cf..47fef2e17 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -1677,3 +1677,173 @@ fn test_merge_no_remote() {
// Try to merge without specifying target (should fail - no remote to get default branch)
snapshot_merge("merge_no_remote", &repo, &[], Some(&feature_wt));
}
+
+#[test]
+fn test_merge_no_commit_with_clean_tree() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.setup_remote("main");
+
+ // Create a worktree for main
+ let main_wt = repo.root_path().parent().unwrap().join("test-repo.main-wt");
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])
+ .current_dir(repo.root_path())
+ .output()
+ .expect("Failed to add worktree");
+
+ // Create a feature worktree with commits (clean tree)
+ let feature_wt = repo.add_worktree("feature", "feature");
+ fs::write(feature_wt.join("feature.txt"), "feature content").expect("Failed to write file");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["add", "feature.txt"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to add file");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["commit", "-m", "Add feature file"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to commit");
+
+ // Merge with --no-commit (should succeed - clean tree)
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(
+ &repo,
+ "merge",
+ &["main", "--no-commit", "--no-remove"],
+ Some(&feature_wt),
+ );
+ assert_cmd_snapshot!(cmd, @r"
+ success: true
+ exit_code: 0
+ ----- stdout -----
+ πŸ”„ Merging 1 commit to main @ [SHA]
+
+ * [SHA] (HEAD -> feature) Add feature file
+
+ feature.txt | 1 +
+ 1 file changed, 1 insertion(+)
+
+ βœ… Merged to main (1 commit, 1 file, +1) 
+
+ βœ… Kept worktree (use 'wt remove' to clean up)
+
+ ----- stderr -----
+ ");
+ });
+}
+
+#[test]
+fn test_merge_no_commit_with_dirty_tree() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.setup_remote("main");
+
+ // Create a feature worktree with a commit
+ let feature_wt = repo.add_worktree("feature", "feature");
+ fs::write(feature_wt.join("committed.txt"), "committed content").expect("Failed to write file");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["add", "committed.txt"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to add file");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["commit", "-m", "Add committed file"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to commit");
+
+ // Add uncommitted changes
+ fs::write(feature_wt.join("uncommitted.txt"), "uncommitted content")
+ .expect("Failed to write file");
+
+ // Try to merge with --no-commit (should fail - dirty tree)
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd =
+ make_snapshot_cmd(&repo, "merge", &["main", "--no-commit"], Some(&feature_wt));
+ assert_cmd_snapshot!(cmd, @r"
+ success: false
+ exit_code: 1
+ ----- stdout -----
+
+ ----- stderr -----
+ ❌ Working tree has uncommitted changes
+
+ πŸ’‘ Commit or stash them first
+ ");
+ });
+}
+
+#[test]
+fn test_merge_no_commit_no_squash_no_remove_redundant() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.setup_remote("main");
+
+ // Create a worktree for main
+ let main_wt = repo.root_path().parent().unwrap().join("test-repo.main-wt");
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])
+ .current_dir(repo.root_path())
+ .output()
+ .expect("Failed to add worktree");
+
+ // Create a feature worktree with commits (clean tree)
+ let feature_wt = repo.add_worktree("feature", "feature");
+ fs::write(feature_wt.join("feature.txt"), "feature content").expect("Failed to write file");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["add", "feature.txt"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to add file");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["commit", "-m", "Add feature file"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to commit");
+
+ // Merge with --no-commit --no-squash --no-remove (redundant but valid - should succeed)
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(
+ &repo,
+ "merge",
+ &["main", "--no-commit", "--no-squash", "--no-remove"],
+ Some(&feature_wt),
+ );
+ assert_cmd_snapshot!(cmd, @r"
+ success: true
+ exit_code: 0
+ ----- stdout -----
+ πŸ”„ Merging 1 commit to main @ [SHA]
+
+ * [SHA] (HEAD -> feature) Add feature file
+
+ feature.txt | 1 +
+ 1 file changed, 1 insertion(+)
+
+ βœ… Merged to main (1 commit, 1 file, +1) 
+
+ βœ… Kept worktree (use 'wt remove' to clean up)
+
+ ----- stderr -----
+ ");
+ });
+}
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snap
index 5cc12202b..e4e84eb42 100644
--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpE95Qy5/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpIW4lMG/test-config.toml
---
success: true
exit_code: 0
@@ -467,7 +467,7 @@ _wt() {
return 0
;;
wt__merge)
- opts="-f -v -h --no-squash --no-remove --no-verify --force --tracked-only --verbose --help [TARGET]"
+ opts="-f -v -h --no-squash --no-commit --no-remove --no-verify --force --tracked-only --verbose --help [TARGET]"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snap
index c2592f023..3ae2424bc 100644
--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpSfk2JM/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpsB1EpK/test-config.toml
---
success: true
exit_code: 0
@@ -283,6 +283,7 @@ complete -c wt -n "__fish_wt_using_subcommand switch" -s h -l help -d 'Print hel
complete -c wt -n "__fish_wt_using_subcommand remove" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand remove" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_using_subcommand merge" -l no-squash -d 'Disable squashing commits (by default, commits are squashed into one before merging)'
+complete -c wt -n "__fish_wt_using_subcommand merge" -l no-commit -d 'Push commits as-is without transformations (requires clean tree; implies --no-squash, --no-remove, and skips rebase)'
complete -c wt -n "__fish_wt_using_subcommand merge" -l no-remove -d 'Keep worktree after merging (don\'t remove)'
complete -c wt -n "__fish_wt_using_subcommand merge" -l no-verify -d 'Skip all project hooks (pre-merge-command)'
complete -c wt -n "__fish_wt_using_subcommand merge" -s f -l force -d 'Skip approval prompts for commands'
diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
index 7bc2fa85f..09e7acc3e 100644
--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpCEH56P/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpZD3Pf7/test-config.toml
---
success: true
exit_code: 0
@@ -339,6 +339,7 @@ _arguments "${_arguments_options[@]}" : \
(merge)
_arguments "${_arguments_options[@]}" : \
'--no-squash[Disable squashing commits (by default, commits are squashed into one before merging)]' \
+'--no-commit[Push commits as-is without transformations (requires clean tree; implies --no-squash, --no-remove, and skips rebase)]' \
'--no-remove[Keep worktree after merging (don'\''t remove)]' \
'--no-verify[Skip all project hooks (pre-merge-command)]' \
'-f[Skip approval prompts for commands]' \