Skip to content

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

refactor: clarify target/integration naming across codebase (#755)

Maximilian Roos1875251bd09c
diff --git a/src/commands/branch_deletion.rs b/src/commands/branch_deletion.rs
index 485716612..c149bb084 100644
--- a/src/commands/branch_deletion.rs
+++ b/src/commands/branch_deletion.rs
@@ -20,14 +20,14 @@ pub enum BranchDeletionOutcome {
pub struct BranchDeletionResult {
pub outcome: BranchDeletionOutcome,
/// The target that was actually checked against (may be upstream if ahead of local)
- pub effective_target: String,
+ pub integration_target: String,
}
/// Attempt to delete a branch if it's integrated or force_delete is set.
///
/// Returns `BranchDeletionResult` with:
/// - `outcome`: Whether/why deletion occurred
-/// - `effective_target`: The ref checked against (may be upstream if ahead of local)
+/// - `integration_target`: The ref checked against (may be upstream if ahead of local)
pub fn delete_branch_if_safe(
repo: &Repository,
branch_name: &str,
@@ -51,7 +51,7 @@ pub fn delete_branch_if_safe(
Ok(BranchDeletionResult {
outcome,
- effective_target,
+ integration_target: effective_target,
})
}
diff --git a/src/commands/list/collect/results.rs b/src/commands/list/collect/results.rs
index 50d7d49b0..56ae5a641 100644
--- a/src/commands/list/collect/results.rs
+++ b/src/commands/list/collect/results.rs
@@ -67,7 +67,7 @@ pub(super) fn apply_default(
status_contexts[idx].has_working_tree_conflicts = None;
}
TaskKind::GitOperation => {
- // Already defaults to GitOperationState::None in WorktreeData
+ // Already defaults to ActiveGitOperation::None in WorktreeData
}
TaskKind::UserMarker => {
// Already defaults to None
diff --git a/src/commands/list/collect/tasks.rs b/src/commands/list/collect/tasks.rs
index 71b88089b..2cef932af 100644
--- a/src/commands/list/collect/tasks.rs
+++ b/src/commands/list/collect/tasks.rs
@@ -7,7 +7,7 @@ use worktrunk::git::{LineDiff, Repository};
use super::super::ci_status::PrStatus;
use super::super::model::{
- AheadBehind, BranchDiffTotals, CommitDetails, GitOperationState, UpstreamStatus,
+ ActiveGitOperation, AheadBehind, BranchDiffTotals, CommitDetails, UpstreamStatus,
WorkingTreeStatus,
};
use super::types::{ErrorCause, TaskError, TaskKind, TaskResult};
@@ -512,7 +512,7 @@ impl Task for GitOperationTask {
.branch_ref
.working_tree(&ctx.repo)
.expect("GitOperationTask requires a worktree");
- let git_operation = detect_git_operation(&wt);
+ let git_operation = detect_active_git_operation(&wt);
Ok(TaskResult::GitOperation {
item_idx: ctx.item_idx,
git_operation,
@@ -654,13 +654,15 @@ impl Task for UrlStatusTask {
// ============================================================================
/// Detect if a worktree is in the middle of a git operation (rebase/merge).
-pub(crate) fn detect_git_operation(wt: &worktrunk::git::WorkingTree<'_>) -> GitOperationState {
+pub(crate) fn detect_active_git_operation(
+ wt: &worktrunk::git::WorkingTree<'_>,
+) -> ActiveGitOperation {
if wt.is_rebasing().unwrap_or(false) {
- GitOperationState::Rebase
+ ActiveGitOperation::Rebase
} else if wt.is_merging().unwrap_or(false) {
- GitOperationState::Merge
+ ActiveGitOperation::Merge
} else {
- GitOperationState::None
+ ActiveGitOperation::None
}
}
diff --git a/src/commands/list/collect/types.rs b/src/commands/list/collect/types.rs
index 918428b2b..58884c945 100644
--- a/src/commands/list/collect/types.rs
+++ b/src/commands/list/collect/types.rs
@@ -10,7 +10,7 @@ use worktrunk::git::LineDiff;
use super::super::ci_status::PrStatus;
use super::super::model::{
- AheadBehind, BranchDiffTotals, CommitDetails, GitOperationState, ListItem, UpstreamStatus,
+ ActiveGitOperation, AheadBehind, BranchDiffTotals, CommitDetails, ListItem, UpstreamStatus,
WorkingTreeStatus,
};
@@ -129,7 +129,7 @@ pub(crate) enum TaskResult {
/// Git operation in progress (rebase/merge)
GitOperation {
item_idx: usize,
- git_operation: GitOperationState,
+ git_operation: ActiveGitOperation,
},
/// User-defined status from git config
UserMarker {
diff --git a/src/commands/list/json_output.rs b/src/commands/list/json_output.rs
index 2a997530c..d5eb62221 100644
--- a/src/commands/list/json_output.rs
+++ b/src/commands/list/json_output.rs
@@ -455,8 +455,8 @@ mod tests {
use super::*;
use crate::commands::list::ci_status::CiStatus;
use crate::commands::list::model::{
- Divergence, GitOperationState, MainState, OperationState, StatusSymbols, WorkingTreeStatus,
- WorktreeData, WorktreeState,
+ ActiveGitOperation, Divergence, MainState, OperationState, StatusSymbols,
+ WorkingTreeStatus, WorktreeData, WorktreeState,
};
// ============================================================================
@@ -631,7 +631,7 @@ mod tests {
locked: None,
prunable: None,
working_tree_diff: None,
- git_operation: GitOperationState::None,
+ git_operation: ActiveGitOperation::None,
branch_worktree_mismatch: false,
working_diff_display: None,
}
diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rs
index f5e0bc550..7088792ec 100644
--- a/src/commands/list/layout.rs
+++ b/src/commands/list/layout.rs
@@ -1183,7 +1183,7 @@ mod tests {
#[test]
fn test_visible_columns_follow_gap_rule() {
use crate::commands::list::model::{
- AheadBehind, BranchDiffTotals, CommitDetails, DisplayFields, GitOperationState,
+ ActiveGitOperation, AheadBehind, BranchDiffTotals, CommitDetails, DisplayFields,
ItemKind, ListItem, StatusSymbols, UpstreamStatus, WorktreeData,
};
@@ -1223,7 +1223,7 @@ mod tests {
locked: None,
prunable: None,
working_tree_diff: Some(LineDiff::from((100, 50))),
- git_operation: GitOperationState::None,
+ git_operation: ActiveGitOperation::None,
is_main: false,
is_current: false,
is_previous: false,
@@ -1285,7 +1285,7 @@ mod tests {
#[test]
fn test_column_positions_with_empty_columns() {
use crate::commands::list::model::{
- AheadBehind, BranchDiffTotals, CommitDetails, DisplayFields, GitOperationState,
+ ActiveGitOperation, AheadBehind, BranchDiffTotals, CommitDetails, DisplayFields,
ItemKind, ListItem, StatusSymbols, UpstreamStatus, WorktreeData,
};
@@ -1321,7 +1321,7 @@ mod tests {
locked: None,
prunable: None,
working_tree_diff: Some(LineDiff::default()),
- git_operation: GitOperationState::None,
+ git_operation: ActiveGitOperation::None,
is_main: true, // Primary worktree: no ahead/behind shown
is_current: false,
is_previous: false,
diff --git a/src/commands/list/model/item.rs b/src/commands/list/model/item.rs
index dfb90f54a..a5a822cb7 100644
--- a/src/commands/list/model/item.rs
+++ b/src/commands/list/model/item.rs
@@ -7,7 +7,7 @@ use std::path::PathBuf;
use worktrunk::git::{IntegrationReason, IntegrationSignals, LineDiff, check_integration};
-use super::state::{Divergence, GitOperationState, MainState, OperationState, WorktreeState};
+use super::state::{ActiveGitOperation, Divergence, MainState, OperationState, WorktreeState};
use super::stats::{AheadBehind, BranchDiffTotals, CommitDetails, UpstreamStatus};
use super::status_symbols::{StatusSymbols, WorkingTreeStatus};
use crate::commands::list::ci_status::PrStatus;
@@ -79,8 +79,8 @@ pub struct WorktreeData {
#[serde(skip_serializing_if = "Option::is_none")]
pub working_tree_diff: Option<LineDiff>,
/// Git operation in progress (rebase/merge)
- #[serde(skip_serializing_if = "GitOperationState::is_none")]
- pub git_operation: GitOperationState,
+ #[serde(skip_serializing_if = "ActiveGitOperation::is_none")]
+ pub git_operation: ActiveGitOperation,
pub is_main: bool,
/// Whether this is the current worktree (matches repo discovery path: PWD or `-C`)
#[serde(skip_serializing_if = "std::ops::Not::not")]
@@ -480,9 +480,9 @@ impl ListItem {
// Operation state - priority: conflicts > rebase > merge
let operation_state = if has_conflicts {
OperationState::Conflicts
- } else if data.git_operation == GitOperationState::Rebase {
+ } else if data.git_operation == ActiveGitOperation::Rebase {
OperationState::Rebase
- } else if data.git_operation == GitOperationState::Merge {
+ } else if data.git_operation == ActiveGitOperation::Merge {
OperationState::Merge
} else {
OperationState::None
diff --git a/src/commands/list/model/mod.rs b/src/commands/list/model/mod.rs
index 8fc0bfa5e..422418795 100644
--- a/src/commands/list/model/mod.rs
+++ b/src/commands/list/model/mod.rs
@@ -24,7 +24,7 @@ pub mod statusline_segment;
#[allow(unused_imports)]
pub use item::{DisplayFields, ItemKind, ListData, ListItem, WorktreeData};
#[allow(unused_imports)]
-pub use state::{Divergence, GitOperationState, MainState, OperationState, WorktreeState};
+pub use state::{ActiveGitOperation, Divergence, MainState, OperationState, WorktreeState};
#[allow(unused_imports)]
pub use stats::{ActiveUpstream, AheadBehind, BranchDiffTotals, CommitDetails, UpstreamStatus};
#[allow(unused_imports)]
diff --git a/src/commands/list/model/state.rs b/src/commands/list/model/state.rs
index 5b08dbc07..363abab11 100644
--- a/src/commands/list/model/state.rs
+++ b/src/commands/list/model/state.rs
@@ -315,13 +315,15 @@ impl serde::Serialize for OperationState {
}
}
-/// Git operation state for a worktree
+/// Active git operation in a worktree
///
-/// Represents whether a worktree is in the middle of a git operation.
+/// Represents raw data about whether a worktree is in the middle of a git operation.
+/// This is distinct from [`OperationState`] which is the display enum (includes Conflicts,
+/// has symbols/colors).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, strum::IntoStaticStr)]
#[serde(rename_all = "kebab-case")]
#[strum(serialize_all = "kebab-case")]
-pub enum GitOperationState {
+pub enum ActiveGitOperation {
#[strum(serialize = "")]
#[serde(rename = "")]
#[default]
@@ -332,7 +334,7 @@ pub enum GitOperationState {
Merge,
}
-impl GitOperationState {
+impl ActiveGitOperation {
pub fn is_none(&self) -> bool {
matches!(self, Self::None)
}
@@ -670,19 +672,19 @@ mod tests {
}
// ============================================================================
- // GitOperationState Tests
+ // ActiveGitOperation Tests
// ============================================================================
#[test]
fn test_git_operation_state_default() {
- let state = GitOperationState::default();
- assert_eq!(state, GitOperationState::None);
+ let state = ActiveGitOperation::default();
+ assert_eq!(state, ActiveGitOperation::None);
}
#[test]
fn test_git_operation_state_is_none() {
- assert!(GitOperationState::None.is_none());
- assert!(!GitOperationState::Rebase.is_none());
- assert!(!GitOperationState::Merge.is_none());
+ assert!(ActiveGitOperation::None.is_none());
+ assert!(!ActiveGitOperation::Rebase.is_none());
+ assert!(!ActiveGitOperation::Merge.is_none());
}
}
diff --git a/src/commands/step_commands.rs b/src/commands/step_commands.rs
index bfd650a13..cb15c23cd 100644
--- a/src/commands/step_commands.rs
+++ b/src/commands/step_commands.rs
@@ -119,7 +119,7 @@ pub fn handle_squash(
.unwrap_or_default();
// Get and validate target ref (any commit-ish for merge-base calculation)
- let target_branch = repo.require_target_ref(target)?;
+ let integration_target = repo.require_target_ref(target)?;
// Auto-stage changes before running pre-commit hooks so both beta and merge paths behave identically
match stage_mode {
@@ -152,7 +152,7 @@ pub fn handle_squash(
// Run pre-commit hooks (user first, then project)
if !skip_pre_commit {
- let extra_vars = [("target", target_branch.as_str())];
+ let extra_vars = [("target", integration_target.as_str())];
run_hook_with_filter(
&ctx,
ctx.config.hooks.pre_commit.as_ref(),
@@ -170,7 +170,7 @@ pub fn handle_squash(
// Get merge base with target branch (required for squash)
let merge_base = repo
- .merge_base("HEAD", &target_branch)?
+ .merge_base("HEAD", &integration_target)?
.context("Cannot squash: no common ancestor with target branch")?;
// Count commits since merge base
@@ -183,7 +183,7 @@ pub fn handle_squash(
// Handle different scenarios
if commit_count == 0 && !has_staged {
// No commits and no staged changes - nothing to squash
- return Ok(SquashResult::NoCommitsAhead(target_branch));
+ return Ok(SquashResult::NoCommitsAhead(integration_target));
}
if commit_count == 0 && has_staged {
@@ -240,7 +240,7 @@ pub fn handle_squash(
// Create safety backup before potentially destructive reset if there are working tree changes
if has_staged {
- let backup_message = format!("{} → {} (squash)", current_branch, target_branch);
+ let backup_message = format!("{} → {} (squash)", current_branch, integration_target);
let sha = wt.create_safety_backup(&backup_message)?;
crate::output::print(hint_message(format!("Backup created @ {sha}")))?;
}
@@ -261,7 +261,7 @@ pub fn handle_squash(
.unwrap_or("repo");
let commit_message = crate::llm::generate_squash_message(
- &target_branch,
+ &integration_target,
&merge_base,
&subjects,
&current_branch,
@@ -313,7 +313,7 @@ pub fn step_show_squash_prompt(target: Option<&str>) -> anyhow::Result<()> {
let effective_config = config.commit_generation(project_id.as_deref());
// Get and validate target ref (any commit-ish for merge-base calculation)
- let target_branch = repo.require_target_ref(target)?;
+ let integration_target = repo.require_target_ref(target)?;
// Get current branch
let wt = repo.current_worktree();
@@ -321,7 +321,7 @@ pub fn step_show_squash_prompt(target: Option<&str>) -> anyhow::Result<()> {
// Get merge base with target branch (required for generating squash message)
let merge_base = repo
- .merge_base("HEAD", &target_branch)?
+ .merge_base("HEAD", &integration_target)?
.context("Cannot generate squash message: no common ancestor with target branch")?;
// Get commit subjects for the squash message
@@ -336,7 +336,7 @@ pub fn step_show_squash_prompt(target: Option<&str>) -> anyhow::Result<()> {
.unwrap_or("repo");
let prompt = crate::llm::build_squash_prompt(
- &target_branch,
+ &integration_target,
&merge_base,
&subjects,
&current_branch,
@@ -360,16 +360,16 @@ pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<RebaseResult> {
let repo = Repository::current()?;
// Get and validate target ref (any commit-ish for rebase)
- let target_branch = repo.require_target_ref(target)?;
+ let integration_target = repo.require_target_ref(target)?;
// Check if already up-to-date (linear extension of target, no merge commits)
- if repo.is_rebased_onto(&target_branch)? {
- return Ok(RebaseResult::UpToDate(target_branch));
+ if repo.is_rebased_onto(&integration_target)? {
+ return Ok(RebaseResult::UpToDate(integration_target));
}
// Check if this is a fast-forward or true rebase
let merge_base = repo
- .merge_base("HEAD", &target_branch)?
+ .merge_base("HEAD", &integration_target)?
.context("Cannot rebase: no common ancestor with target branch")?;
let head_sha = repo.run_command(&["rev-parse", "HEAD"])?.trim().to_string();
let is_fast_forward = merge_base == head_sha;
@@ -377,11 +377,11 @@ pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<RebaseResult> {
// Only show progress for true rebases (fast-forwards are instant)
if !is_fast_forward {
crate::output::print(progress_message(cformat!(
- "Rebasing onto <bold>{target_branch}</>..."
+ "Rebasing onto <bold>{integration_target}</>..."
)))?;
}
- let rebase_result = repo.run_command(&["rebase", &target_branch]);
+ let rebase_result = repo.run_command(&["rebase", &integration_target]);
// If rebase failed, check if it's due to conflicts
if let Err(e) = rebase_result {
@@ -391,14 +391,18 @@ pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<RebaseResult> {
// Extract git's stderr output from the error
let git_output = e.to_string();
return Err(worktrunk::git::GitError::RebaseConflict {
- target_branch: target_branch.clone(),
+ target_branch: integration_target.clone(),
git_output,
}
.into());
}
// Not a rebase conflict, return original error
return Err(worktrunk::git::GitError::Other {
- message: cformat!("Failed to rebase onto <bold>{}</>: {}", target_branch, e),
+ message: cformat!(
+ "Failed to rebase onto <bold>{}</>: {}",
+ integration_target,
+ e
+ ),
}
.into());
}
@@ -407,7 +411,7 @@ pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<RebaseResult> {
if let Some(state) = repo.worktree_state()? {
let _ = state; // used for diagnostics
return Err(worktrunk::git::GitError::RebaseConflict {
- target_branch: target_branch.clone(),
+ target_branch: integration_target.clone(),
git_output: String::new(),
}
.into());
@@ -416,11 +420,11 @@ pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<RebaseResult> {
// Success
if is_fast_forward {
crate::output::print(success_message(cformat!(
- "Fast-forwarded to <bold>{target_branch}</>"
+ "Fast-forwarded to <bold>{integration_target}</>"
)))?;
} else {
crate::output::print(success_message(cformat!(
- "Rebased onto <bold>{target_branch}</>"
+ "Rebased onto <bold>{integration_target}</>"
)))?;
}
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index d2e25abaf..6cd1e13d2 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -527,7 +527,7 @@ fn handle_branch_only_output(
let flag_note = get_flag_note(
deletion_mode,
&deletion.outcome,
- Some(&deletion.effective_target),
+ Some(&deletion.integration_target),
);
let flag_text = &flag_note.text;
let flag_after = flag_note.after_green();
@@ -582,8 +582,8 @@ fn spawn_post_switch_after_remove(
struct RemovalDisplayInfo {
/// The deletion outcome (NotDeleted, ForceDeleted, or Integrated)
outcome: BranchDeletionOutcome,
- /// The effective target branch used for integration check
- effective_target: Option<String>,
+ /// The target branch used for integration check (may be upstream if ahead of local)
+ integration_target: Option<String>,
/// Whether the branch was integrated (used for hints when branch is kept)
branch_was_integrated: bool,
/// Whether to show the "unmerged, run -D" hint (foreground only, based on actual deletion)
@@ -603,7 +603,7 @@ impl RemovalDisplayInfo {
target_branch: Option<&str>,
force_worktree: bool,
) -> Self {
- let (outcome, effective_target) = if deletion_mode.should_keep() {
+ let (outcome, integration_target) = if deletion_mode.should_keep() {
(
BranchDeletionOutcome::NotDeleted,
target_branch.map(String::from),
@@ -623,7 +623,7 @@ impl RemovalDisplayInfo {
Self {
outcome,
- effective_target,
+ integration_target,
branch_was_integrated: pre_computed_integration.is_some(),
show_unmerged_hint: false, // Background mode never shows this hint
force_worktree,
@@ -641,13 +641,13 @@ impl RemovalDisplayInfo {
) -> anyhow::Result<Self> {
let branch_was_integrated = pre_computed_integration.is_some();
- let (outcome, effective_target, show_unmerged_hint) = if !deletion_mode.should_keep() {
+ let (outcome, integration_target, show_unmerged_hint) = if !deletion_mode.should_keep() {
let check_target = target_branch.unwrap_or("HEAD");
let result =
delete_branch_if_safe(repo, branch_name, check_target, deletion_mode.is_force());
let (deletion, needs_hint) = handle_branch_deletion_result(result, branch_name, true)?;
- // Only use effective_target for display if we had a real target (not "HEAD" fallback)
- let display_target = target_branch.map(|_| deletion.effective_target);
+ // Only use integration_target for display if we had a real target (not "HEAD" fallback)
+ let display_target = target_branch.map(|_| deletion.integration_target);
(deletion.outcome, display_target, needs_hint)
} else {
(
@@ -659,7 +659,7 @@ impl RemovalDisplayInfo {
Ok(Self {
outcome,
- effective_target,
+ integration_target,
branch_was_integrated,
show_unmerged_hint,
force_worktree,
@@ -683,7 +683,7 @@ impl RemovalDisplayInfo {
BranchDeletionMode::Keep
},
&self.outcome,
- self.effective_target.as_deref(),
+ self.integration_target.as_deref(),
);
let force_text = if self.force_worktree {
" (--force)"
@@ -732,7 +732,7 @@ impl RemovalDisplayInfo {
if deletion_mode.should_keep() && self.branch_was_integrated {
// User kept an integrated branch - show integration info
let reason = pre_computed_integration.as_ref().unwrap();
- let target = self.effective_target.as_deref().unwrap_or("target");
+ let target = self.integration_target.as_deref().unwrap_or("target");
let desc = reason.description();
let symbol = reason.symbol();
super::print(hint_message(cformat!(