Skip to content

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

Refactor HookType to use strum's EnumIter derive

Maximilian Roos369c9fca0637
diff --git a/README.md b/README.md
index 9fe57ff9c..00e837d68 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Scaling agents becomes trivial. A quick demo:
![Worktrunk Demo](https://cdn.jsdelivr.net/gh/max-sixty/worktrunk-assets@main/demos/docs/light/wt-core.gif)
-> ## πŸ“š Full documentation at [worktrunk.dev](https://worktrunk.dev) πŸ“š
+> ### πŸ“š Full documentation at [worktrunk.dev](https://worktrunk.dev) πŸ“š
<!-- ⚠️ AUTO-GENERATED from docs/content/worktrunk.md#context-git-worktrees..worktrunk-makes-git-worktrees-as-easy-as-branches β€” edit source to update -->
@@ -135,4 +135,4 @@ cargo install worktrunk && wt config shell install
- [Open an issue](https://github.com/max-sixty/worktrunk/issues/new?title=&body=%23%23%20Description%0A%0A%3C!--%20Describe%20the%20bug%20or%20feature%20request%20--%3E%0A%0A%23%23%20Context%0A%0A%3C!--%20Any%20relevant%20context%3A%20your%20workflow%2C%20what%20you%20were%20trying%20to%20do%2C%20etc.%20--%3E) β€” feedback, feature requests, even a small friction or imperfect user message, or [a worktree pain not yet solved](https://github.com/max-sixty/worktrunk/issues/new?title=Worktree%20friction%3A%20&body=%23%23%20The%20friction%0A%0A%3C!--%20What%20worktree-related%20task%20is%20still%20painful%3F%20--%3E%0A%0A%23%23%20Current%20workaround%0A%0A%3C!--%20How%20do%20you%20handle%20this%20today%3F%20--%3E%0A%0A%23%23%20Ideal%20solution%0A%0A%3C!--%20What%20would%20make%20this%20easier%3F%20--%3E)
- Share: [X](https://twitter.com/intent/tweet?text=Worktrunk%20%E2%80%94%20CLI%20for%20git%20worktree%20management&url=https%3A%2F%2Fworktrunk.dev) Β· [Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fworktrunk.dev&title=Worktrunk%20%E2%80%94%20CLI%20for%20git%20worktree%20management) Β· [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fworktrunk.dev)
-> ## πŸ“š Full documentation at [worktrunk.dev](https://worktrunk.dev) πŸ“š
+> ### πŸ“š Full documentation at [worktrunk.dev](https://worktrunk.dev) πŸ“š
diff --git a/src/commands/hook_commands.rs b/src/commands/hook_commands.rs
index bf3bc8dde..0bc987123 100644
--- a/src/commands/hook_commands.rs
+++ b/src/commands/hook_commands.rs
@@ -9,6 +9,7 @@
use anyhow::Context;
use color_print::cformat;
use std::fmt::Write as _;
+use strum::IntoEnumIterator;
use worktrunk::HookType;
use worktrunk::config::{CommandConfig, ProjectConfig, WorktrunkConfig};
use worktrunk::git::{GitError, Repository};
@@ -274,13 +275,7 @@ pub fn add_approvals(show_all: bool) -> anyhow::Result<()> {
.ok_or(GitError::ProjectConfigNotFound { config_path })?;
// Collect all commands from the project config
- let all_hooks = [
- HookType::PostCreate,
- HookType::PostStart,
- HookType::PreCommit,
- HookType::PreMerge,
- HookType::PostMerge,
- ];
+ let all_hooks: Vec<_> = HookType::iter().collect();
let commands = collect_commands_for_hooks(&project_config, &all_hooks);
if commands.is_empty() {
diff --git a/src/commands/project_config.rs b/src/commands/project_config.rs
index d8eaaccff..4c122d7b5 100644
--- a/src/commands/project_config.rs
+++ b/src/commands/project_config.rs
@@ -88,16 +88,11 @@ pre-merge = "cargo test"
#[test]
fn test_collect_commands_for_hooks_all_hook_types() {
+ use strum::IntoEnumIterator;
+
let config = ProjectConfig::default();
// All hooks should work even when empty
- let hooks = [
- HookType::PostCreate,
- HookType::PostStart,
- HookType::PreCommit,
- HookType::PreMerge,
- HookType::PostMerge,
- HookType::PreRemove,
- ];
+ let hooks: Vec<_> = HookType::iter().collect();
let commands = collect_commands_for_hooks(&config, &hooks);
assert!(commands.is_empty());
}
diff --git a/src/git/mod.rs b/src/git/mod.rs
index 0cf85bc6a..6b49abace 100644
--- a/src/git/mod.rs
+++ b/src/git/mod.rs
@@ -283,7 +283,17 @@ pub(crate) use parse::DefaultBranchName;
// They're accessible as git::HookType and git::Worktree without needing re-export.
/// Hook types for git operations
-#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum, strum::Display, strum::EnumString)]
+#[derive(
+ Debug,
+ Clone,
+ Copy,
+ PartialEq,
+ Eq,
+ clap::ValueEnum,
+ strum::Display,
+ strum::EnumString,
+ strum::EnumIter,
+)]
#[strum(serialize_all = "kebab-case")]
pub enum HookType {
PostCreate,
@@ -498,16 +508,15 @@ mod tests {
#[test]
fn test_hook_type_display() {
- let cases = [
- (HookType::PostCreate, "post-create"),
- (HookType::PostStart, "post-start"),
- (HookType::PreCommit, "pre-commit"),
- (HookType::PreMerge, "pre-merge"),
- (HookType::PostMerge, "post-merge"),
- (HookType::PreRemove, "pre-remove"),
- ];
- for (hook, expected) in cases {
- assert_eq!(format!("{hook}"), expected);
+ use strum::IntoEnumIterator;
+
+ // Verify all hook types serialize to kebab-case
+ for hook in HookType::iter() {
+ let display = format!("{hook}");
+ assert!(
+ display.chars().all(|c| c.is_lowercase() || c == '-'),
+ "Hook {hook:?} should be kebab-case, got: {display}"
+ );
}
}