Skip to content

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

feat(rebase): Display git output for conflicts

Maximilian Roos977640c81018
diff --git a/src/commands/dev.rs b/src/commands/dev.rs
index 03926822e..32190c04f 100644
--- a/src/commands/dev.rs
+++ b/src/commands/dev.rs
@@ -324,9 +324,15 @@ pub fn handle_dev_rebase(target: Option<&str>) -> Result<(), GitError> {
if let Some(state) = repo.worktree_state()?
&& state.starts_with("REBASING")
{
+ // Extract git's stderr output from the error
+ let git_output = match &e {
+ GitError::CommandFailed(msg) => msg.clone(),
+ _ => e.to_string(),
+ };
return Err(GitError::RebaseConflict {
state,
target_branch: target_branch.to_string(),
+ git_output,
});
}
// Not a rebase conflict, return original error
@@ -341,6 +347,7 @@ pub fn handle_dev_rebase(target: Option<&str>) -> Result<(), GitError> {
return Err(GitError::RebaseConflict {
state,
target_branch: target_branch.to_string(),
+ git_output: String::new(), // No error output in this edge case
});
}
diff --git a/src/git.rs b/src/git.rs
index a3b5700ef..75bfdfabc 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -68,6 +68,7 @@ pub enum GitError {
RebaseConflict {
state: String,
target_branch: String,
+ git_output: String,
},
}
@@ -227,14 +228,30 @@ impl std::fmt::Display for GitError {
// Rebase conflict
GitError::RebaseConflict {
- state,
+ state: _,
target_branch,
+ git_output,
} => {
+ use crate::styling::format_with_gutter;
let error_bold = ERROR.bold();
+
write!(
f,
- "{ERROR_EMOJI} {ERROR}Rebase onto {ERROR:#}{error_bold}{target_branch}{error_bold:#}{ERROR} incomplete: {state}{ERROR:#}\n\n{HINT_EMOJI} {HINT}Resolve conflicts and run 'git rebase --continue'{HINT:#}\n{HINT_EMOJI} {HINT}Or abort with 'git rebase --abort'{HINT:#}"
- )
+ "{ERROR_EMOJI} {ERROR}Rebase onto {ERROR:#}{error_bold}{target_branch}{error_bold:#}{ERROR} incomplete{ERROR:#}"
+ )?;
+
+ if !git_output.is_empty() {
+ writeln!(f)?;
+ write!(f, "{}", format_with_gutter(git_output, "", None))?;
+ } else {
+ // Fallback hints if no git output (edge case)
+ write!(
+ f,
+ "\n\n{HINT_EMOJI} {HINT}Resolve conflicts and run 'git rebase --continue'{HINT:#}\n{HINT_EMOJI} {HINT}Or abort with 'git rebase --abort'{HINT:#}"
+ )?;
+ }
+
+ Ok(())
}
}
}
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_rebase_conflict.snap b/tests/snapshots/integration__integration_tests__merge__merge_rebase_conflict.snap
index 35571ea86..46c27d504 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_rebase_conflict.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_rebase_conflict.snap
@@ -12,11 +12,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpkIyPq0/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpDxsSjV/test-config.toml
---
success: false
exit_code: 1
@@ -25,7 +24,11 @@ exit_code: 1
πŸ”„ Rebasing onto main...
----- stderr -----
-❌ Rebase onto main incomplete: REBASING 1/1
-
-πŸ’‘ Resolve conflicts and run 'git rebase --continue'
-πŸ’‘ Or abort with 'git rebase --abort'
+❌ Rebase onto main incomplete
+  Rebasing (1/1) error: could not apply [SHA]... Update shared.txt in feature
+  hint: Resolve all conflicts manually, mark them as resolved with
+  hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
+  hint: You can instead skip this commit: run "git rebase --skip".
+  hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
+  hint: Disable this message with "git config set advice.mergeConflict false"
+  Could not apply [SHA]... # Update shared.txt in feature