Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor: rename advance_and_push to local_push for clarity
Maximilian Roosbf37f1298bde
diff --git a/src/commands/handle_merge_jj.rs b/src/commands/handle_merge_jj.rsindex d962c4cae..0cc4a7268 100644--- a/src/commands/handle_merge_jj.rs+++ b/src/commands/handle_merge_jj.rs@@ -142,8 +142,8 @@ pub fn handle_merge_jj(opts: MergeOptions<'_>) -> anyhow::Result<()> {)?;}- // Push (best-effort — may not have a git remote)- match workspace.advance_and_push(target, &ws_path, Default::default()) {+ // Local push: advance target bookmark to include feature commits+ match workspace.local_push(target, &ws_path, Default::default()) {Ok(result) if result.commit_count > 0 => {eprintln!("{}", success_message(cformat!("Pushed <bold>{target}</>")));}diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 680338fcd..7220d9579 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -4,7 +4,7 @@ use worktrunk::HookType;use worktrunk::config::UserConfig;use worktrunk::git::{GitError, Repository};use worktrunk::styling::{eprintln, info_message, success_message};-use worktrunk::workspace::PushDisplay;+use worktrunk::workspace::LocalPushDisplay;use super::command_approval::approve_command_batch;use super::command_executor::CommandContext;@@ -239,13 +239,13 @@ pub fn handle_merge(opts: MergeOptions<'_>) -> anyhow::Result<()> {}};- // Fast-forward push to target branch via workspace trait+ // Local push: advance target branch ref to include feature commitslet push_result = env.workspace- .advance_and_push(+ .local_push(&target_branch,&env.worktree_path,- PushDisplay {+ LocalPushDisplay {verb: "Merging",notes: &operations_note,},diff --git a/src/commands/step_commands.rs b/src/commands/step_commands.rsindex 223047c83..1c77b2aa9 100644--- a/src/commands/step_commands.rs+++ b/src/commands/step_commands.rs@@ -461,7 +461,7 @@ pub fn handle_squash(/// Handle `wt step push` command.///-/// Fully trait-based: opens the workspace and uses `advance_and_push`+/// Fully trait-based: opens the workspace and uses `local_push`/// for both git and jj, with zero VcsKind branching.////// Each VCS implementation validates push safety internally:@@ -474,7 +474,7 @@ pub fn step_push(target: Option<&str>) -> anyhow::Result<()> {let target = ws.resolve_integration_target(target)?;let result = ws- .advance_and_push(&target, &cwd, Default::default())+ .local_push(&target, &cwd, Default::default()).context("Failed to push")?;if result.commit_count > 0 {diff --git a/src/workspace/git.rs b/src/workspace/git.rsindex ea9e75f44..30524fca5 100644--- a/src/workspace/git.rs+++ b/src/workspace/git.rs@@ -17,13 +17,13 @@ use crate::git::{};use crate::path::format_path_for_display;-use super::types::{IntegrationReason, LineDiff, PushDisplay, path_dir_name};+use super::types::{IntegrationReason, LineDiff, LocalPushDisplay, path_dir_name};use crate::styling::{GUTTER_OVERHEAD, eprintln, format_with_gutter, get_terminal_width, progress_message,warning_message,};-use super::{PushResult, RebaseOutcome, SquashOutcome, VcsKind, Workspace, WorkspaceItem};+use super::{LocalPushResult, RebaseOutcome, SquashOutcome, VcsKind, Workspace, WorkspaceItem};impl Workspace for Repository {fn kind(&self) -> VcsKind {@@ -218,12 +218,12 @@ impl Workspace for Repository {Ok(())}- fn advance_and_push(+ fn local_push(&self,target: &str,_path: &Path,- display: PushDisplay<'_>,- ) -> anyhow::Result<PushResult> {+ display: LocalPushDisplay<'_>,+ ) -> anyhow::Result<LocalPushResult> {// Check fast-forwardif !self.is_ancestor(target, "HEAD")? {let commits_formatted = self@@ -246,7 +246,7 @@ impl Workspace for Repository {let commit_count = self.count_commits(target, "HEAD")?;if commit_count == 0 {- return Ok(PushResult {+ return Ok(LocalPushResult {commit_count: 0,stats_summary: Vec::new(),});@@ -263,7 +263,7 @@ impl Workspace for Repository {// Show progress message, commit graph, and diffstat (between stash and restore)show_push_preview(self, target, commit_count, &range, &display);- // Local push to advance the target branch+ // Local push: advance the target branch ref via git push to local pathlet git_common_dir = self.git_common_dir();let push_target = format!("HEAD:{target}");let push_result = self.run_command(&[@@ -283,7 +283,7 @@ impl Workspace for Repository {error: e.to_string(),})?;- Ok(PushResult {+ Ok(LocalPushResult {commit_count,stats_summary,})@@ -423,7 +423,7 @@ fn show_push_preview(target: &str,commit_count: usize,range: &str,- display: &PushDisplay<'_>,+ display: &LocalPushDisplay<'_>,) {let commit_text = if commit_count == 1 {"commit"@@ -835,17 +835,17 @@ mod tests {let subjects = ws.commit_subjects("main", "commit-branch").unwrap();assert!(subjects.contains(&"trait commit".to_string()));- // advance_and_push via Workspace trait — local push of feature onto main+ // local_push via Workspace trait — local push of feature onto mainlet repo_at_wt = Repository::at(&commit_wt).unwrap();let ws_at_wt: &dyn Workspace = &repo_at_wt;let push_result = ws_at_wt- .advance_and_push("main", &commit_wt, Default::default())+ .local_push("main", &commit_wt, Default::default()).unwrap();assert_eq!(push_result.commit_count, 1);- // advance_and_push with zero commits ahead — returns early+ // local_push with zero commits ahead — returns earlylet push_result = ws_at_wt- .advance_and_push("main", &commit_wt, Default::default())+ .local_push("main", &commit_wt, Default::default()).unwrap();assert_eq!(push_result.commit_count, 0);@@ -929,7 +929,7 @@ mod tests {assert!(matches!(outcome, super::super::RebaseOutcome::Rebased));ws.remove_workspace("rebase-diverged").unwrap();- // advance_and_push with dirty target worktree — exercises stash/restore path+ // local_push with dirty target worktree — exercises stash/restore path// Make main worktree dirty with a non-conflicting filestd::fs::write(repo_path.join("dirty.txt"), "dirty\n").unwrap();// Create a new branch with a commit to push onto main@@ -942,7 +942,7 @@ mod tests {let repo_at_stash = Repository::at(&stash_wt).unwrap();let ws_stash: &dyn Workspace = &repo_at_stash;let push_result = ws_stash- .advance_and_push("main", &stash_wt, Default::default())+ .local_push("main", &stash_wt, Default::default()).unwrap();assert_eq!(push_result.commit_count, 1);// Verify dirty file in main worktree was preserved after stash/restorediff --git a/src/workspace/jj.rs b/src/workspace/jj.rsindex 6671aeec5..88bdec3a0 100644--- a/src/workspace/jj.rs+++ b/src/workspace/jj.rs@@ -9,11 +9,11 @@ use std::path::{Path, PathBuf};use anyhow::Context;use color_print::cformat;-use super::types::{IntegrationReason, LineDiff, PushDisplay};+use super::types::{IntegrationReason, LineDiff, LocalPushDisplay};use crate::shell_exec::Cmd;use crate::styling::{eprintln, progress_message};-use super::{PushResult, RebaseOutcome, SquashOutcome, VcsKind, Workspace, WorkspaceItem};+use super::{LocalPushResult, RebaseOutcome, SquashOutcome, VcsKind, Workspace, WorkspaceItem};/// Jujutsu-backed workspace implementation.///@@ -492,12 +492,12 @@ impl Workspace for JjWorkspace {Ok(())}- fn advance_and_push(+ fn local_push(&self,target: &str,path: &Path,- _display: PushDisplay<'_>,- ) -> anyhow::Result<PushResult> {+ _display: LocalPushDisplay<'_>,+ ) -> anyhow::Result<LocalPushResult> {// Guard: target must be an ancestor of the feature tip.// Prevents moving the bookmark sideways or backward (which would lose commits).if !self.is_rebased_onto(target, path)? {@@ -517,16 +517,16 @@ impl Workspace for JjWorkspace {let commit_count = count_output.lines().filter(|l| !l.is_empty()).count();if commit_count == 0 {- return Ok(PushResult {+ return Ok(LocalPushResult {commit_count: 0,stats_summary: Vec::new(),});}- // Move bookmark to feature tip (local only — no remote push)+ // Move bookmark to feature tip (local only)run_jj_command(path, &["bookmark", "set", target, "-r", &feature_tip])?;- Ok(PushResult {+ Ok(LocalPushResult {commit_count,stats_summary: Vec::new(),})diff --git a/src/workspace/mod.rs b/src/workspace/mod.rsindex da9f3dcdb..bf00684dc 100644--- a/src/workspace/mod.rs+++ b/src/workspace/mod.rs@@ -20,7 +20,7 @@ use std::collections::HashMap;use std::path::{Path, PathBuf};use crate::git::WorktreeInfo;-pub use types::{IntegrationReason, LineDiff, PushDisplay, PushResult, path_dir_name};+pub use types::{IntegrationReason, LineDiff, LocalPushDisplay, LocalPushResult, path_dir_name};pub use detect::detect_vcs;pub use jj::JjWorkspace;@@ -206,22 +206,25 @@ pub trait Workspace: Send + Sync {/// `target` is the branch/bookmark to update on the remote.fn push_to_target(&self, target: &str, path: &Path) -> anyhow::Result<()>;- /// Advance the target branch/bookmark to include current changes, then push.+ /// Advance the target branch ref to include current feature commits (local only).///- /// Git: fast-forward merge target branch to HEAD (local push), with- /// auto-stash/restore of non-conflicting changes in the target worktree.- /// Emits progress messages (commit graph, diffstat) to stderr during the- /// operation.- /// Jj: set bookmark to feature tip, then `jj git push --bookmark`.+ /// "Local push" means moving the target branch pointer forward — no remote+ /// interaction. This is the git term for advancing a ref locally via+ /// `git push <local-path>`.///- /// Returns a [`PushResult`] with commit count and optional stats for the- /// command handler to format the final success message.- fn advance_and_push(+ /// Git: fast-forward the target branch to HEAD, with auto-stash/restore of+ /// non-conflicting changes in the target worktree. Emits progress messages+ /// (commit graph, diffstat) to stderr.+ /// Jj: `jj bookmark set` to move the target bookmark to the feature tip.+ ///+ /// Returns a [`LocalPushResult`] with commit count and optional stats for+ /// the command handler to format the final success message.+ fn local_push(&self,target: &str,path: &Path,- display: PushDisplay<'_>,- ) -> anyhow::Result<PushResult>;+ display: LocalPushDisplay<'_>,+ ) -> anyhow::Result<LocalPushResult>;// ====== Squash ======diff --git a/src/workspace/types.rs b/src/workspace/types.rsindex bd11c1527..faca98bd8 100644--- a/src/workspace/types.rs+++ b/src/workspace/types.rs@@ -111,12 +111,16 @@ impl IntegrationReason {}}-/// Display context for the push progress message.+/// Display context for the local push progress message.////// Controls the verb and optional notes in the progress line emitted by-/// `advance_and_push`. E.g. merge passes `verb: "Merging"` and notes like+/// `local_push`. E.g. merge passes `verb: "Merging"` and notes like/// "(no commit/squash needed)", while step push uses the default "Pushing".-pub struct PushDisplay<'a> {+///+/// "Local push" means advancing a target branch ref to include feature commits —+/// no remote interaction. Git implements this via `git push <local-path>`,+/// jj via `jj bookmark set`.+pub struct LocalPushDisplay<'a> {/// Verb in -ing form for the progress line.pub verb: &'a str,/// Optional parenthetical notes appended after the SHA@@ -125,7 +129,7 @@ pub struct PushDisplay<'a> {pub notes: &'a str,}-impl Default for PushDisplay<'_> {+impl Default for LocalPushDisplay<'_> {fn default() -> Self {Self {verb: "Pushing",@@ -134,11 +138,13 @@ impl Default for PushDisplay<'_> {}}-/// Result of a push operation, with enough data for the command handler+/// Result of a local push operation, with enough data for the command handler/// to format the final success/info message.+///+/// "Local push" means advancing a target branch ref — no remote interaction.#[derive(Debug, Clone)]-pub struct PushResult {- /// Number of commits pushed (0 = already up-to-date).+pub struct LocalPushResult {+ /// Number of commits pushed locally (0 = already up-to-date).pub commit_count: usize,/// Summary parts for the success message parenthetical./// E.g. `["1 commit", "1 file", "+1"]`. Empty for jj or when count is 0.