Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Add --project flag to wt config create (#110)
Maximilian Roos69474c620dc8
diff --git a/dev/config.example.toml b/dev/config.example.tomlindex 035549ca2..cc78ecc5f 100644--- a/dev/config.example.toml+++ b/dev/config.example.toml@@ -70,7 +70,7 @@ approved-commands = ["npm install"]# NOTE: For project-specific hooks (post-create, post-start, pre-merge, etc.),# use a separate PROJECT config file at <repo>/.config/wt.toml-# See: dev/wt.example.toml for project configuration examples+# Run `wt config create --project` to create one, or see https://worktrunk.dev/hooks/# ============================================================================# Custom Prompt Templates (Advanced)diff --git a/docs/content/config.md b/docs/content/config.mdindex f6e80d106..94405e316 100644--- a/docs/content/config.md+++ b/docs/content/config.md@@ -31,6 +31,12 @@ Create user config file with documented examples:wt config create```+Create project config file (.config/wt.toml) for hooks:++```bash+wt config create --project+```+Show current configuration and file locations:```bash@@ -219,7 +225,7 @@ Usage: wt config [OPTIONS] <COMMAND>Commands:shell Shell integration setup- create Create user configuration file+ create Create configuration fileshow Show configuration files & locationscache Manage caches (CI status, default branch)var Get or set runtime variables (stored in git config)diff --git a/src/cli.rs b/src/cli.rsindex 3de00902f..04baac8d0 100644--- a/src/cli.rs+++ b/src/cli.rs@@ -269,15 +269,24 @@ pub enum ConfigCommand {action: ConfigShellCommand,},- /// Create user configuration file+ /// Create configuration file#[command(after_long_help = concat!(+ "## User config\n\n","Creates `~/.config/worktrunk/config.toml` with the following content:\n\n```\n",include_str!("../dev/config.example.toml"),+ "```\n\n",+ "## Project config\n\n",+ "With `--project`, creates `.config/wt.toml` in the current repository:\n\n```\n",+ include_str!("../dev/wt.example.toml"),"```"))]- Create,+ Create {+ /// Create project config (.config/wt.toml) instead of user config+ #[arg(long)]+ project: bool,+ },/// Show configuration files & locations#[command(@@ -693,6 +702,12 @@ Create user config file with documented examples:wt config create```+Create project config file (.config/wt.toml) for hooks:++```console+wt config create --project+```+Show current configuration and file locations:```consolediff --git a/src/commands/config.rs b/src/commands/config.rsindex 7e1598852..782d4d77e 100644--- a/src/commands/config.rs+++ b/src/commands/config.rs@@ -18,8 +18,11 @@ use crate::help_pager::show_help_in_pager;use crate::llm::test_commit_generation;use crate::output;-/// Example configuration file content (displayed in help with values uncommented)-const CONFIG_EXAMPLE: &str = include_str!("../../dev/config.example.toml");+/// Example user configuration file content (displayed in help with values uncommented)+const USER_CONFIG_EXAMPLE: &str = include_str!("../../dev/config.example.toml");++/// Example project configuration file content+const PROJECT_CONFIG_EXAMPLE: &str = include_str!("../../dev/wt.example.toml");/// Comment out all non-comment, non-empty lines for writing to diskfn comment_out_config(content: &str) -> String {@@ -45,14 +48,41 @@ fn comment_out_config(content: &str) -> String {}/// Handle the config create command-pub fn handle_config_create() -> anyhow::Result<()> {- let config_path = require_user_config_path()?;+pub fn handle_config_create(project: bool) -> anyhow::Result<()> {+ if project {+ let repo = Repository::current();+ let config_path = repo.worktree_root()?.join(".config/wt.toml");+ create_config_file(+ config_path,+ PROJECT_CONFIG_EXAMPLE,+ "Project config",+ &[+ "Edit this file to configure hooks for this repository",+ "See https://worktrunk.dev/hooks/ for hook documentation",+ ],+ )+ } else {+ create_config_file(+ require_user_config_path()?,+ USER_CONFIG_EXAMPLE,+ "User config",+ &["Edit this file to customize worktree paths and LLM settings"],+ )+ }+}+/// Create a config file at the specified path with the given content+fn create_config_file(+ path: PathBuf,+ content: &str,+ config_type: &str,+ success_hints: &[&str],+) -> anyhow::Result<()> {// Check if file already exists- if config_path.exists() {+ if path.exists() {output::info(cformat!(- "User config already exists: <bold>{}</>",- format_path_for_display(&config_path)+ "{config_type} already exists: <bold>{}</>",+ format_path_for_display(&path)))?;output::blank()?;output::hint(cformat!(@@ -65,21 +95,24 @@ pub fn handle_config_create() -> anyhow::Result<()> {}// Create parent directory if it doesn't exist- if let Some(parent) = config_path.parent() {+ if let Some(parent) = path.parent() {std::fs::create_dir_all(parent).context("Failed to create config directory")?;}// Write the example config with all values commented out- let commented_config = comment_out_config(CONFIG_EXAMPLE);- std::fs::write(&config_path, commented_config).context("Failed to write config file")?;+ let commented_config = comment_out_config(content);+ std::fs::write(&path, commented_config).context("Failed to write config file")?;// Success messageoutput::success(cformat!(- "Created config file: <bold>{}</>",- format_path_for_display(&config_path)+ "Created {}: <bold>{}</>",+ config_type.to_lowercase(),+ format_path_for_display(&path)))?;output::blank()?;- output::hint("Edit this file to customize worktree paths and LLM settings")?;+ for hint in success_hints {+ output::hint(*hint)?;+ }Ok(())}diff --git a/src/main.rs b/src/main.rsindex 97529ab48..1948ba2e6 100644--- a/src/main.rs+++ b/src/main.rs@@ -732,7 +732,7 @@ fn main() {}}}- ConfigCommand::Create => handle_config_create(),+ ConfigCommand::Create { project } => handle_config_create(project),ConfigCommand::Show { doctor } => handle_config_show(doctor),ConfigCommand::Cache { action } => match action {CacheCommand::Show => handle_cache_show(),diff --git a/tests/integration_tests/config_init.rs b/tests/integration_tests/config_init.rsindex 780072e04..82f8e360f 100644--- a/tests/integration_tests/config_init.rs+++ b/tests/integration_tests/config_init.rs@@ -59,7 +59,7 @@ fn test_config_init_creates_file() {----- stdout ---------- stderr ------ ✅ [32mCreated config file: [1m~/.config/worktrunk/config.toml[22m[39m+ ✅ [32mCreated user config: [1m~/.config/worktrunk/config.toml[22m[39m💡 [2mEdit this file to customize worktree paths and LLM settings[22m");diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snapindex 681d4b830..4e86bd2c1 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap@@ -18,10 +18,13 @@ exit_code: 0----- stdout ---------- stderr ------wt config create - Create user configuration file+wt config create - Create configuration fileUsage: [1m[36mwt config create[0m [36m[OPTIONS][0m[1m[32mOptions:[0m+ [1m[36m--project[0m+ Create project config (.config/wt.toml) instead of user config+[1m[36m-h[0m, [1m[36m--help[0mPrint help (see a summary with '-h')@@ -35,6 +38,8 @@ Usage: [1m[36mwt config create[0m [36m[OPTIONS][0m[1m[36m-v[0m, [1m[36m--verbose[0mShow commands and debug info+[32mUser config[0m+Creates [2m~/.config/worktrunk/config.toml[0m with the following content:[2m# Worktrunk Global Configuration[0m@@ -109,7 +114,7 @@ Creates [2m~/.config/worktrunk/config.toml[0m with the following content:[2m[0m[2m# NOTE: For project-specific hooks (post-create, post-start, pre-merge, etc.),[0m[2m# use a separate PROJECT config file at <repo>/.config/wt.toml[0m- [2m# See: dev/wt.example.toml for project configuration examples[0m+ [2m# Run `wt config create --project` to create one, or see https://worktrunk.dev/hooks/[0m[2m[0m[2m# ============================================================================[0m[2m# Custom Prompt Templates (Advanced)[0m@@ -227,3 +232,125 @@ Creates [2m~/.config/worktrunk/config.toml[0m with the following content:[2m# Generate one cohesive commit message that captures the overall change.[0m[2m# Use conventional commit format (feat/fix/docs/refactor).[0m[2m# """[0m++[32mProject config[0m++With [2m--project[0m, creates [2m.config/wt.toml[0m in the current repository:++ [2m# Worktrunk Project Configuration[0m+ [2m# Copy to: <repo>/.config/wt.toml[0m+ [2m#[0m+ [2m# This file defines project-specific hooks that run automatically during[0m+ [2m# worktree operations. It should be checked into git and shared across all[0m+ [2m# developers working on the project.[0m+ [2m[0m+ [2m# Available template variables (all hooks):[0m+ [2m# {{ repo }} - Repository name (e.g., "my-project")[0m+ [2m# {{ branch }} - Branch name (slashes replaced with dashes)[0m+ [2m# {{ worktree }} - Absolute path to the worktree[0m+ [2m# {{ repo_root }} - Absolute path to the repository root[0m+ [2m#[0m+ [2m# Merge-related hooks also support:[0m+ [2m# {{ target }} - Target branch for the merge (e.g., "main")[0m+ [2m[0m+ [2m# Post-Create Hook[0m+ [2m# Runs SEQUENTIALLY and BLOCKS until complete[0m+ [2m# The worktree switch won't complete until these finish[0m+ [2m# Commands run one after another in the worktree directory[0m+ [2m#[0m+ [2m# Format options:[0m+ [2m# 1. Single string:[0m+ [2m# post-create = "npm install"[0m+ [2m#[0m+ [2m# 2. Named table (runs sequentially in declaration order):[0m+ [2m# [post-create][0m+ [2m# install = "npm install --frozen-lockfile"[0m+ [2m# build = "npm run build"[0m+ [2m[0m+ [2m# Post-Start Hook[0m+ [2m# Runs in BACKGROUND as detached processes (parallel)[0m+ [2m# Use for: uv sync, npm install, bundle install, build, dev servers, file watchers,[0m+ [2m# downloading assets too large for git (images, ML models, binaries), long-running tasks[0m+ [2m# The worktree switch completes immediately, these run in parallel[0m+ [2m# Output is logged to .git/wt-logs/{branch}-post-start-{name}.log[0m+ [2m#[0m+ [2m# Format options:[0m+ [2m# 1. Single string:[0m+ [2m# post-start = "npm run dev"[0m+ [2m#[0m+ [2m# 2. Named table (runs in parallel):[0m+ [2m# [post-start][0m+ [2m# server = "npm run dev"[0m+ [2m# watch = "npm run watch"[0m+ [2m[0m+ [2m# Pre-Commit Hook[0m+ [2m# Runs SEQUENTIALLY before committing changes during merge (blocking, fail-fast)[0m+ [2m# All commands must exit with code 0 for commit to proceed[0m+ [2m# Runs for both squash and no-squash merge modes[0m+ [2m# Use for: formatters, linters, quick validation[0m+ [2m#[0m+ [2m# Single command:[0m+ [2m# pre-commit = "cargo fmt -- --check"[0m+ [2m#[0m+ [2m# Multiple commands:[0m+ [2m# [pre-commit][0m+ [2m# format = "cargo fmt -- --check"[0m+ [2m# lint = "cargo clippy -- -D warnings"[0m+ [2m[0m+ [2m# Pre-Merge Hook[0m+ [2m# Runs SEQUENTIALLY before merging to target branch (blocking, fail-fast)[0m+ [2m# All commands must exit with code 0 for merge to proceed[0m+ [2m# Use for: tests, linters, build verification before merging[0m+ [2m#[0m+ [2m# Single command:[0m+ [2m# pre-merge = "cargo test"[0m+ [2m#[0m+ [2m# Multiple commands:[0m+ [2m# [pre-merge][0m+ [2m# test = "cargo test"[0m+ [2m# build = "cargo build --release"[0m+ [2m[0m+ [2m# Post-Merge Hook[0m+ [2m# Runs SEQUENTIALLY in the main worktree after successful merge (blocking)[0m+ [2m# Runs after push succeeds but before cleanup[0m+ [2m# Use for: updating production builds, notifications, cleanup[0m+ [2m#[0m+ [2m# Single command:[0m+ [2m# post-merge = "cargo install --path ."[0m+ [2m#[0m+ [2m# Multiple commands:[0m+ [2m# [post-merge][0m+ [2m# install = "cargo install --path ."[0m+ [2m# notify = "echo 'Merged!'"[0m+ [2m[0m+ [2m# Example: Node.js Project[0m+ [2m# [post-create][0m+ [2m# install = "npm ci"[0m+ [2m#[0m+ [2m# [post-start][0m+ [2m# server = "npm run dev"[0m+ [2m#[0m+ [2m# [pre-merge][0m+ [2m# lint = "npm run lint"[0m+ [2m# test = "npm test"[0m+ [2m[0m+ [2m# Example: Rust Project[0m+ [2m# [post-create][0m+ [2m# build = "cargo build"[0m+ [2m#[0m+ [2m# [pre-merge][0m+ [2m# format = "cargo fmt -- --check"[0m+ [2m# clippy = "cargo clippy -- -D warnings"[0m+ [2m# test = "cargo test"[0m+ [2m#[0m+ [2m# post-merge = "cargo install --path ."[0m+ [2m[0m+ [2m# Example: Python Project[0m+ [2m# [post-create][0m+ [2m# venv = "python -m venv .venv"[0m+ [2m# install = ".venv/bin/pip install -r requirements.txt"[0m+ [2m#[0m+ [2m# [pre-merge][0m+ [2m# format = ".venv/bin/black --check ."[0m+ [2m# lint = ".venv/bin/ruff check ."[0m+ [2m# test = ".venv/bin/pytest"[0mdiff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snapindex 6b8fdd715..45d9e4bdc 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap@@ -22,7 +22,7 @@ Usage: [1m[36mwt config[0m [36m[OPTIONS][0m [36m<COMMAND>[0m[1m[32mCommands:[0m[1m[36mshell[0m Shell integration setup- [1m[36mcreate[0m Create user configuration file+ [1m[36mcreate[0m Create configuration file[1m[36mshow[0m Show configuration files & locations[1m[36mcache[0m Manage caches (CI status, default branch)[1m[36mvar[0m Get or set runtime variables (stored in git config)@@ -61,6 +61,10 @@ Create user config file with documented examples:[2mwt config create[0m+Create project config file (.config/wt.toml) for hooks:++ [2mwt config create --project[0m+Show current configuration and file locations:[2mwt config show[0mdiff --git a/tests/snapshots/integration__integration_tests__help__help_config_short.snap b/tests/snapshots/integration__integration_tests__help__help_config_short.snapindex b0c876f31..e3d10cb9e 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_short.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_short.snap@@ -22,7 +22,7 @@ Usage: [1m[36mwt config[0m [36m[OPTIONS][0m [36m<COMMAND>[0m[1m[32mCommands:[0m[1m[36mshell[0m Shell integration setup- [1m[36mcreate[0m Create user configuration file+ [1m[36mcreate[0m Create configuration file[1m[36mshow[0m Show configuration files & locations[1m[36mcache[0m Manage caches (CI status, default branch)[1m[36mvar[0m Get or set runtime variables (stored in git config)