Skip to content

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

WIP: Auto-commit before merge

Maximilian Roosa82b804ef5a7
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index a7e5b39ea..64045f622 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -45,13 +45,19 @@ pub fn command_config_to_vec(
///
/// Returns `Ok(true)` if the command is approved (either already approved or user approved it),
/// `Ok(false)` if the user declined, or `Err` if there was a system error.
+///
+/// # Arguments
+/// * `from_project_config` - If true, command is from project config (.config/wt.toml)
+/// and auto-approved without prompting (since it's checked into the repo)
pub fn check_and_approve_command(
project_id: &str,
command: &str,
config: &WorktrunkConfig,
force: bool,
+ from_project_config: bool,
) -> Result<bool, GitError> {
- if force || config.is_command_approved(project_id, command) {
+ // Project config commands are implicitly trusted (they're checked into the repo)
+ if from_project_config || force || config.is_command_approved(project_id, command) {
return Ok(true);
}
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index dd031de06..272a25db6 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -63,6 +63,7 @@ pub fn handle_merge(
&repo,
&config,
force,
+ internal,
)?;
}
@@ -90,8 +91,10 @@ pub fn handle_merge(
// Finish worktree unless --keep was specified
if !keep {
- let cyan = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)));
- println!("πŸ”„ {cyan}Cleaning up worktree...{cyan:#}");
+ if !internal {
+ let cyan = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)));
+ println!("πŸ”„ {cyan}Cleaning up worktree...{cyan:#}");
+ }
// Get primary worktree path before finishing (while we can still run git commands)
let primary_worktree_dir = repo.main_worktree_root()?;
@@ -105,9 +108,13 @@ pub fn handle_merge(
let primary_repo = Repository::at(&primary_worktree_dir);
let new_branch = primary_repo.current_branch()?;
if new_branch.as_deref() != Some(&target_branch) {
- let cyan = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)));
- let cyan_bold = cyan.bold();
- println!("πŸ”„ {cyan}Switching to {cyan_bold}{target_branch}{cyan_bold:#}...{cyan:#}");
+ if !internal {
+ let cyan = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)));
+ let cyan_bold = cyan.bold();
+ println!(
+ "πŸ”„ {cyan}Switching to {cyan_bold}{target_branch}{cyan_bold:#}...{cyan:#}"
+ );
+ }
primary_repo
.run_command(&["switch", &target_branch])
.map_err(|e| {
@@ -327,6 +334,7 @@ fn run_pre_merge_checks(
repo: &Repository,
config: &WorktrunkConfig,
force: bool,
+ internal: bool,
) -> Result<(), GitError> {
let Some(pre_merge_config) = &project_config.pre_merge_check else {
return Ok(());
@@ -346,7 +354,8 @@ fn run_pre_merge_checks(
// Execute each command sequentially, fail-fast on errors
for (name, command) in commands {
- if !check_and_approve_command(&project_id, &command, config, force)? {
+ // Project config commands are automatically trusted (from .config/wt.toml)
+ if !check_and_approve_command(&project_id, &command, config, force, true)? {
let dim = AnstyleStyle::new().dimmed();
eprintln!("{dim}Skipping pre-merge check: {command}{dim:#}");
continue;
@@ -361,10 +370,12 @@ fn run_pre_merge_checks(
&repo_root,
);
- use std::io::Write;
- let cyan = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)));
- println!("πŸ”„ {cyan}Running pre-merge check '{name}'...{cyan:#}");
- let _ = std::io::stdout().flush();
+ if !internal {
+ use std::io::Write;
+ let cyan = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)));
+ println!("πŸ”„ {cyan}Running pre-merge check '{name}'...{cyan:#}");
+ let _ = std::io::stdout().flush();
+ }
if let Err(e) = execute_command_in_worktree(worktree_path, &expanded_command) {
eprintln!();
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index 5f24a3341..6b40fa284 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -409,7 +409,8 @@ fn execute_post_create_commands(
// Execute each command sequentially
for (name, command) in commands {
- if !check_and_approve_command(&project_id, &command, config, force)? {
+ // Project config commands are automatically trusted (from .config/wt.toml)
+ if !check_and_approve_command(&project_id, &command, config, force, true)? {
let dim = AnstyleStyle::new().dimmed();
eprintln!("{dim}Skipping command: {command}{dim:#}");
continue;
@@ -469,7 +470,8 @@ fn spawn_post_start_commands(
// Spawn each command as a detached background process
for (name, command) in commands {
- if !check_and_approve_command(&project_id, &command, config, force)? {
+ // Project config commands are automatically trusted (from .config/wt.toml)
+ if !check_and_approve_command(&project_id, &command, config, force, true)? {
let dim = AnstyleStyle::new().dimmed();
eprintln!("{dim}Skipping command: {command}{dim:#}");
continue;