Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Remove --refresh flag from config state get commands (#530)
Maximilian Roos0c727fd2c5be
diff --git a/.claude-plugin/skills/worktrunk/reference/config.md b/.claude-plugin/skills/worktrunk/reference/config.mdindex 385925f6d..eddf1dc39 100644--- a/.claude-plugin/skills/worktrunk/reference/config.md+++ b/.claude-plugin/skills/worktrunk/reference/config.md@@ -752,7 +752,7 @@ Useful in scripts to avoid hardcoding `main` or `master`:git rebase $(wt config state default-branch)```-Without a subcommand, runs `get`. Use `set` to override, `get --refresh` to re-detect, or `clear` to reset.+Without a subcommand, runs `get`. Use `set` to override, or `clear` then `get` to re-detect.### Detection@@ -820,7 +820,7 @@ Caches GitHub/GitLab CI status for display in [`wt list`](https://worktrunk.dev/See [`wt list` CI status](https://worktrunk.dev/list/#ci-status) for display symbols and colors.-Without a subcommand, runs `get` for the current branch. Use `get --refresh` to force re-fetch or `clear --all` to reset cache.+Without a subcommand, runs `get` for the current branch. Use `clear` to reset cache for a branch or `clear --all` to reset all.### Command referencediff --git a/.claude-plugin/skills/worktrunk/reference/faq.md b/.claude-plugin/skills/worktrunk/reference/faq.mdindex d7d42b57d..a55ed426f 100644--- a/.claude-plugin/skills/worktrunk/reference/faq.md+++ b/.claude-plugin/skills/worktrunk/reference/faq.md@@ -82,7 +82,7 @@ Git TUIs operate on a single repository. Worktrunk manages multiple worktrees, rWorktrunk checks the local git cache first, queries the remote if needed, and falls back to local inference when no remote exists. The result is cached for fast subsequent lookups.-If the remote's default branch has changed (e.g., renamed from master to main), refresh with `wt config state default-branch get --refresh`.+If the remote's default branch has changed (e.g., renamed from master to main), clear the cache with `wt config state default-branch clear`.For full details on the detection mechanism, see `wt config state default-branch --help`.diff --git a/docs/content/config.md b/docs/content/config.mdindex 1444b9e7a..b21794bad 100644--- a/docs/content/config.md+++ b/docs/content/config.md@@ -770,7 +770,7 @@ Useful in scripts to avoid hardcoding `main` or `master`:git rebase $(wt config state default-branch)```-Without a subcommand, runs `get`. Use `set` to override, `get --refresh` to re-detect, or `clear` to reset.+Without a subcommand, runs `get`. Use `set` to override, or `clear` then `get` to re-detect.### Detection@@ -841,7 +841,7 @@ Caches GitHub/GitLab CI status for display in [`wt list`](@/list.md#ci-status).See [`wt list` CI status](@/list.md#ci-status) for display symbols and colors.-Without a subcommand, runs `get` for the current branch. Use `get --refresh` to force re-fetch or `clear --all` to reset cache.+Without a subcommand, runs `get` for the current branch. Use `clear` to reset cache for a branch or `clear --all` to reset all.### Command referencediff --git a/docs/content/faq.md b/docs/content/faq.mdindex 7ea8d2601..91e6c055a 100644--- a/docs/content/faq.md+++ b/docs/content/faq.md@@ -92,7 +92,7 @@ Git TUIs operate on a single repository. Worktrunk manages multiple worktrees, rWorktrunk checks the local git cache first, queries the remote if needed, and falls back to local inference when no remote exists. The result is cached for fast subsequent lookups.-If the remote's default branch has changed (e.g., renamed from master to main), refresh with `wt config state default-branch get --refresh`.+If the remote's default branch has changed (e.g., renamed from master to main), clear the cache with `wt config state default-branch clear`.For full details on the detection mechanism, see `wt config state default-branch --help`.diff --git a/src/cli/config.rs b/src/cli/config.rsindex f4fbc5919..b73faccff 100644--- a/src/cli/config.rs+++ b/src/cli/config.rs@@ -279,7 +279,7 @@ pub enum StateCommand {git rebase $(wt config state default-branch)```-Without a subcommand, runs `get`. Use `set` to override, `get --refresh` to re-detect, or `clear` to reset.+Without a subcommand, runs `get`. Use `set` to override, or `clear` then `get` to re-detect.## Detection@@ -344,7 +344,7 @@ Without a subcommand, runs `get`. Use `set` to override or `clear` to reset."#See [`wt list` CI status](@/list.md#ci-status) for display symbols and colors.-Without a subcommand, runs `get` for the current branch. Use `get --refresh` to force re-fetch or `clear --all` to reset cache."#+Without a subcommand, runs `get` for the current branch. Use `clear` to reset cache for a branch or `clear --all` to reset all."#)]CiStatus {#[command(subcommand)]@@ -496,15 +496,11 @@ Get the default branch:wt config state default-branch```-Force refresh from remote:+Clear cache and re-detect:```console-wt config state default-branch get --refresh+wt config state default-branch clear && wt config state default-branch get```"#)]- Get {- /// Force refresh from remote- #[arg(long)]- refresh: bool,- },+ Get,/// Set the default branch#[command(after_long_help = r#"## Examples@@ -564,21 +560,17 @@ Get CI status for current branch:wt config state ci-status```-Force refresh from GitHub/GitLab:+Get CI status for a specific branch:```console-wt config state ci-status get --refresh+wt config state ci-status get --branch=feature```-Get CI status for a specific branch:+Clear cache and re-fetch:```console-wt config state ci-status get --branch=feature+wt config state ci-status clear && wt config state ci-status get```"#)]Get {- /// Force refresh from GitHub/GitLab- #[arg(long)]- refresh: bool,-/// Target branch (defaults to current)#[arg(long, add = crate::completion::branch_value_completer())]branch: Option<String>,diff --git a/src/commands/config.rs b/src/commands/config.rsindex 96a1dcede..99d5efe0e 100644--- a/src/commands/config.rs+++ b/src/commands/config.rs@@ -11,7 +11,7 @@ use worktrunk::path::format_path_for_display;use worktrunk::shell::{Shell, scan_for_detection_details};use worktrunk::styling::{error_message, format_bash_with_gutter, format_heading, format_toml, format_with_gutter,- hint_message, info_message, progress_message, success_message, warning_message,+ hint_message, info_message, success_message, warning_message,};use worktrunk::utils::get_now;@@ -962,19 +962,14 @@ fn render_log_files(out: &mut String, repo: &Repository) -> anyhow::Result<()> {}/// Handle the state get command-pub fn handle_state_get(key: &str, refresh: bool, branch: Option<String>) -> anyhow::Result<()> {+pub fn handle_state_get(key: &str, branch: Option<String>) -> anyhow::Result<()> {use super::list::ci_status::PrStatus;let repo = Repository::current()?;match key {"default-branch" => {- let branch_name = if refresh {- crate::output::print(progress_message("Querying remote for default branch..."))?;- repo.refresh_default_branch()?- } else {- repo.default_branch()?- };+ let branch_name = repo.default_branch()?;crate::output::stdout(branch_name)?;}"previous-branch" => match repo.get_switch_previous() {@@ -1010,13 +1005,6 @@ pub fn handle_state_get(key: &str, refresh: bool, branch: Option<String>) -> any.into());}- if refresh {- crate::output::print(progress_message("Fetching CI status..."))?;- // Clear cache to force refresh- let config_key = format!("worktrunk.state.{branch_name}.ci-status");- let _ = repo.run_command(&["config", "--unset", &config_key]);- }-let has_upstream = repo.upstream_branch(&branch_name).ok().flatten().is_some();let ci_status = PrStatus::detect(&repo, &branch_name, &head, has_upstream).map_or(super::list::ci_status::CiStatus::NoCI, |s| s.ci_status);diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rsindex b099736c6..ac327a13b 100644--- a/src/commands/list/mod.rs+++ b/src/commands/list/mod.rs@@ -16,7 +16,7 @@//! 2. **Default branch lookup** (~1-5ms)//! - Reads cached value from `.git/refs/remotes/origin/HEAD`//! - Falls back to `git remote show origin` if not cached (~100-300ms network)-//! - Refresh with `wt config state get default-branch --refresh`+//! - Clear cache with `wt config state default-branch clear` to force re-detection//!//! 3. **Sort worktrees** (<1ms)//! - Orders by: current → main → rest by timestamp (most recent first)@@ -95,7 +95,7 @@//! This is a git-native cache stored in `.git/refs/remotes/origin/HEAD`. All other data is//! fetched fresh on each `wt list` invocation.//!-//! Refresh with: `wt config state get default-branch --refresh`+//! Clear cache with: `wt config state default-branch clear`//!//! ## Performance Characteristics//!diff --git a/src/git/repository/config.rs b/src/git/repository/config.rsindex 4a20b7868..1c79e71b1 100644--- a/src/git/repository/config.rs+++ b/src/git/repository/config.rs@@ -115,26 +115,10 @@ impl Repository {Ok(count)}- /// Refresh the default branch cache by querying the remote.- ///- /// This forces a network call to `git ls-remote` to fetch the current default- /// branch from the remote, then updates the local cache. Use this when you- /// suspect the cached default branch is stale (e.g., after a repository's- /// default branch has been changed on the remote).- ///- /// Returns the refreshed default branch name.- pub fn refresh_default_branch(&self) -> anyhow::Result<String> {- let remote = self.primary_remote()?;- let branch = self.query_remote_default_branch(&remote)?;- // Update worktrunk's cache- let _ = self.run_command(&["config", "worktrunk.default-branch", &branch]);- Ok(branch)- }-/// Set the default branch manually.///- /// This sets worktrunk's cache (`worktrunk.default-branch`). Use `--refresh`- /// to re-query the remote and update git's cache.+ /// This sets worktrunk's cache (`worktrunk.default-branch`). Use `clear` then+ /// `get` to re-detect from remote.pub fn set_default_branch(&self, branch: &str) -> anyhow::Result<()> {self.run_command(&["config", "worktrunk.default-branch", branch])?;Ok(())diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rsindex ccae3618b..a1a8d74db 100644--- a/src/git/repository/mod.rs+++ b/src/git/repository/mod.rs@@ -317,8 +317,8 @@ impl Repository {/// Detect the default branch without using worktrunk's cache.///- /// Used by `default_branch()` to populate the cache, and by- /// `wt config state get default-branch --refresh` to force re-detection.+ /// Used by `default_branch()` to populate the cache, and after+ /// `wt config state default-branch clear` to force re-detection.pub fn detect_default_branch(&self) -> anyhow::Result<String> {// Try to get from the primary remoteif let Ok(remote) = self.primary_remote() {diff --git a/src/main.rs b/src/main.rsindex 6bcb0d633..4b70291b4 100644--- a/src/main.rs+++ b/src/main.rs@@ -1002,10 +1002,9 @@ fn main() {ConfigCommand::Show { full } => handle_config_show(full),ConfigCommand::State { action } => match action {StateCommand::DefaultBranch { action } => match action {- Some(DefaultBranchAction::Get { refresh }) => {- handle_state_get("default-branch", refresh, None)+ Some(DefaultBranchAction::Get) | None => {+ handle_state_get("default-branch", None)}- None => handle_state_get("default-branch", false, None),Some(DefaultBranchAction::Set { branch }) => {handle_state_set("default-branch", branch, None)}@@ -1015,7 +1014,7 @@ fn main() {},StateCommand::PreviousBranch { action } => match action {Some(PreviousBranchAction::Get) | None => {- handle_state_get("previous-branch", false, None)+ handle_state_get("previous-branch", None)}Some(PreviousBranchAction::Set { branch }) => {handle_state_set("previous-branch", branch, None)@@ -1025,17 +1024,15 @@ fn main() {}},StateCommand::CiStatus { action } => match action {- Some(CiStatusAction::Get { refresh, branch }) => {- handle_state_get("ci-status", refresh, branch)- }- None => handle_state_get("ci-status", false, None),+ Some(CiStatusAction::Get { branch }) => handle_state_get("ci-status", branch),+ None => handle_state_get("ci-status", None),Some(CiStatusAction::Clear { branch, all }) => {handle_state_clear("ci-status", branch, all)}},StateCommand::Marker { action } => match action {- Some(MarkerAction::Get { branch }) => handle_state_get("marker", false, branch),- None => handle_state_get("marker", false, None),+ Some(MarkerAction::Get { branch }) => handle_state_get("marker", branch),+ None => handle_state_get("marker", None),Some(MarkerAction::Set { value, branch }) => {handle_state_set("marker", value, branch)}@@ -1044,7 +1041,7 @@ fn main() {}},StateCommand::Logs { action } => match action {- Some(LogsAction::Get) | None => handle_state_get("logs", false, None),+ Some(LogsAction::Get) | None => handle_state_get("logs", None),Some(LogsAction::Clear) => handle_state_clear("logs", None, false),},StateCommand::Hints { action } => match action {diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snapindex 19c7c84f3..df2a6e7ba 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap@@ -9,7 +9,7 @@ info:- "--help"env:CLICOLOR_FORCE: "1"- COLUMNS: "150"+ COLUMNS: "500"GIT_EDITOR: ""RUST_LOG: warnSOURCE_DATE_EPOCH: "1735776000"@@ -66,4 +66,4 @@ Caches GitHub/GitLab CI status for display in [2mwt list[0m.See [2mwt list[0m CI status for display symbols and colors.-Without a subcommand, runs [2mget[0m for the current branch. Use [2mget --refresh[0m to force re-fetch or [2mclear --all[0m to reset cache.+Without a subcommand, runs [2mget[0m for the current branch. Use [2mclear[0m to reset cache for a branch or [2mclear --all[0m to reset all.diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_default_branch.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_default_branch.snapindex 11d4e96af..1e6ac9326 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_state_default_branch.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_default_branch.snap@@ -49,7 +49,7 @@ Useful in scripts to avoid hardcoding [2mmain[0m or [2mmaster[0m:[2mgit rebase $(wt config state default-branch)-Without a subcommand, runs [2mget[0m. Use [2mset[0m to override, [2mget --refresh[0m to re-detect, or [2mclear[0m to reset.+Without a subcommand, runs [2mget[0m. Use [2mset[0m to override, or [2mclear[0m then [2mget[0m to re-detect.[32mDetection