Skip to content

Commit

Permalink
fix: collect stderr and print it afterwards to avoid intersection w…
Browse files Browse the repository at this point in the history
…ith line progress. (#450)

Previously it would happen that stderr would be printed directly and mix
with the line progress (as in `-v`) which also prints to stderr.

Now errors are collected and output at the end once the line renderer
was already shutdown.
  • Loading branch information
Byron committed Oct 17, 2022
1 parent 91798ae commit 3a05328
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
19 changes: 2 additions & 17 deletions gitoxide-core/src/repository/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) mod function {
let (repo, outcome) = if bare {
(checkout.persist(), None)
} else {
let (repo, outcome) = checkout.main_worktree(&mut progress, &git::interrupt::IS_INTERRUPTED)?;
let (repo, outcome) = checkout.main_worktree(progress, &git::interrupt::IS_INTERRUPTED)?;
(repo, Some(outcome))
};

Expand All @@ -80,22 +80,7 @@ pub(crate) mod function {
}
};

if let Some(git::worktree::index::checkout::Outcome {
files_updated,
bytes_written,
collisions,
errors,
}) = outcome
{
progress.set_name("checkout");
progress.done(format!(
"{} files ({})",
files_updated,
git::progress::bytes()
.unwrap()
.display(bytes_written as usize, None, None)
));

if let Some(git::worktree::index::checkout::Outcome { collisions, errors, .. }) = outcome {
if !(collisions.is_empty() && errors.is_empty()) {
let mut messages = Vec::new();
if !errors.is_empty() {
Expand Down
8 changes: 5 additions & 3 deletions src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,18 @@ pub mod pretty {
run(progress::DoOrDiscard::from(None), &mut stdout_lock, &mut stderr_lock)
}
(true, false) => {
let progress = crate::shared::progress_tree();
use crate::shared::{self, STANDARD_RANGE};
let progress = shared::progress_tree();
let sub_progress = progress.add_child(name);

use crate::shared::{self, STANDARD_RANGE};
let handle = shared::setup_line_renderer_range(&progress, range.into().unwrap_or(STANDARD_RANGE));

let mut out = Vec::<u8>::new();
let res = run(progress::DoOrDiscard::from(Some(sub_progress)), &mut out, &mut stderr());
let mut err = Vec::<u8>::new();
let res = run(progress::DoOrDiscard::from(Some(sub_progress)), &mut out, &mut err);
handle.shutdown_and_wait();
std::io::Write::write_all(&mut stdout(), &out)?;
std::io::Write::write_all(&mut stderr(), &err)?;
res
}
#[cfg(not(feature = "prodash-render-tui"))]
Expand Down

0 comments on commit 3a05328

Please sign in to comment.