Skip to content

Commit

Permalink
Pass color option to git
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Oct 31, 2024
1 parent edfb398 commit 6a42bcd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fmt::Write as _;
use std::io::Write as _;
use std::path::{Path, PathBuf};

use anstream::ColorChoice;
use anyhow::Result;
use futures::stream::FuturesUnordered;
use futures::StreamExt;
Expand All @@ -11,7 +12,7 @@ use owo_colors::{OwoColorize, Style};
use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator};
use regex::Regex;
use tokio::process::Command;
use tracing::{debug, trace};
use tracing::{debug, error};
use unicode_width::UnicodeWidthStr;

use crate::cli::ExitStatus;
Expand Down Expand Up @@ -311,11 +312,17 @@ async fn run_hooks(

if !success && show_diff_on_failure {
writeln!(printer.stdout(), "All changes made by hooks:")?;
// TODO: color
let color = match ColorChoice::global() {
ColorChoice::Auto => "auto",
ColorChoice::Always | ColorChoice::AlwaysAnsi => "always",
ColorChoice::Never => "never",
};
Command::new("git")
.arg("diff")
.arg("--no-ext-diff")
.arg("--no-pager")
.arg("--color")
.arg(color)
.spawn()?
.wait()
.await?;
Expand Down Expand Up @@ -364,7 +371,7 @@ async fn run_hook(
match tags_from_path(path) {
Ok(tags) => filter.filter(&tags),
Err(err) => {
trace!("Failed to get tags for {filename}: {err}");
error!("Failed to get tags for {filename}: {err}");
false
}
}
Expand Down

0 comments on commit 6a42bcd

Please sign in to comment.