Skip to content

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

feat: Add clear-approvals command with comprehensive snapshot tests

Maximilian Roos0722d37bd4e4
diff --git a/CLAUDE.md b/CLAUDE.md
index 14cd273df..0857155ad 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -529,6 +529,58 @@ print!("{}", format_with_gutter(&command));
The colored space at column 0 provides visual separation from surrounding text. Content starts at column 3 (gutter + 2 spaces) to align with emoji messages where the emoji (2 columns) + space (1 column) also starts content at column 3.
+### Snapshot Testing Requirement
+
+**CRITICAL: Every command output MUST have a snapshot test.**
+
+All user-facing command outputs must be covered by `insta` snapshot tests to ensure:
+- Output format remains consistent
+- Changes to messages are intentional and reviewable
+- ANSI codes, colors, and formatting are preserved correctly
+- Regression prevention for edge cases
+
+**Test location:** `tests/integration_tests/` with snapshots in `tests/snapshots/`
+
+**Pattern:**
+```rust
+use crate::common::{make_snapshot_cmd, setup_snapshot_settings, TestRepo};
+use insta_cmd::assert_cmd_snapshot;
+
+fn snapshot_command(test_name: &str, repo: &TestRepo, args: &[&str]) {
+ let settings = setup_snapshot_settings(repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(repo, "beta", &[], None);
+ cmd.arg("command-name").args(args);
+ assert_cmd_snapshot!(test_name, cmd);
+ });
+}
+
+#[test]
+fn test_command_success() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ snapshot_command("command_success", &repo, &[]);
+}
+
+#[test]
+fn test_command_no_data() {
+ let repo = TestRepo::new();
+ snapshot_command("command_no_data", &repo, &[]);
+}
+```
+
+**Required test cases:**
+- Success state with data
+- Success state with no data
+- Error states
+- Edge cases (empty input, max values, etc.)
+
+**When adding new commands:**
+1. Write snapshot tests BEFORE marking implementation complete
+2. Cover all message variations (success, info, warning, error)
+3. Test both with and without data/approvals/resources
+4. Include flag variations (e.g., `--global` vs default)
+
## Output System Architecture
### Two Output Modes
diff --git a/src/cli.rs b/src/cli.rs
index 769168c63..dae7fd16b 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -171,6 +171,13 @@ pub enum StandaloneCommand {
all: bool,
},
+ /// Clear approved commands from config
+ ClearApprovals {
+ /// Clear approvals from global config (all projects)
+ #[arg(short, long)]
+ global: bool,
+ },
+
/// Interactive worktree selector
///
/// Preview modes (toggle with 1/2/3):
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 87d04047a..49b2ab39b 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -28,8 +28,8 @@ pub use merge::handle_merge;
#[cfg(unix)]
pub use select::handle_select;
pub use standalone::{
- handle_rebase, handle_squash, handle_standalone_ask_approvals, handle_standalone_commit,
- handle_standalone_run_hook,
+ handle_rebase, handle_squash, handle_standalone_ask_approvals,
+ handle_standalone_clear_approvals, handle_standalone_commit, handle_standalone_run_hook,
};
pub use worktree::{handle_remove, handle_switch};
diff --git a/src/commands/standalone.rs b/src/commands/standalone.rs
index 0bbd665e7..7b391f6dc 100644
--- a/src/commands/standalone.rs
+++ b/src/commands/standalone.rs
@@ -372,3 +372,64 @@ pub fn handle_standalone_ask_approvals(force: bool, show_all: bool) -> Result<()
Ok(())
}
+
+/// Handle `wt beta clear-approvals` command - clear approved commands
+pub fn handle_standalone_clear_approvals(global: bool) -> Result<(), GitError> {
+ use worktrunk::config::WorktrunkConfig;
+
+ let mut config = WorktrunkConfig::load().git_context("Failed to load config")?;
+
+ if global {
+ // Clear all approvals for all projects
+ let project_count = config.projects.len();
+
+ if project_count == 0 {
+ let dim = worktrunk::styling::AnstyleStyle::new().dimmed();
+ crate::output::info(format!("{dim}No approvals to clear{dim:#}"))?;
+ return Ok(());
+ }
+
+ config.projects.clear();
+ config.save().git_context("Failed to save config")?;
+
+ use worktrunk::styling::GREEN;
+ crate::output::success(format!(
+ "{GREEN}Cleared approvals for {project_count} project{}{GREEN:#}",
+ if project_count == 1 { "" } else { "s" }
+ ))?;
+ } else {
+ // Clear approvals for current project (default)
+ let repo = Repository::current();
+ let project_id = repo.project_identifier()?;
+
+ // Check if project has any approvals
+ let had_approvals = config.projects.contains_key(&project_id);
+
+ if !had_approvals {
+ let dim = worktrunk::styling::AnstyleStyle::new().dimmed();
+ crate::output::info(format!(
+ "{dim}No approvals to clear for this project{dim:#}"
+ ))?;
+ return Ok(());
+ }
+
+ // Count approvals before removing
+ let approval_count = config
+ .projects
+ .get(&project_id)
+ .map(|p| p.approved_commands.len())
+ .unwrap_or(0);
+
+ config
+ .revoke_project(&project_id)
+ .git_context("Failed to clear project approvals")?;
+
+ use worktrunk::styling::GREEN;
+ crate::output::success(format!(
+ "{GREEN}Cleared {approval_count} approval{} for this project{GREEN:#}",
+ if approval_count == 1 { "" } else { "s" }
+ ))?;
+ }
+
+ Ok(())
+}
diff --git a/src/main.rs b/src/main.rs
index 96913e0d4..c15e4741c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,7 +21,8 @@ use commands::{
ConfigAction, handle_complete, handle_config_help, handle_config_init, handle_config_list,
handle_config_refresh_cache, handle_configure_shell, handle_init, handle_list, handle_merge,
handle_rebase, handle_remove, handle_squash, handle_standalone_ask_approvals,
- handle_standalone_commit, handle_standalone_run_hook, handle_switch,
+ handle_standalone_clear_approvals, handle_standalone_commit, handle_standalone_run_hook,
+ handle_switch,
};
use output::{execute_user_command, handle_remove_output, handle_switch_output};
@@ -176,6 +177,9 @@ fn main() {
StandaloneCommand::AskApprovals { force, all } => {
handle_standalone_ask_approvals(force, all)
}
+ StandaloneCommand::ClearApprovals { global } => {
+ handle_standalone_clear_approvals(global)
+ }
#[cfg(unix)]
StandaloneCommand::Select => handle_select(),
},
diff --git a/tests/integration_tests/approvals.rs b/tests/integration_tests/approvals.rs
new file mode 100644
index 000000000..3b1e117b5
--- /dev/null
+++ b/tests/integration_tests/approvals.rs
@@ -0,0 +1,205 @@
+//! Integration tests for ask-approvals and clear-approvals commands
+
+use crate::common::{TestRepo, make_snapshot_cmd, setup_snapshot_settings};
+use insta_cmd::assert_cmd_snapshot;
+use worktrunk::config::WorktrunkConfig;
+
+/// Helper to snapshot ask-approvals command
+fn snapshot_ask_approvals(test_name: &str, repo: &TestRepo, args: &[&str]) {
+ let settings = setup_snapshot_settings(repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(repo, "beta", &[], None);
+ cmd.arg("ask-approvals").args(args);
+ assert_cmd_snapshot!(test_name, cmd);
+ });
+}
+
+/// Helper to snapshot clear-approvals command
+fn snapshot_clear_approvals(test_name: &str, repo: &TestRepo, args: &[&str]) {
+ let settings = setup_snapshot_settings(repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(repo, "beta", &[], None);
+ cmd.arg("clear-approvals").args(args);
+ assert_cmd_snapshot!(test_name, cmd);
+ });
+}
+
+// ============================================================================
+// ask-approvals tests
+// ============================================================================
+
+#[test]
+fn test_ask_approvals_no_config() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ snapshot_ask_approvals("ask_approvals_no_config", &repo, &[]);
+}
+
+#[test]
+fn test_ask_approvals_force() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.write_project_config(r#"post-create-command = "echo 'test'""#);
+ repo.commit("Add config");
+
+ snapshot_ask_approvals("ask_approvals_force", &repo, &["--force"]);
+}
+
+#[test]
+fn test_ask_approvals_all_with_none_approved() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.write_project_config(r#"post-create-command = "echo 'test'""#);
+ repo.commit("Add config");
+
+ snapshot_ask_approvals("ask_approvals_all_none_approved", &repo, &["--all"]);
+}
+
+#[test]
+fn test_ask_approvals_empty_config() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.write_project_config("");
+ repo.commit("Add empty config");
+
+ snapshot_ask_approvals("ask_approvals_empty_config", &repo, &[]);
+}
+
+// ============================================================================
+// clear-approvals tests
+// ============================================================================
+
+#[test]
+fn test_clear_approvals_no_approvals() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ snapshot_clear_approvals("clear_approvals_no_approvals", &repo, &[]);
+}
+
+#[test]
+fn test_clear_approvals_with_approvals() {
+ let repo = TestRepo::new();
+ let project_id = format!("{}/origin", repo.root_path().display());
+ repo.commit("Initial commit");
+ repo.write_project_config(r#"post-create-command = "echo 'test'""#);
+ repo.commit("Add config");
+
+ // Manually approve the command by writing to test config
+ let mut config = WorktrunkConfig::default();
+ config
+ .approve_command_to(
+ project_id,
+ "echo 'test'".to_string(),
+ repo.test_config_path(),
+ )
+ .expect("Failed to save approval");
+
+ // Now clear approvals
+ snapshot_clear_approvals("clear_approvals_with_approvals", &repo, &[]);
+}
+
+#[test]
+fn test_clear_approvals_global_no_approvals() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ snapshot_clear_approvals("clear_approvals_global_no_approvals", &repo, &["--global"]);
+}
+
+#[test]
+fn test_clear_approvals_global_with_approvals() {
+ let repo = TestRepo::new();
+ let project_id = format!("{}/origin", repo.root_path().display());
+ repo.commit("Initial commit");
+ repo.write_project_config(r#"post-create-command = "echo 'test'""#);
+ repo.commit("Add config");
+
+ // Manually approve the command
+ let mut config = WorktrunkConfig::default();
+ config
+ .approve_command_to(
+ project_id,
+ "echo 'test'".to_string(),
+ repo.test_config_path(),
+ )
+ .expect("Failed to save approval");
+
+ // Now clear all global approvals
+ snapshot_clear_approvals(
+ "clear_approvals_global_with_approvals",
+ &repo,
+ &["--global"],
+ );
+}
+
+#[test]
+fn test_clear_approvals_after_clear() {
+ let repo = TestRepo::new();
+ let project_id = format!("{}/origin", repo.root_path().display());
+ repo.commit("Initial commit");
+ repo.write_project_config(r#"post-create-command = "echo 'test'""#);
+ repo.commit("Add config");
+
+ // Manually approve the command
+ let mut config = WorktrunkConfig::default();
+ config
+ .approve_command_to(
+ project_id.clone(),
+ "echo 'test'".to_string(),
+ repo.test_config_path(),
+ )
+ .expect("Failed to save approval");
+
+ // Clear approvals
+ let mut cmd = make_snapshot_cmd(&repo, "beta", &[], None);
+ cmd.arg("clear-approvals");
+ cmd.output().expect("Failed to clear approvals");
+
+ // Try to clear again (should show "no approvals")
+ snapshot_clear_approvals("clear_approvals_after_clear", &repo, &[]);
+}
+
+#[test]
+fn test_clear_approvals_multiple_approvals() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.write_project_config(
+ r#"
+post-create-command = "echo 'first'"
+post-start-command = "echo 'second'"
+[pre-commit-command]
+lint = "echo 'third'"
+"#,
+ );
+ repo.commit("Add config with multiple commands");
+
+ // Manually approve all commands
+ let project_id = format!("{}/origin", repo.root_path().display());
+ let mut config = WorktrunkConfig::default();
+ config
+ .approve_command_to(
+ project_id.clone(),
+ "echo 'first'".to_string(),
+ repo.test_config_path(),
+ )
+ .expect("Failed to save approval");
+ config
+ .approve_command_to(
+ project_id.clone(),
+ "echo 'second'".to_string(),
+ repo.test_config_path(),
+ )
+ .expect("Failed to save approval");
+ config
+ .approve_command_to(
+ project_id,
+ "echo 'third'".to_string(),
+ repo.test_config_path(),
+ )
+ .expect("Failed to save approval");
+
+ // Now clear approvals (should show count of 3)
+ snapshot_clear_approvals("clear_approvals_multiple_approvals", &repo, &[]);
+}
diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs
index 2382ed95d..65578c6b2 100644
--- a/tests/integration_tests/mod.rs
+++ b/tests/integration_tests/mod.rs
@@ -5,6 +5,7 @@
// column_alignment merged into spacing_edge_cases
pub mod approval_save;
pub mod approval_ui;
+pub mod approvals;
pub mod bare_repository;
pub mod column_alignment_verification;
pub mod completion;
diff --git a/tests/snapshots/integration__integration_tests__approvals__ask_approvals_all_none_approved.snap b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_all_none_approved.snap
new file mode 100644
index 000000000..450340bc2
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_all_none_approved.snap
@@ -0,0 +1,36 @@
+---
+source: tests/integration_tests/approvals.rs
+assertion_line: 13
+info:
+ program: wt
+ args:
+ - beta
+ - ask-approvals
+ - "--all"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ 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: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpRy2MnB/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+⚪ post-create declined
+⚪ Commands declined
+
+----- stderr -----
+
+🟡 test-repo wants to execute 1 command:
+
+🔄 post-create:
+  echo 'test'
+
+💡 Allow and remember? [y/N]
diff --git a/tests/snapshots/integration__integration_tests__approvals__ask_approvals_empty_config.snap b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_empty_config.snap
new file mode 100644
index 000000000..9a72cbbbd
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_empty_config.snap
@@ -0,0 +1,27 @@
+---
+source: tests/integration_tests/approvals.rs
+assertion_line: 13
+info:
+ program: wt
+ args:
+ - beta
+ - ask-approvals
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ 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: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpwGlLon/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+⚪ No commands configured in project
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__approvals__ask_approvals_force.snap b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_force.snap
new file mode 100644
index 000000000..6e17d8250
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_force.snap
@@ -0,0 +1,28 @@
+---
+source: tests/integration_tests/approvals.rs
+assertion_line: 12
+info:
+ program: wt
+ args:
+ - beta
+ - ask-approvals
+ - "--force"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ 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: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpQPV1jE/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+✅ Commands approved (not saved with --force)
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__approvals__ask_approvals_no_config.snap b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_no_config.snap
new file mode 100644
index 000000000..ae8902005
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_no_config.snap
@@ -0,0 +1,29 @@
+---
+source: tests/integration_tests/approvals.rs
+assertion_line: 12
+info:
+ program: wt
+ args:
+ - beta
+ - ask-approvals
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ 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: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpU3OaGe/test-config.toml
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+❌ No project configuration found
+💡 Create a config file at: [REPO]/.config/wt.toml
+No project configuration found
diff --git a/tests/snapshots/integration__integration_tests__approvals__clear_approvals_after_clear.snap b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_after_clear.snap
new file mode 100644
index 000000000..c44d98325
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_after_clear.snap
@@ -0,0 +1,27 @@
+---
+source: tests/integration_tests/approvals.rs
+assertion_line: 22
+info:
+ program: wt
+ args:
+ - beta
+ - clear-approvals
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ 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: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpT3PtnA/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+⚪ No approvals to clear for this project
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__approvals__clear_approvals_global_no_approvals.snap b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_global_no_approvals.snap
new file mode 100644
index 000000000..baf0750a9
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_global_no_approvals.snap
@@ -0,0 +1,28 @@
+---
+source: tests/integration_tests/approvals.rs
+assertion_line: 22
+info:
+ program: wt
+ args:
+ - beta
+ - clear-approvals
+ - "--global"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ 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: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp1XSZsq/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+⚪ No approvals to clear
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__approvals__clear_approvals_global_with_approvals.snap b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_global_with_approvals.snap
new file mode 100644
index 000000000..9b396d3be
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_global_with_approvals.snap
@@ -0,0 +1,28 @@
+---
+source: tests/integration_tests/approvals.rs
+assertion_line: 23
+info:
+ program: wt
+ args:
+ - beta
+ - clear-approvals
+ - "--global"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ 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: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpDcGXy8/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+✅ Cleared approvals for 1 project
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__approvals__clear_approvals_multiple_approvals.snap b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_multiple_approvals.snap
new file mode 100644
index 000000000..a2547d587
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_multiple_approvals.snap
@@ -0,0 +1,27 @@
+---
+source: tests/integration_tests/approvals.rs
+assertion_line: 22
+info:
+ program: wt
+ args:
+ - beta
+ - clear-approvals
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ 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: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpAlL1op/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+⚪ No approvals to clear for this project
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__approvals__clear_approvals_no_approvals.snap b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_no_approvals.snap
new file mode 100644
index 000000000..f2ba84df4
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_no_approvals.snap
@@ -0,0 +1,27 @@
+---
+source: tests/integration_tests/approvals.rs
+assertion_line: 22
+info:
+ program: wt
+ args:
+ - beta
+ - clear-approvals
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ 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: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpNgYgAo/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+⚪ No approvals to clear for this project
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__approvals__clear_approvals_with_approvals.snap b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_with_approvals.snap
new file mode 100644
index 000000000..9ec455c3d
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approvals__clear_approvals_with_approvals.snap
@@ -0,0 +1,27 @@
+---
+source: tests/integration_tests/approvals.rs
+assertion_line: 22
+info:
+ program: wt
+ args:
+ - beta
+ - clear-approvals
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ 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: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpvWf3nm/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+⚪ No approvals to clear for this project
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snap
index 7235e4d54..b91ed3b02 100644
--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap
@@ -1,5 +1,6 @@
---
source: tests/integration_tests/init.rs
+assertion_line: 23
info:
program: wt
args:
@@ -16,7 +17,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpi1D9uO/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpxCeqZT/test-config.toml
---
success: true
exit_code: 0
@@ -170,6 +171,9 @@ _wt() {
wt__beta,ask-approvals)
cmd="wt__beta__ask__approvals"
;;
+ wt__beta,clear-approvals)
+ cmd="wt__beta__clear__approvals"
+ ;;
wt__beta,commit)
cmd="wt__beta__commit"
;;
@@ -224,7 +228,7 @@ _wt() {
return 0
;;
wt__beta)
- opts="-v -h --verbose --help run-hook commit squash push rebase ask-approvals select"
+ opts="-v -h --verbose --help run-hook commit squash push rebase ask-approvals clear-approvals select"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -251,6 +255,20 @@ _wt() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
+ wt__beta__clear__approvals)
+ opts="-g -v -h --global --verbose --help"
+ if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
+ return 0
+ fi
+ case "${prev}" in
+ *)
+ COMPREPLY=()
+ ;;
+ esac
+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
+ return 0
+ ;;
wt__beta__commit)
opts="-f -v -h --force --no-verify --verbose --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snap
index 4cffebc00..34b352609 100644
--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap
@@ -1,5 +1,6 @@
---
source: tests/integration_tests/init.rs
+assertion_line: 23
info:
program: wt
args:
@@ -12,10 +13,11 @@ info:
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: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpmJ34gU/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpBzxXJn/test-config.toml
---
success: true
exit_code: 0
@@ -232,15 +234,16 @@ zsh\t''"
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s f -l force -d 'Skip confirmation prompt'
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s h -l help -d 'Print help (see more with \'--help\')'
-complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals select" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
-complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals select" -s h -l help -d 'Print help'
-complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals select" -f -a "run-hook" -d 'Run a project hook for testing'
-complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals select" -f -a "commit" -d 'Commit changes with LLM-generated message'
-complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals select" -f -a "squash" -d 'Squash commits with LLM-generated message'
-complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals select" -f -a "push" -d 'Push changes to target branch'
-complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals select" -f -a "rebase" -d 'Rebase current branch onto target branch'
-complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals select" -f -a "ask-approvals" -d 'Approve commands in the project config (shows unapproved by default)'
-complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals select" -f -a "select" -d 'Interactive worktree selector'
+complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
+complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "run-hook" -d 'Run a project hook for testing'
+complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "commit" -d 'Commit changes with LLM-generated message'
+complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "squash" -d 'Squash commits with LLM-generated message'
+complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "push" -d 'Push changes to target branch'
+complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "rebase" -d 'Rebase current branch onto target branch'
+complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "ask-approvals" -d 'Approve commands in the project config (shows unapproved by default)'
+complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "clear-approvals" -d 'Clear approved commands from config'
+complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "select" -d 'Interactive worktree selector'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s f -l force -d 'Auto-approve project commands without saving approvals'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s h -l help -d 'Print help'
@@ -261,6 +264,9 @@ complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_f
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -l all -d 'Show all commands including already-approved ones'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s g -l global -d 'Clear approvals from global config (all projects)'
+complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
+complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from select" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from select" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c wt -n "__fish_wt_using_subcommand list" -l format -d 'Output format' -r -f -a "table\t'Human-readable table format'
diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
index dc7cfca3f..d89eba299 100644
--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
@@ -1,5 +1,6 @@
---
source: tests/integration_tests/init.rs
+assertion_line: 23
info:
program: wt
args:
@@ -12,10 +13,11 @@ info:
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: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp58Uw1Q/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpMoxDqw/test-config.toml
---
success: true
exit_code: 0
@@ -322,6 +324,16 @@ _arguments "${_arguments_options[@]}" : \
'--help[Print help]' \
&& ret=0
;;
+(clear-approvals)
+_arguments "${_arguments_options[@]}" : \
+'-g[Clear approvals from global config (all projects)]' \
+'--global[Clear approvals from global config (all projects)]' \
+'-v[Enable verbose output (show git commands and debug info)]' \
+'--verbose[Enable verbose output (show git commands and debug info)]' \
+'-h[Print help]' \
+'--help[Print help]' \
+&& ret=0
+;;
(select)
_arguments "${_arguments_options[@]}" : \
'-v[Enable verbose output (show git commands and debug info)]' \
@@ -427,6 +439,7 @@ _wt__beta_commands() {
'push:Push changes to target branch' \
'rebase:Rebase current branch onto target branch' \
'ask-approvals:Approve commands in the project config (shows unapproved by default)' \
+'clear-approvals:Clear approved commands from config' \
'select:Interactive worktree selector' \
)
_describe -t commands 'wt beta commands' commands "$@"
@@ -436,6 +449,11 @@ _wt__beta__ask-approvals_commands() {
local commands; commands=()
_describe -t commands 'wt beta ask-approvals commands' commands "$@"
}
+(( $+functions[_wt__beta__clear-approvals_commands] )) ||
+_wt__beta__clear-approvals_commands() {
+ local commands; commands=()
+ _describe -t commands 'wt beta clear-approvals commands' commands "$@"
+}
(( $+functions[_wt__beta__commit_commands] )) ||
_wt__beta__commit_commands() {
local commands; commands=()