Skip to content

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

feat: Auto-commit uncommitted changes before merge

Maximilian Rooseaf225c61536
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index bd0065dd6..adea9cfa8 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -11,6 +11,7 @@ pub fn handle_merge(
target: Option<&str>,
squash: bool,
keep: bool,
+ message: Option<&str>,
internal: bool,
) -> Result<(), GitError> {
let repo = Repository::current();
@@ -36,8 +37,14 @@ pub fn handle_merge(
return Ok(());
}
- // Check for uncommitted changes
- repo.ensure_clean_working_tree()?;
+ // Load config for LLM integration
+ let config = WorktrunkConfig::load()
+ .map_err(|e| GitError::CommandFailed(format!("Failed to load config: {}", e)))?;
+
+ // Auto-commit uncommitted changes if they exist
+ if repo.is_dirty()? {
+ handle_commit_changes(message, &config.llm)?;
+ }
// Track operations for summary
let mut squashed_count: Option<usize> = None;
@@ -113,6 +120,42 @@ fn print_merge_summary(
println!("βœ… {green}Merge complete{green:#}");
}
+/// Commit uncommitted changes with LLM-generated message
+fn handle_commit_changes(
+ custom_instruction: Option<&str>,
+ llm_config: &worktrunk::config::LlmConfig,
+) -> Result<(), GitError> {
+ let repo = Repository::current();
+
+ let cyan = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)));
+ println!("πŸ”„ {cyan}Committing uncommitted changes...{cyan:#}");
+
+ // Stage all tracked changes (excludes untracked files)
+ repo.run_command(&["add", "-u"])
+ .map_err(|e| GitError::CommandFailed(format!("Failed to stage changes: {}", e)))?;
+
+ // Check if there are staged changes after staging
+ if !repo.has_staged_changes()? {
+ // No staged changes means only untracked files exist
+ eprintln!("{ERROR_EMOJI} {ERROR}Working tree has untracked files{ERROR:#}");
+ eprintln!();
+ eprintln!("{HINT_EMOJI} {HINT}Add them with 'git add' and try again{HINT:#}");
+ return Err(GitError::CommandFailed(String::new()));
+ }
+
+ // Generate commit message
+ let commit_message = crate::llm::generate_commit_message(custom_instruction, llm_config)?;
+
+ // Commit
+ repo.run_command(&["commit", "-m", &commit_message])
+ .map_err(|e| GitError::CommandFailed(format!("Failed to commit: {}", e)))?;
+
+ let green = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Green)));
+ println!("βœ… {green}Committed changes{green:#}");
+
+ Ok(())
+}
+
fn handle_squash(target_branch: &str) -> Result<Option<usize>, GitError> {
let repo = Repository::current();
diff --git a/src/llm.rs b/src/llm.rs
index 1c5d9d646..7065d460e 100644
--- a/src/llm.rs
+++ b/src/llm.rs
@@ -1,7 +1,135 @@
use std::process;
use worktrunk::config::LlmConfig;
+use worktrunk::git::{GitError, Repository};
use worktrunk::styling::{WARNING, WARNING_EMOJI, eprintln};
+pub fn generate_commit_message(
+ custom_instruction: Option<&str>,
+ llm_config: &LlmConfig,
+) -> Result<String, GitError> {
+ // Try LLM generation if configured
+ if let Some(ref command) = llm_config.command {
+ if let Ok(llm_message) =
+ try_generate_commit_message(custom_instruction, command, &llm_config.args)
+ {
+ return Ok(llm_message);
+ }
+ // If LLM fails, fall through to deterministic approach
+ eprintln!(
+ "{WARNING_EMOJI} {WARNING}LLM generation failed, using deterministic message{WARNING:#}"
+ );
+ }
+
+ // Fallback: simple deterministic commit message
+ Ok("WIP: Auto-commit before merge".to_string())
+}
+
+fn try_generate_commit_message(
+ custom_instruction: Option<&str>,
+ command: &str,
+ args: &[String],
+) -> Result<String, Box<dyn std::error::Error>> {
+ let repo = Repository::current();
+
+ // Get staged diff
+ let diff_output = repo.run_command(&["--no-pager", "diff", "--staged"])?;
+
+ // Get current branch
+ let current_branch = repo.current_branch()?.unwrap_or_else(|| "HEAD".to_string());
+
+ // Get recent commit messages for style reference
+ let recent_commits = repo
+ .run_command(&["log", "--pretty=format:%s", "-n", "5", "--no-merges"])
+ .ok()
+ .and_then(|output| {
+ if output.trim().is_empty() {
+ None
+ } else {
+ Some(output.lines().map(String::from).collect::<Vec<_>>())
+ }
+ });
+
+ // Build the prompt following the Fish function format exactly
+ let user_instruction = custom_instruction
+ .unwrap_or("Write a concise, clear git commit message based on the provided diff.");
+
+ let mut prompt = String::new();
+
+ // Format section
+ prompt.push_str("Format\n");
+ prompt.push_str("- First line: <50 chars, present tense, describes WHAT and WHY (not HOW).\n");
+ prompt.push_str("- Blank line after first line.\n");
+ prompt.push_str("- Optional details with proper line breaks explaining context. Commits with more substantial changes should have more details.\n");
+ prompt.push_str(
+ "- Return ONLY the formatted message without quotes, code blocks, or preamble.\n",
+ );
+ prompt.push('\n');
+
+ // Style section
+ prompt.push_str("Style\n");
+ prompt.push_str(
+ "- Do not give normative statements or otherwise speculate on why the change was made.\n",
+ );
+ prompt.push_str("- Broadly match the style of the previous commit messages.\n");
+ prompt.push_str(" - For example, if they're in conventional commit format, use conventional commits; if they're not, don't use conventional commits.\n");
+ prompt.push('\n');
+
+ // Context description
+ prompt.push_str("The context contains:\n");
+ prompt.push_str("- <git-diff> with the staged changes. This is the ONLY content you should base your message on.\n");
+ prompt.push_str("- <git-info> with branch name and recent commit message titles for style reference ONLY. DO NOT use their content to inform your message.\n");
+ prompt.push('\n');
+ prompt.push_str("---\n");
+ prompt.push_str("The following is the context for your task:\n");
+ prompt.push_str("---\n");
+
+ // Git diff section
+ prompt.push_str("<git-diff>\n```\n");
+ prompt.push_str(&diff_output);
+ prompt.push_str("\n```\n</git-diff>\n\n");
+
+ // Git info section
+ prompt.push_str("<git-info>\n");
+ prompt.push_str(&format!(
+ " <current-branch>{}</current-branch>\n",
+ current_branch
+ ));
+
+ if let Some(commits) = recent_commits {
+ prompt.push_str(" <previous-commit-message-titles>\n");
+ for commit in commits {
+ prompt.push_str(&format!(
+ " <previous-commit-message-title>{}</previous-commit-message-title>\n",
+ commit
+ ));
+ }
+ prompt.push_str(" </previous-commit-message-titles>\n");
+ }
+
+ prompt.push_str("</git-info>\n\n");
+
+ // Execute LLM command
+ let output = process::Command::new(command)
+ .args(args)
+ .arg("--system")
+ .arg(user_instruction)
+ .arg(&prompt)
+ .output()?;
+
+ if !output.status.success() {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ return Err(format!("LLM command failed: {}", stderr).into());
+ }
+
+ let message = String::from_utf8_lossy(&output.stdout).trim().to_owned();
+
+ if message.is_empty() {
+ return Err("LLM returned empty message".into());
+ }
+
+ Ok(message)
+}
+
pub fn generate_squash_message(
target_branch: &str,
subjects: &[String],
diff --git a/src/main.rs b/src/main.rs
index 74509e67d..7d297f8b9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -145,6 +145,10 @@ enum Commands {
#[arg(short, long)]
keep: bool,
+ /// Custom instruction for commit message generation
+ #[arg(short = 'm', long)]
+ message: Option<String>,
+
/// Use internal mode (outputs directives for shell wrapper)
#[arg(long, hide = true)]
internal: bool,
@@ -262,8 +266,15 @@ fn main() {
target,
squash,
keep,
+ message,
+ internal,
+ } => handle_merge(
+ target.as_deref(),
+ squash,
+ keep,
+ message.as_deref(),
internal,
- } => handle_merge(target.as_deref(), squash, keep, internal),
+ ),
Commands::Completion { shell } => {
let mut cli_cmd = Cli::command();
handle_completion(shell, &mut cli_cmd);
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index 2ae18427d..7559e991a 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -479,3 +479,216 @@ fn test_merge_squash_single_commit() {
Some(&feature_wt),
);
}
+
+#[test]
+fn test_merge_auto_commit_deterministic() {
+ 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 a commit
+ let feature_wt = repo.add_worktree("feature", "feature");
+ std::fs::write(feature_wt.join("feature.txt"), "initial 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", "feat: initial feature"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to commit");
+
+ // Now add uncommitted tracked changes
+ std::fs::write(feature_wt.join("feature.txt"), "modified content")
+ .expect("Failed to write file");
+
+ // Merge - should auto-commit with deterministic message (no LLM configured)
+ snapshot_merge(
+ "merge_auto_commit_deterministic",
+ &repo,
+ &["main"],
+ Some(&feature_wt),
+ );
+}
+
+#[test]
+fn test_merge_auto_commit_with_llm() {
+ 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 a commit
+ let feature_wt = repo.add_worktree("feature", "feature");
+ std::fs::write(feature_wt.join("auth.txt"), "initial auth").expect("Failed to write file");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["add", "auth.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", "feat: add authentication"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to commit");
+
+ // Now add uncommitted tracked changes
+ std::fs::write(feature_wt.join("auth.txt"), "improved auth with validation")
+ .expect("Failed to write file");
+
+ // Merge with LLM configured - should auto-commit with LLM-generated message
+ snapshot_merge_with_env(
+ "merge_auto_commit_with_llm",
+ &repo,
+ &["main"],
+ Some(&feature_wt),
+ &[
+ ("WORKTRUNK_LLM__COMMAND", "echo"),
+ ("WORKTRUNK_LLM__ARGS", "fix: improve auth validation logic"),
+ ],
+ );
+}
+
+#[test]
+fn test_merge_auto_commit_with_message() {
+ 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 a commit
+ let feature_wt = repo.add_worktree("feature", "feature");
+ std::fs::write(feature_wt.join("feature.txt"), "initial").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", "feat: start feature"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to commit");
+
+ // Add uncommitted tracked changes
+ std::fs::write(feature_wt.join("feature.txt"), "completed feature")
+ .expect("Failed to write file");
+
+ // Merge with -m flag (custom instruction) and LLM configured
+ snapshot_merge_with_env(
+ "merge_auto_commit_with_message",
+ &repo,
+ &["main", "-m", "Complete the user dashboard feature"],
+ Some(&feature_wt),
+ &[
+ ("WORKTRUNK_LLM__COMMAND", "echo"),
+ ("WORKTRUNK_LLM__ARGS", "feat: complete user dashboard"),
+ ],
+ );
+}
+
+#[test]
+fn test_merge_auto_commit_and_squash() {
+ 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 multiple commits
+ let feature_wt = repo.add_worktree("feature", "feature");
+
+ // First commit
+ std::fs::write(feature_wt.join("file1.txt"), "content 1").expect("Failed to write file");
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["add", "file1.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", "feat: add file 1"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to commit");
+
+ // Second commit
+ std::fs::write(feature_wt.join("file2.txt"), "content 2").expect("Failed to write file");
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["add", "file2.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", "feat: add file 2"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to commit");
+
+ // Add uncommitted tracked changes
+ std::fs::write(feature_wt.join("file1.txt"), "updated content 1")
+ .expect("Failed to write file");
+
+ // Merge with --squash - should auto-commit first, then squash all commits including the new one
+ snapshot_merge_with_env(
+ "merge_auto_commit_and_squash",
+ &repo,
+ &["main", "--squash"],
+ Some(&feature_wt),
+ &[
+ ("WORKTRUNK_LLM__COMMAND", "echo"),
+ // First message is for auto-commit
+ ("WORKTRUNK_LLM__ARGS", "fix: update file 1 content"),
+ ],
+ );
+}
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snap
index afabe5170..c4491b84f 100644
--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap
@@ -290,12 +290,20 @@ _wt() {
return 0
;;
wt__merge)
- opts="-s -k -h --squash --keep --help [TARGET]"
+ opts="-s -k -m -h --squash --keep --message --help [TARGET]"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ --message)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
+ -m)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap
index cf08a97bd..bccc4c664 100644
--- a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap
@@ -292,12 +292,20 @@ _wt() {
return 0
;;
wt__merge)
- opts="-s -k -h --squash --keep --help [TARGET]"
+ opts="-s -k -m -h --squash --keep --message --help [TARGET]"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ --message)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
+ -m)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snap
index 562c66b23..497b6bad8 100644
--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap
@@ -175,6 +175,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 h -l help -d 'Print help'
complete -c wt -n "__fish_wt_using_subcommand push" -l allow-merge-commits -d 'Allow pushing merge commits (non-linear history)'
complete -c wt -n "__fish_wt_using_subcommand push" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand merge" -s m -l message -d 'Custom instruction for commit message generation' -r
complete -c wt -n "__fish_wt_using_subcommand merge" -s s -l squash -d 'Squash all commits into one before merging'
complete -c wt -n "__fish_wt_using_subcommand merge" -s k -l keep -d 'Keep worktree after merging (don\'t remove)'
complete -c wt -n "__fish_wt_using_subcommand merge" -s h -l help -d 'Print help'
diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
index a73102de4..a428af151 100644
--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
@@ -217,6 +217,8 @@ _arguments "${_arguments_options[@]}" : \
;;
(merge)
_arguments "${_arguments_options[@]}" : \
+'-m+[Custom instruction for commit message generation]:MESSAGE:_default' \
+'--message=[Custom instruction for commit message generation]:MESSAGE:_default' \
'-s[Squash all commits into one before merging]' \
'--squash[Squash all commits into one before merging]' \
'-k[Keep worktree after merging (don'\''t remove)]' \
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap
new file mode 100644
index 000000000..afa916776
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap
@@ -0,0 +1,49 @@
+---
+source: tests/integration_tests/merge.rs
+info:
+ program: wt
+ args:
+ - merge
+ - main
+ - "--squash"
+ env:
+ CLICOLOR_FORCE: "1"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_LLM__ARGS: "fix: update file 1 content"
+ WORKTRUNK_LLM__COMMAND: echo
+---
+success: true
+exit_code: 0
+----- stdout -----
+πŸ”„ Committing uncommitted changes...
+βœ… Committed changes
+πŸ”„ Squashing 3 commits into one...
+βœ… Squashed 3 commits into one
+πŸ”„ Rebasing onto main...
+πŸ”„ Pushing 1 commit to main @ [SHA]
+
+* aaf1370 (HEAD -> feature) Squash commits from main
+
+ file1.txt | 1 +
+ file2.txt | 1 +
+ 2 files changed, 2 insertions(+)
+
+βœ… Pushed to main (1 commit, 2 files, +2) 
+πŸ”„ Cleaning up worktree...
+βœ… Removed worktree and returned to primary
+ Path: [REPO]
+
+To enable automatic cd, run: wt configure-shell
+
+βœ… Merge complete
+
+----- stderr -----
+🟑 LLM generation failed, using deterministic message
+🟑 LLM generation failed, using deterministic message
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap
new file mode 100644
index 000000000..e1a43bb25
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap
@@ -0,0 +1,43 @@
+---
+source: tests/integration_tests/merge.rs
+info:
+ program: wt
+ args:
+ - merge
+ - main
+ env:
+ CLICOLOR_FORCE: "1"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1704067200"
+---
+success: true
+exit_code: 0
+----- stdout -----
+πŸ”„ Committing uncommitted changes...
+βœ… Committed changes
+πŸ”„ Rebasing onto main...
+πŸ”„ Pushing 2 commits to main @ [SHA]
+
+* d03931d (HEAD -> feature) WIP: Auto-commit before merge
+* 0f80f56 feat: initial feature
+
+ feature.txt | 1 +
+ 1 file changed, 1 insertion(+)
+
+βœ… Pushed to main (2 commits, 1 file, +1) 
+πŸ”„ Cleaning up worktree...
+βœ… Removed worktree and returned to primary
+ Path: [REPO]
+
+To enable automatic cd, run: wt configure-shell
+
+βœ… Merge complete
+
+----- stderr -----
+🟑 LLM generation failed, using deterministic message
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap
new file mode 100644
index 000000000..ee3e2268f
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap
@@ -0,0 +1,45 @@
+---
+source: tests/integration_tests/merge.rs
+info:
+ program: wt
+ args:
+ - merge
+ - main
+ env:
+ CLICOLOR_FORCE: "1"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_LLM__ARGS: "fix: improve auth validation logic"
+ WORKTRUNK_LLM__COMMAND: echo
+---
+success: true
+exit_code: 0
+----- stdout -----
+πŸ”„ Committing uncommitted changes...
+βœ… Committed changes
+πŸ”„ Rebasing onto main...
+πŸ”„ Pushing 2 commits to main @ [SHA]
+
+* a9b74e2 (HEAD -> feature) WIP: Auto-commit before merge
+* 274308f feat: add authentication
+
+ auth.txt | 1 +
+ 1 file changed, 1 insertion(+)
+
+βœ… Pushed to main (2 commits, 1 file, +1) 
+πŸ”„ Cleaning up worktree...
+βœ… Removed worktree and returned to primary
+ Path: [REPO]
+
+To enable automatic cd, run: wt configure-shell
+
+βœ… Merge complete
+
+----- stderr -----
+🟑 LLM generation failed, using deterministic message
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_message.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_message.snap
new file mode 100644
index 000000000..26b365cb2
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_message.snap
@@ -0,0 +1,47 @@
+---
+source: tests/integration_tests/merge.rs
+info:
+ program: wt
+ args:
+ - merge
+ - main
+ - "-m"
+ - Complete the user dashboard feature
+ env:
+ CLICOLOR_FORCE: "1"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_LLM__ARGS: "feat: complete user dashboard"
+ WORKTRUNK_LLM__COMMAND: echo
+---
+success: true
+exit_code: 0
+----- stdout -----
+πŸ”„ Committing uncommitted changes...
+βœ… Committed changes
+πŸ”„ Rebasing onto main...
+πŸ”„ Pushing 2 commits to main @ [SHA]
+
+* 9440cbc (HEAD -> feature) WIP: Auto-commit before merge
+* 24c9965 feat: start feature
+
+ feature.txt | 1 +
+ 1 file changed, 1 insertion(+)
+
+βœ… Pushed to main (2 commits, 1 file, +1) 
+πŸ”„ Cleaning up worktree...
+βœ… Removed worktree and returned to primary
+ Path: [REPO]
+
+To enable automatic cd, run: wt configure-shell
+
+βœ… Merge complete
+
+----- stderr -----
+🟑 LLM generation failed, using deterministic message
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snap b/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snap
index 769925f1b..9279f6a70 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_dirty_working_tree.snap
@@ -19,8 +19,9 @@ info:
success: false
exit_code: 1
----- stdout -----
+πŸ”„ Committing uncommitted changes...
----- stderr -----
-❌ Working tree has uncommitted changes
+❌ Working tree has untracked files
-πŸ’‘ Commit or stash them first
+πŸ’‘ Add them with 'git add' and try again