Skip to content

Commit

Permalink
feat: add gix env to print paths relevant to the Git installation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 11, 2025
1 parent 51bbb86 commit 60c3de3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
40 changes: 40 additions & 0 deletions gitoxide-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#![deny(rust_2018_idioms)]
#![forbid(unsafe_code)]

use anyhow::bail;
use std::str::FromStr;

#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
Expand Down Expand Up @@ -82,6 +83,45 @@ pub mod repository;
mod discover;
pub use discover::discover;

pub fn env(mut out: impl std::io::Write, format: OutputFormat) -> anyhow::Result<()> {
if format != OutputFormat::Human {
bail!("JSON output isn't supported");
};

let width = 15;
writeln!(
out,
"{field:>width$}: {}",
std::path::Path::new(gix::path::env::shell()).display(),
field = "shell",
)?;
writeln!(
out,
"{field:>width$}: {:?}",
gix::path::env::installation_config_prefix(),
field = "config prefix",
)?;
writeln!(
out,
"{field:>width$}: {:?}",
gix::path::env::installation_config(),
field = "config",
)?;
writeln!(
out,
"{field:>width$}: {}",
gix::path::env::exe_invocation().display(),
field = "git exe",
)?;
writeln!(
out,
"{field:>width$}: {:?}",
gix::path::env::system_prefix(),
field = "system prefix",
)?;
Ok(())
}

#[cfg(all(feature = "async-client", feature = "blocking-client"))]
compile_error!("Cannot set both 'blocking-client' and 'async-client' features as they are mutually exclusive");

Expand Down
9 changes: 9 additions & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ pub fn main() -> Result<()> {
}

match cmd {
Subcommands::Env => prepare_and_run(
"env",
trace,
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, _err| core::env(out, format),
),
Subcommands::Merge(merge::Platform { cmd }) => match cmd {
merge::SubCommands::File {
resolve_with,
Expand Down
1 change: 1 addition & 0 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub enum Subcommands {
Corpus(corpus::Platform),
MergeBase(merge_base::Command),
Merge(merge::Platform),
Env,
Diff(diff::Platform),
Log(log::Platform),
Worktree(worktree::Platform),
Expand Down

0 comments on commit 60c3de3

Please sign in to comment.