Skip to content

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

Refactor: Move approved commands to project config

Maximilian Roos6384748de28c
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index d72102053..e3d7e710a 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -2,7 +2,7 @@
//!
//! Shared helpers for approving commands declared in project configuration.
-use worktrunk::config::{ApprovedCommand, WorktrunkConfig};
+use worktrunk::config::WorktrunkConfig;
use worktrunk::git::{GitError, GitResultExt};
use worktrunk::styling::{
AnstyleStyle, HINT_EMOJI, WARNING, WARNING_EMOJI, eprint, eprintln, format_bash_with_gutter,
@@ -42,13 +42,16 @@ pub fn approve_command_batch(
let mut fresh_config = WorktrunkConfig::load().git_context("Failed to reload config")?;
+ // Get or create the project entry once, outside the loop
+ let project_entry = fresh_config
+ .projects
+ .entry(project_id.to_string())
+ .or_default();
+
let mut updated = false;
for (_, command) in needs_approval {
- if !fresh_config.is_command_approved(project_id, command) {
- fresh_config.approved_commands.push(ApprovedCommand {
- project: project_id.to_string(),
- command: command.to_string(),
- });
+ if !project_entry.approved_commands.iter().any(|c| c == command) {
+ project_entry.approved_commands.push(command.to_string());
updated = true;
}
}
diff --git a/src/config.rs b/src/config.rs
index 5c35d121c..3ed2a3489 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -70,6 +70,10 @@ use etcetera::base_strategy::{BaseStrategy, choose_base_strategy};
/// [commit-generation]
/// command = "llm" # Command to invoke for generating commit messages (e.g., "llm", "claude")
/// args = ["-s"] # Arguments to pass to the command
+///
+/// # Per-project configuration
+/// [projects."github.com/user/repo"]
+/// approved-commands = ["npm install", "npm test"]
/// ```
///
/// Config file location:
@@ -86,9 +90,10 @@ pub struct WorktrunkConfig {
#[serde(default, rename = "commit-generation")]
pub commit_generation: CommitGenerationConfig,
- /// Commands that have been approved for automatic execution
- #[serde(default, rename = "approved-commands")]
- pub approved_commands: Vec<ApprovedCommand>,
+ /// Per-project configuration (approved commands, etc.)
+ /// Uses BTreeMap for deterministic serialization order and better diff readability
+ #[serde(default)]
+ pub projects: std::collections::BTreeMap<String, UserProjectConfig>,
}
/// Configuration for commit message generation
@@ -282,13 +287,31 @@ impl Serialize for CommandConfig {
}
}
-/// Approved command for automatic execution
-#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
-pub struct ApprovedCommand {
- /// Project identifier (git remote URL or repo name)
- pub project: String,
- /// Command that was approved
- pub command: String,
+/// Per-project user configuration
+///
+/// Stored in the user's config file under `[projects."project-id"]`.
+/// Contains project-specific settings that are user preferences, not checked into git.
+///
+/// # TOML Format
+/// ```toml
+/// [projects."github.com/user/repo"]
+/// approved-commands = ["npm install", "npm test"]
+/// ```
+///
+/// # Future Extensibility
+/// This structure is designed to accommodate additional per-project settings:
+/// - default-target-branch
+/// - auto-squash preferences
+/// - project-specific hooks
+#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
+pub struct UserProjectConfig {
+ /// Commands that have been approved for automatic execution in this project
+ #[serde(
+ default,
+ rename = "approved-commands",
+ skip_serializing_if = "Vec::is_empty"
+ )]
+ pub approved_commands: Vec<String>,
}
impl Default for WorktrunkConfig {
@@ -296,7 +319,7 @@ impl Default for WorktrunkConfig {
Self {
worktree_path: "../{main-worktree}.{branch}".to_string(),
commit_generation: CommitGenerationConfig::default(),
- approved_commands: Vec::new(),
+ projects: std::collections::BTreeMap::new(),
}
}
}
@@ -526,9 +549,10 @@ impl ProjectConfig {
impl WorktrunkConfig {
/// Check if a command is approved for the given project
pub fn is_command_approved(&self, project: &str, command: &str) -> bool {
- self.approved_commands
- .iter()
- .any(|ac| ac.project == project && ac.command == command)
+ self.projects
+ .get(project)
+ .map(|p| p.approved_commands.iter().any(|c| c == command))
+ .unwrap_or(false)
}
/// Add an approved command and save to config file
@@ -538,8 +562,11 @@ impl WorktrunkConfig {
return Ok(());
}
- self.approved_commands
- .push(ApprovedCommand { project, command });
+ self.projects
+ .entry(project)
+ .or_default()
+ .approved_commands
+ .push(command);
self.save()
}
@@ -559,11 +586,92 @@ impl WorktrunkConfig {
return Ok(());
}
- self.approved_commands
- .push(ApprovedCommand { project, command });
+ self.projects
+ .entry(project)
+ .or_default()
+ .approved_commands
+ .push(command);
self.save_to(config_path)
}
+ /// Revoke an approved command and save to config file
+ ///
+ /// Removes the specified command from the project's approved commands list.
+ /// If this results in an empty project entry, the project is removed entirely.
+ pub fn revoke_command(&mut self, project: &str, command: &str) -> Result<(), ConfigError> {
+ if let Some(project_config) = self.projects.get_mut(project) {
+ let len_before = project_config.approved_commands.len();
+ project_config.approved_commands.retain(|c| c != command);
+ let changed = len_before != project_config.approved_commands.len();
+
+ // Clean up empty project entries
+ if project_config.approved_commands.is_empty() {
+ self.projects.remove(project);
+ }
+
+ if changed {
+ self.save()?;
+ }
+ }
+ Ok(())
+ }
+
+ /// Remove all approvals for a project and save to config file
+ ///
+ /// Removes the entire project entry from the configuration.
+ pub fn revoke_project(&mut self, project: &str) -> Result<(), ConfigError> {
+ if self.projects.remove(project).is_some() {
+ self.save()?;
+ }
+ Ok(())
+ }
+
+ /// Revoke an approved command and save to a specific config file (for testing)
+ ///
+ /// This is the same as `revoke_command()` but saves to an explicit path
+ /// instead of the default user config location. Use this in tests to avoid
+ /// polluting the user's actual config.
+ #[doc(hidden)]
+ pub fn revoke_command_to(
+ &mut self,
+ project: &str,
+ command: &str,
+ config_path: &std::path::Path,
+ ) -> Result<(), ConfigError> {
+ if let Some(project_config) = self.projects.get_mut(project) {
+ let len_before = project_config.approved_commands.len();
+ project_config.approved_commands.retain(|c| c != command);
+ let changed = len_before != project_config.approved_commands.len();
+
+ // Clean up empty project entries
+ if project_config.approved_commands.is_empty() {
+ self.projects.remove(project);
+ }
+
+ if changed {
+ self.save_to(config_path)?;
+ }
+ }
+ Ok(())
+ }
+
+ /// Remove all approvals for a project and save to a specific config file (for testing)
+ ///
+ /// This is the same as `revoke_project()` but saves to an explicit path
+ /// instead of the default user config location. Use this in tests to avoid
+ /// polluting the user's actual config.
+ #[doc(hidden)]
+ pub fn revoke_project_to(
+ &mut self,
+ project: &str,
+ config_path: &std::path::Path,
+ ) -> Result<(), ConfigError> {
+ if self.projects.remove(project).is_some() {
+ self.save_to(config_path)?;
+ }
+ Ok(())
+ }
+
/// Save the current configuration to the default config file location
pub fn save(&self) -> Result<(), ConfigError> {
let config_path = get_config_path()
@@ -637,7 +745,7 @@ mod tests {
let config = WorktrunkConfig::default();
assert_eq!(config.worktree_path, "../{main-worktree}.{branch}");
assert_eq!(config.commit_generation.command, None);
- assert!(config.approved_commands.is_empty());
+ assert!(config.projects.is_empty());
}
#[test]
@@ -645,7 +753,7 @@ mod tests {
let config = WorktrunkConfig {
worktree_path: "{main-worktree}.{branch}".to_string(),
commit_generation: CommitGenerationConfig::default(),
- approved_commands: Vec::new(),
+ projects: std::collections::BTreeMap::new(),
};
assert_eq!(
config.format_path("myproject", "feature-x"),
@@ -658,7 +766,7 @@ mod tests {
let config = WorktrunkConfig {
worktree_path: "{main-worktree}-{branch}".to_string(),
commit_generation: CommitGenerationConfig::default(),
- approved_commands: Vec::new(),
+ projects: std::collections::BTreeMap::new(),
};
assert_eq!(
config.format_path("myproject", "feature-x"),
@@ -671,7 +779,7 @@ mod tests {
let config = WorktrunkConfig {
worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),
commit_generation: CommitGenerationConfig::default(),
- approved_commands: Vec::new(),
+ projects: std::collections::BTreeMap::new(),
};
assert_eq!(
config.format_path("myproject", "feature-x"),
@@ -685,7 +793,7 @@ mod tests {
let config = WorktrunkConfig {
worktree_path: "{main-worktree}.{branch}".to_string(),
commit_generation: CommitGenerationConfig::default(),
- approved_commands: Vec::new(),
+ projects: std::collections::BTreeMap::new(),
};
assert_eq!(
config.format_path("myproject", "feature/foo"),
@@ -698,7 +806,7 @@ mod tests {
let config = WorktrunkConfig {
worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),
commit_generation: CommitGenerationConfig::default(),
- approved_commands: Vec::new(),
+ projects: std::collections::BTreeMap::new(),
};
assert_eq!(
config.format_path("myproject", "feature/sub/task"),
@@ -712,7 +820,7 @@ mod tests {
let config = WorktrunkConfig {
worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),
commit_generation: CommitGenerationConfig::default(),
- approved_commands: Vec::new(),
+ projects: std::collections::BTreeMap::new(),
};
assert_eq!(
config.format_path("myproject", "feature\\foo"),
@@ -885,30 +993,29 @@ mod tests {
}
#[test]
- fn test_approved_command_equality() {
- let cmd1 = ApprovedCommand {
- project: "github.com/user/repo".to_string(),
- command: "npm install".to_string(),
+ fn test_user_project_config_equality() {
+ let config1 = UserProjectConfig {
+ approved_commands: vec!["npm install".to_string()],
};
- let cmd2 = ApprovedCommand {
- project: "github.com/user/repo".to_string(),
- command: "npm install".to_string(),
+ let config2 = UserProjectConfig {
+ approved_commands: vec!["npm install".to_string()],
};
- let cmd3 = ApprovedCommand {
- project: "github.com/user/repo".to_string(),
- command: "npm test".to_string(),
+ let config3 = UserProjectConfig {
+ approved_commands: vec!["npm test".to_string()],
};
- assert_eq!(cmd1, cmd2);
- assert_ne!(cmd1, cmd3);
+ assert_eq!(config1, config2);
+ assert_ne!(config1, config3);
}
#[test]
fn test_is_command_approved() {
let mut config = WorktrunkConfig::default();
- config.approved_commands.push(ApprovedCommand {
- project: "github.com/user/repo".to_string(),
- command: "npm install".to_string(),
- });
+ config.projects.insert(
+ "github.com/user/repo".to_string(),
+ UserProjectConfig {
+ approved_commands: vec!["npm install".to_string()],
+ },
+ );
assert!(config.is_command_approved("github.com/user/repo", "npm install"));
assert!(!config.is_command_approved("github.com/user/repo", "npm test"));
@@ -935,7 +1042,91 @@ mod tests {
assert!(config.is_command_approved("github.com/user/repo", "npm install"));
// Duplicate approval shouldn't add twice
- let count_before = config.approved_commands.len();
+ let count_before = config
+ .projects
+ .get("github.com/user/repo")
+ .unwrap()
+ .approved_commands
+ .len();
+ config
+ .approve_command_to(
+ "github.com/user/repo".to_string(),
+ "npm install".to_string(),
+ &config_path,
+ )
+ .unwrap();
+ assert_eq!(
+ config
+ .projects
+ .get("github.com/user/repo")
+ .unwrap()
+ .approved_commands
+ .len(),
+ count_before
+ );
+ }
+
+ #[test]
+ fn test_revoke_command() {
+ use tempfile::TempDir;
+
+ let temp_dir = TempDir::new().unwrap();
+ let config_path = temp_dir.path().join("test-config.toml");
+
+ let mut config = WorktrunkConfig::default();
+
+ // Set up two approved commands
+ config
+ .approve_command_to(
+ "github.com/user/repo".to_string(),
+ "npm install".to_string(),
+ &config_path,
+ )
+ .unwrap();
+ config
+ .approve_command_to(
+ "github.com/user/repo".to_string(),
+ "npm test".to_string(),
+ &config_path,
+ )
+ .unwrap();
+
+ assert!(config.is_command_approved("github.com/user/repo", "npm install"));
+ assert!(config.is_command_approved("github.com/user/repo", "npm test"));
+
+ // Revoke one command
+ config
+ .revoke_command_to("github.com/user/repo", "npm install", &config_path)
+ .unwrap();
+ assert!(!config.is_command_approved("github.com/user/repo", "npm install"));
+ assert!(config.is_command_approved("github.com/user/repo", "npm test"));
+
+ // Project entry should still exist
+ assert!(config.projects.contains_key("github.com/user/repo"));
+
+ // Revoke the last command - should remove the project entry
+ config
+ .revoke_command_to("github.com/user/repo", "npm test", &config_path)
+ .unwrap();
+ assert!(!config.is_command_approved("github.com/user/repo", "npm test"));
+ assert!(!config.projects.contains_key("github.com/user/repo"));
+ }
+
+ #[test]
+ fn test_revoke_command_nonexistent() {
+ use tempfile::TempDir;
+
+ let temp_dir = TempDir::new().unwrap();
+ let config_path = temp_dir.path().join("test-config.toml");
+
+ let mut config = WorktrunkConfig::default();
+
+ // Revoking from non-existent project is a no-op
+ config
+ .revoke_command_to("github.com/user/repo", "npm install", &config_path)
+ .unwrap();
+
+ // Set up one command
config
.approve_command_to(
"github.com/user/repo".to_string(),
@@ -943,7 +1134,63 @@ mod tests {
&config_path,
)
.unwrap();
- assert_eq!(config.approved_commands.len(), count_before);
+
+ // Revoking non-existent command is a no-op
+ config
+ .revoke_command_to("github.com/user/repo", "npm test", &config_path)
+ .unwrap();
+ assert!(config.is_command_approved("github.com/user/repo", "npm install"));
+ }
+
+ #[test]
+ fn test_revoke_project() {
+ use tempfile::TempDir;
+
+ let temp_dir = TempDir::new().unwrap();
+ let config_path = temp_dir.path().join("test-config.toml");
+
+ let mut config = WorktrunkConfig::default();
+
+ // Set up multiple projects
+ config
+ .approve_command_to(
+ "github.com/user/repo1".to_string(),
+ "npm install".to_string(),
+ &config_path,
+ )
+ .unwrap();
+ config
+ .approve_command_to(
+ "github.com/user/repo1".to_string(),
+ "npm test".to_string(),
+ &config_path,
+ )
+ .unwrap();
+ config
+ .approve_command_to(
+ "github.com/user/repo2".to_string(),
+ "cargo build".to_string(),
+ &config_path,
+ )
+ .unwrap();
+
+ assert!(config.projects.contains_key("github.com/user/repo1"));
+ assert!(config.projects.contains_key("github.com/user/repo2"));
+
+ // Revoke entire project
+ config
+ .revoke_project_to("github.com/user/repo1", &config_path)
+ .unwrap();
+ assert!(!config.projects.contains_key("github.com/user/repo1"));
+ assert!(config.projects.contains_key("github.com/user/repo2"));
+
+ // Revoking non-existent project is a no-op
+ config
+ .revoke_project_to("github.com/user/repo1", &config_path)
+ .unwrap();
+ config
+ .revoke_project_to("github.com/nonexistent/repo", &config_path)
+ .unwrap();
}
#[test]
diff --git a/tests/integration_tests/approval_save.rs b/tests/integration_tests/approval_save.rs
index 611264ee6..0fb28ff74 100644
--- a/tests/integration_tests/approval_save.rs
+++ b/tests/integration_tests/approval_save.rs
@@ -38,9 +38,8 @@ fn test_approval_saves_to_disk() {
[commit-generation]
args = []
- [[approved-commands]]
- project = "github.com/test/repo"
- command = "test command"
+ [projects."github.com/test/repo"]
+ approved-commands = ["test command"]
"#);
// Verify approval is in memory
@@ -72,13 +71,18 @@ fn test_duplicate_approvals_not_saved_twice() {
.ok();
// Verify only one entry exists
- let matching_approvals: Vec<_> = config
- .approved_commands
- .iter()
- .filter(|ac| ac.project == "github.com/test/repo" && ac.command == "test")
- .collect();
-
- assert_eq!(matching_approvals.len(), 1, "Duplicate approval was saved");
+ let matching_commands = config
+ .projects
+ .get("github.com/test/repo")
+ .map(|p| {
+ p.approved_commands
+ .iter()
+ .filter(|cmd| *cmd == "test")
+ .count()
+ })
+ .unwrap_or(0);
+
+ assert_eq!(matching_commands, 1, "Duplicate approval was saved");
// Verify file contains only one entry
let toml_content = fs::read_to_string(&config_path).unwrap();
@@ -88,9 +92,8 @@ fn test_duplicate_approvals_not_saved_twice() {
[commit-generation]
args = []
- [[approved-commands]]
- project = "github.com/test/repo"
- command = "test"
+ [projects."github.com/test/repo"]
+ approved-commands = ["test"]
"#);
}
@@ -139,17 +142,14 @@ fn test_multiple_project_approvals() {
[commit-generation]
args = []
- [[approved-commands]]
- project = "github.com/user1/repo1"
- command = "npm install"
-
- [[approved-commands]]
- project = "github.com/user2/repo2"
- command = "cargo build"
+ [projects."github.com/user1/repo1"]
+ approved-commands = [
+ "npm install",
+ "npm test",
+ ]
- [[approved-commands]]
- project = "github.com/user1/repo1"
- command = "npm test"
+ [projects."github.com/user2/repo2"]
+ approved-commands = ["cargo build"]
"#);
}
@@ -234,9 +234,8 @@ fn test_force_flag_saves_approval() {
[commit-generation]
args = []
- [[approved-commands]]
- project = "github.com/test/force-repo"
- command = "test --force command"
+ [projects."github.com/test/force-repo"]
+ approved-commands = ["test --force command"]
"#);
}
@@ -272,8 +271,7 @@ fn test_force_flag_saves_to_new_config_file() {
[commit-generation]
args = []
- [[approved-commands]]
- project = "github.com/test/nested"
- command = "test command"
+ [projects."github.com/test/nested"]
+ approved-commands = ["test command"]
"#);
}
diff --git a/tests/integration_tests/e2e_shell_post_start.rs b/tests/integration_tests/e2e_shell_post_start.rs
index cc46415b5..7aee36003 100644
--- a/tests/integration_tests/e2e_shell_post_start.rs
+++ b/tests/integration_tests/e2e_shell_post_start.rs
@@ -143,9 +143,8 @@ fn test_e2e_post_start_background_command(#[case] shell: &str) {
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "sleep 0.5 && echo 'Background task done' > bg_marker.txt"
+[projects."test-repo"]
+approved-commands = ["sleep 0.5 && echo 'Background task done' > bg_marker.txt"]
"#,
)
.expect("Failed to write user config");
@@ -270,13 +269,11 @@ task2 = "sleep 0.5 && echo 'Task 2' > task2.txt"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "sleep 0.5 && echo 'Task 1' > task1.txt"
-
-[[approved-commands]]
-project = "test-repo"
-command = "sleep 0.5 && echo 'Task 2' > task2.txt"
+[projects."test-repo"]
+approved-commands = [
+ "sleep 0.5 && echo 'Task 1' > task1.txt",
+ "sleep 0.5 && echo 'Task 2' > task2.txt",
+]
"#,
)
.expect("Failed to write test config");
@@ -353,9 +350,8 @@ fn test_bash_post_create_blocks() {
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Setup done' > setup.txt"
+[projects."test-repo"]
+approved-commands = ["echo 'Setup done' > setup.txt"]
"#,
)
.expect("Failed to write test config");
@@ -436,9 +432,8 @@ fish_bg = "sleep 0.5 && echo 'Fish background done' > fish_bg.txt"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "sleep 0.5 && echo 'Fish background done' > fish_bg.txt"
+[projects."test-repo"]
+approved-commands = ["sleep 0.5 && echo 'Fish background done' > fish_bg.txt"]
"#,
)
.expect("Failed to write test config");
diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rs
index 99ecf46ad..ce28a113b 100644
--- a/tests/integration_tests/post_start_commands.rs
+++ b/tests/integration_tests/post_start_commands.rs
@@ -62,9 +62,8 @@ fn test_post_create_single_command() {
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Setup complete'"
+[projects."test-repo"]
+approved-commands = ["echo 'Setup complete'"]
"#,
)
.expect("Failed to write test config");
@@ -98,13 +97,11 @@ fn test_post_create_multiple_commands_array() {
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'First'"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Second'"
+[projects."test-repo"]
+approved-commands = [
+ "echo 'First'",
+ "echo 'Second'",
+]
"#,
)
.expect("Failed to write user config");
@@ -141,13 +138,11 @@ setup = "echo 'Running setup'"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Installing deps'"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Running setup'"
+[projects."test-repo"]
+approved-commands = [
+ "echo 'Installing deps'",
+ "echo 'Running setup'",
+]
"#,
)
.expect("Failed to write user config");
@@ -181,9 +176,8 @@ fn test_post_create_failing_command() {
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "exit 1"
+[projects."test-repo"]
+approved-commands = ["exit 1"]
"#,
)
.expect("Failed to write user config");
@@ -223,21 +217,13 @@ fn test_post_create_template_expansion() {
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Repo: {main-worktree}' > info.txt"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Branch: {branch}' >> info.txt"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Worktree: {worktree}' >> info.txt"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Root: {repo_root}' >> info.txt"
+[projects."test-repo"]
+approved-commands = [
+ "echo 'Repo: {main-worktree}' > info.txt",
+ "echo 'Branch: {branch}' >> info.txt",
+ "echo 'Worktree: {worktree}' >> info.txt",
+ "echo 'Root: {repo_root}' >> info.txt",
+]
"#,
)
.expect("Failed to write test config");
@@ -302,9 +288,8 @@ fn test_post_start_single_background_command() {
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "sleep 1 && echo 'Background task done' > background.txt"
+[projects."test-repo"]
+approved-commands = ["sleep 1 && echo 'Background task done' > background.txt"]
"#,
)
.expect("Failed to write user config");
@@ -357,13 +342,11 @@ task2 = "echo 'Task 2 running' > task2.txt"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Task 1 running' > task1.txt"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Task 2 running' > task2.txt"
+[projects."test-repo"]
+approved-commands = [
+ "echo 'Task 1 running' > task1.txt",
+ "echo 'Task 2 running' > task2.txt",
+]
"#,
)
.expect("Failed to write user config");
@@ -409,13 +392,11 @@ server = "sleep 0.5 && echo 'Server running' > server.txt"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Setup done' > setup.txt"
-
-[[approved-commands]]
-project = "test-repo"
-command = "sleep 0.5 && echo 'Server running' > server.txt"
+[projects."test-repo"]
+approved-commands = [
+ "echo 'Setup done' > setup.txt",
+ "sleep 0.5 && echo 'Server running' > server.txt",
+]
"#,
)
.expect("Failed to write user config");
@@ -485,9 +466,8 @@ fn test_post_start_log_file_captures_output() {
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'stdout output' && echo 'stderr output' >&2"
+[projects."test-repo"]
+approved-commands = ["echo 'stdout output' && echo 'stderr output' >&2"]
"#,
)
.expect("Failed to write user config");
@@ -552,9 +532,8 @@ fn test_post_start_invalid_command_handling() {
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'unclosed quote"
+[projects."test-repo"]
+approved-commands = ["echo 'unclosed quote"]
"#,
)
.expect("Failed to write user config");
@@ -599,17 +578,12 @@ task3 = "echo 'TASK3_OUTPUT'"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'TASK1_OUTPUT'"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'TASK2_OUTPUT'"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'TASK3_OUTPUT'"
+[projects."test-repo"]
+approved-commands = [
+ "echo 'TASK1_OUTPUT'",
+ "echo 'TASK2_OUTPUT'",
+ "echo 'TASK3_OUTPUT'",
+]
"#,
)
.expect("Failed to write user config");
@@ -693,9 +667,8 @@ fn test_execute_flag_with_post_start_commands() {
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Background task' > background.txt"
+[projects."test-repo"]
+approved-commands = ["echo 'Background task' > background.txt"]
"#,
)
.expect("Failed to write user config");
@@ -751,9 +724,8 @@ fn test_post_start_complex_shell_commands() {
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'line1\nline2\nline3' | grep line2 > filtered.txt"
+[projects."test-repo"]
+approved-commands = ["echo 'line1\nline2\nline3' | grep line2 > filtered.txt"]
"#,
)
.expect("Failed to write user config");
@@ -806,10 +778,9 @@ echo 'third line' >> multiline.txt
format!(
r#"worktree-path = "../{{main-worktree}}.{{branch}}"
-[[approved-commands]]
-project = "test-repo"
-command = """
-{}"""
+[projects."test-repo"]
+approved-commands = ["""
+{}"""]
"#,
multiline_cmd
),
@@ -876,10 +847,9 @@ fi
format!(
r#"worktree-path = "../{{main-worktree}}.{{branch}}"
-[[approved-commands]]
-project = "test-repo"
-command = """
-{}"""
+[projects."test-repo"]
+approved-commands = ["""
+{}"""]
"#,
multiline_cmd
),
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index 87a1c4514..6601a332e 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -523,21 +523,13 @@ watch = "echo 'Watching for file changes'"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Installing dependencies...'"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Building project...'"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Starting dev server on port 3000'"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'Watching for file changes'"
+[projects."test-repo"]
+approved-commands = [
+ "echo 'Installing dependencies...'",
+ "echo 'Building project...'",
+ "echo 'Starting dev server on port 3000'",
+ "echo 'Watching for file changes'",
+]
"#,
)
.expect("Failed to write user config");
@@ -611,17 +603,12 @@ test = "echo '✓ All 47 tests passed in 2.3s'"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo '✓ Code formatting check passed'"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo '✓ Linting passed - no warnings'"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo '✓ All 47 tests passed in 2.3s'"
+[projects."test-repo"]
+approved-commands = [
+ "echo '✓ Code formatting check passed'",
+ "echo '✓ Linting passed - no warnings'",
+ "echo '✓ All 47 tests passed in 2.3s'",
+]
"#,
)
.expect("Failed to write user config");
@@ -696,13 +683,11 @@ test = "echo '✗ Test suite failed: 3 tests failing' && exit 1"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo '✓ Code formatting check passed'"
-
-[[approved-commands]]
-project = "test-repo"
-command = "echo '✗ Test suite failed: 3 tests failing' && exit 1"
+[projects."test-repo"]
+approved-commands = [
+ "echo '✓ Code formatting check passed'",
+ "echo '✗ Test suite failed: 3 tests failing' && exit 1",
+]
"#,
)
.expect("Failed to write user config");
@@ -746,9 +731,8 @@ command = "echo '✗ Test suite failed: 3 tests failing' && exit 1"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'test command executed'"
+[projects."test-repo"]
+approved-commands = ["echo 'test command executed'"]
"#,
)
.expect("Failed to write user config");
@@ -849,9 +833,8 @@ command = "echo 'test command executed'"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'background task'"
+[projects."test-repo"]
+approved-commands = ["echo 'background task'"]
"#,
)
.expect("Failed to write user config");
@@ -918,9 +901,8 @@ command = "echo 'background task'"
repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
-[[approved-commands]]
-project = "test-repo"
-command = "echo 'fish background task'"
+[projects."test-repo"]
+approved-commands = ["echo 'fish background task'"]
"#,
)
.expect("Failed to write user config");
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index ea19a9656..00d637e1e 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -331,9 +331,8 @@ fn test_switch_no_config_commands_skips_post_start_commands() {
format!(
r#"worktree-path = "../{{main-worktree}}.{{branch}}"
-[[approved-commands]]
-project = "main"
-command = "{}"
+[projects."main"]
+approved-commands = ["{}"]
"#,
create_file_cmd
),