Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Add target_branch to push-related error variants
Maximilian Roosffa8151aabb8
diff --git a/src/commands/repository_ext.rs b/src/commands/repository_ext.rsindex 9af029729..bb2c26061 100644--- a/src/commands/repository_ext.rs+++ b/src/commands/repository_ext.rs@@ -252,6 +252,7 @@ impl RepositoryCliExt for Repository {if !overlapping.is_empty() {return Err(GitError::ConflictingChanges {+ target_branch: target_branch.to_string(),files: overlapping,worktree_path: wt_path.clone(),}diff --git a/src/commands/worktree.rs b/src/commands/worktree.rsindex de0e3aa7f..3cfe4d43d 100644--- a/src/commands/worktree.rs+++ b/src/commands/worktree.rs@@ -988,7 +988,10 @@ pub fn handle_push(// Check for merge commits unless allowedlet has_merge_commits = repo.has_merge_commits(&target_branch, "HEAD")?;if !allow_merge_commits && has_merge_commits {- return Err(GitError::MergeCommitsFound.into());+ return Err(GitError::MergeCommitsFound {+ target_branch: target_branch.clone(),+ }+ .into());}// Check for conflicting changes in target worktree (auto-stash safe changes)@@ -1085,6 +1088,7 @@ pub fn handle_push(}// CommandFailed contains raw git output, wrap in PushFailed for proper formattingreturn Err(GitError::PushFailed {+ target_branch: target_branch.clone(),error: e.to_string(),}.into());diff --git a/src/git/error.rs b/src/git/error.rsindex 7d32997c0..e31d1d9e4 100644--- a/src/git/error.rs+++ b/src/git/error.rs@@ -92,6 +92,7 @@ pub enum GitError {// Merge/push errorsConflictingChanges {+ target_branch: String,files: Vec<String>,worktree_path: PathBuf,},@@ -100,7 +101,9 @@ pub enum GitError {commits_formatted: String,in_merge_context: bool,},- MergeCommitsFound,+ MergeCommitsFound {+ target_branch: String,+ },RebaseConflict {target_branch: String,git_output: String,@@ -109,6 +112,7 @@ pub enum GitError {target_branch: String,},PushFailed {+ target_branch: String,error: String,},@@ -318,13 +322,16 @@ impl std::fmt::Display for GitError {}GitError::ConflictingChanges {+ target_branch,files,worktree_path,} => {writeln!(f,"{}",- error_message("Cannot push: conflicting uncommitted changes in:")+ error_message(cformat!(+ "Can't push to local <bold>{target_branch}</> branch: conflicting uncommitted changes"+ )))?;if !files.is_empty() {let joined_files = files.join("\n");@@ -377,12 +384,14 @@ impl std::fmt::Display for GitError {}}- GitError::MergeCommitsFound => {+ GitError::MergeCommitsFound { target_branch } => {let merge_cmd = suggest_command("merge", &[], &["--allow-merge-commits"]);write!(f,"{}\n\n{}",- error_message("Found merge commits in push range"),+ error_message(cformat!(+ "Can't push to local <bold>{target_branch}</> branch: found merge commits"+ )),hint_message(cformat!("To push non-linear history, run <bright-black>{merge_cmd}</>"))@@ -426,8 +435,13 @@ impl std::fmt::Display for GitError {)}- GitError::PushFailed { error } => {- let header = error_message("Push failed");+ GitError::PushFailed {+ target_branch,+ error,+ } => {+ let header = error_message(cformat!(+ "Can't push to local <bold>{target_branch}</> branch"+ ));write!(f, "{}", format_error_block(header, error))}@@ -978,10 +992,13 @@ mod tests {#[test]fn test_git_error_conflicting_changes() {let err = GitError::ConflictingChanges {+ target_branch: "main".into(),files: vec!["file1.rs".into(), "file2.rs".into()],worktree_path: PathBuf::from("/tmp/repo"),};let display = err.to_string();+ assert!(display.contains("push to local"));+ assert!(display.contains("main"));assert!(display.contains("conflicting"));assert!(display.contains("file1.rs"));}@@ -1010,8 +1027,12 @@ mod tests {#[test]fn test_git_error_merge_commits_found() {- let err = GitError::MergeCommitsFound;+ let err = GitError::MergeCommitsFound {+ target_branch: "main".into(),+ };let display = err.to_string();+ assert!(display.contains("push to local"));+ assert!(display.contains("main"));assert!(display.contains("merge commits"));assert!(display.contains("--allow-merge-commits"));}@@ -1049,10 +1070,12 @@ mod tests {#[test]fn test_git_error_push_failed() {let err = GitError::PushFailed {+ target_branch: "main".into(),error: "rejected".into(),};let display = err.to_string();- assert!(display.contains("Push failed"));+ assert!(display.contains("push to local"));+ assert!(display.contains("main"));assert!(display.contains("rejected"));}@@ -1208,6 +1231,7 @@ mod tests {fn test_git_error_conflicting_changes_empty_files() {// Test with empty files listlet err = GitError::ConflictingChanges {+ target_branch: "main".into(),files: vec![],worktree_path: PathBuf::from("/tmp/repo"),};diff --git a/tests/integration_tests/git_error_display.rs b/tests/integration_tests/git_error_display.rsindex 8f7c25aea..a1712e6e4 100644--- a/tests/integration_tests/git_error_display.rs+++ b/tests/integration_tests/git_error_display.rs@@ -140,6 +140,7 @@ fn display_invalid_reference() {#[test]fn display_push_failed() {let err = GitError::PushFailed {+ target_branch: "main".into(),error: "To /Users/user/workspace/repo/.git\n ! [remote rejected] HEAD -> main (Up-to-date check failed)\nerror: failed to push some refs to '/Users/user/workspace/repo/.git'".into(),};@@ -149,6 +150,7 @@ fn display_push_failed() {#[test]fn display_conflicting_changes() {let err = GitError::ConflictingChanges {+ target_branch: "main".into(),files: vec!["src/main.rs".into(), "src/lib.rs".into()],worktree_path: PathBuf::from("/tmp/repo.main"),};@@ -180,7 +182,9 @@ fn display_not_fast_forward_merge_context() {#[test]fn display_merge_commits_found() {- let err = GitError::MergeCommitsFound;+ let err = GitError::MergeCommitsFound {+ target_branch: "main".into(),+ };assert_snapshot!("merge_commits_found", err.to_string());}diff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__conflicting_changes.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__conflicting_changes.snapindex 7142e6480..0053efaa6 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__conflicting_changes.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__conflicting_changes.snap@@ -2,7 +2,7 @@source: tests/integration_tests/git_error_display.rsexpression: err.to_string()----[31m✗[39m [31mCannot push: conflicting uncommitted changes in:[39m+[31m✗[39m [31mCan't push to local [1mmain[22m branch: conflicting uncommitted changes[39m[107m [0m src/main.rs[107m [0m src/lib.rsdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__merge_commits_found.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__merge_commits_found.snapindex 6c5a97a19..0300a14b9 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__merge_commits_found.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__merge_commits_found.snap@@ -2,6 +2,6 @@source: tests/integration_tests/git_error_display.rsexpression: err.to_string()----[31m✗[39m [31mFound merge commits in push range[39m+[31m✗[39m [31mCan't push to local [1mmain[22m branch: found merge commits[39m[2m↳[22m [2mTo push non-linear history, run [90mwt merge --allow-merge-commits[39m[22mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__push_failed.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__push_failed.snapindex fe1c09988..cd5305355 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__push_failed.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__push_failed.snap@@ -2,7 +2,7 @@source: tests/integration_tests/git_error_display.rsexpression: err.to_string()----[31m✗[39m [31mPush failed[39m+[31m✗[39m [31mCan't push to local [1mmain[22m branch[39m[107m [0m To /Users/user/workspace/repo/.git[107m [0m ! [remote rejected] HEAD -> main (Up-to-date check failed)[107m [0m error: failed to push some refs to '/Users/user/workspace/repo/.git'diff --git a/tests/snapshots/integration__integration_tests__merge__merge_error_conflicting_changes.snap b/tests/snapshots/integration__integration_tests__merge__merge_error_conflicting_changes.snapindex b54867156..dcb4a77e8 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_error_conflicting_changes.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_error_conflicting_changes.snap@@ -30,7 +30,7 @@ exit_code: 1----- stdout ---------- stderr ------[31m✗[39m [31mCannot push: conflicting uncommitted changes in:[39m+[31m✗[39m [31mCan't push to local [1mmain[22m branch: conflicting uncommitted changes[39m[107m [0m shared.txt[2m↳[22m [2mCommit or stash these changes in _REPO_.main-wt first[22mdiff --git a/tests/snapshots/integration__integration_tests__push__push_dirty_target_overlap.snap b/tests/snapshots/integration__integration_tests__push__push_dirty_target_overlap.snapindex f7f2f52d0..43bc90aae 100644--- a/tests/snapshots/integration__integration_tests__push__push_dirty_target_overlap.snap+++ b/tests/snapshots/integration__integration_tests__push__push_dirty_target_overlap.snap@@ -31,7 +31,7 @@ exit_code: 1----- stdout ---------- stderr ------[31m✗[39m [31mCannot push: conflicting uncommitted changes in:[39m+[31m✗[39m [31mCan't push to local [1mmain[22m branch: conflicting uncommitted changes[39m[107m [0m conflict.txt[2m↳[22m [2mCommit or stash these changes in _REPO_ first[22mdiff --git a/tests/snapshots/integration__integration_tests__push__push_dirty_target_overlap_renamed_file.snap b/tests/snapshots/integration__integration_tests__push__push_dirty_target_overlap_renamed_file.snapindex 020b00cc6..811df3c2c 100644--- a/tests/snapshots/integration__integration_tests__push__push_dirty_target_overlap_renamed_file.snap+++ b/tests/snapshots/integration__integration_tests__push__push_dirty_target_overlap_renamed_file.snap@@ -31,7 +31,7 @@ exit_code: 1----- stdout ---------- stderr ------[31m✗[39m [31mCannot push: conflicting uncommitted changes in:[39m+[31m✗[39m [31mCan't push to local [1mmain[22m branch: conflicting uncommitted changes[39m[107m [0m file.txt[2m↳[22m [2mCommit or stash these changes in _REPO_ first[22mdiff --git a/tests/snapshots/integration__integration_tests__push__push_error_with_merge_commits.snap b/tests/snapshots/integration__integration_tests__push__push_error_with_merge_commits.snapindex 6ac694107..c8c38c616 100644--- a/tests/snapshots/integration__integration_tests__push__push_error_with_merge_commits.snap+++ b/tests/snapshots/integration__integration_tests__push__push_error_with_merge_commits.snap@@ -31,6 +31,6 @@ exit_code: 1----- stdout ---------- stderr ------[31m✗[39m [31mFound merge commits in push range[39m+[31m✗[39m [31mCan't push to local [1mmain[22m branch: found merge commits[39m[2m↳[22m [2mTo push non-linear history, run [90mwt merge --allow-merge-commits[39m[22m