Skip to content

Commit

Permalink
feat: print uncommitted patches
Browse files Browse the repository at this point in the history
The newly uncommitted patches are printed using the conventions for applied
patches. Without this printing, the user only output provided to the user
is the topmost patch, which may or may not be one of the newly uncommitted
patches.
  • Loading branch information
jpgrayson committed Aug 19, 2023
1 parent 56c9249 commit 4d7c275
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/stack/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ impl<'repo> StackTransaction<'repo> {
);
new_applied.push(patchname.clone());
}
self.ui.print_uncommitted(new_applied.as_ref())?;
new_applied.append(&mut self.applied);
self.applied = new_applied;
Ok(())
Expand Down
18 changes: 18 additions & 0 deletions src/stack/transaction/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ impl TransactionUserInterface {
Ok(())
}

pub(super) fn print_uncommitted(&mut self, uncommitted: &[PatchName]) -> Result<()> {
if !uncommitted.is_empty() {
let mut output = self.output.borrow_mut();
let mut color_spec = termcolor::ColorSpec::new();
output.set_color(color_spec.set_fg(Some(termcolor::Color::Green)))?;
write!(output, "+ ")?;
output.set_color(color_spec.set_fg(None))?;
let first = uncommitted.first().unwrap();
if uncommitted.len() == 1 {
writeln!(output, "{first}")?;
} else {
let last = uncommitted.last().unwrap();
writeln!(output, "{first}..{last}")?;
}
}
Ok(())
}

pub(super) fn print_deleted(&self, deleted: &[PatchName]) -> Result<()> {
if !deleted.is_empty() {
let mut output = self.output.borrow_mut();
Expand Down

0 comments on commit 4d7c275

Please sign in to comment.