chore: import upstream snapshot with attribution
FreeBSD Smoke / FreeBSD Smoke (x86_64) (push) Has been cancelled
CI / Quality Guardrails (push) Has been cancelled
CI / Build & Test (macos-latest) (push) Has been cancelled
CI / Build & Test (ubuntu-latest) (push) Has been cancelled
CI / Build & Test (windows-latest) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / PowerShell Syntax (push) Has been cancelled
CI / Windows Cross-Target Check (Linux) (push) Has been cancelled
FreeBSD Smoke / FreeBSD Smoke (x86_64) (push) Has been cancelled
CI / Quality Guardrails (push) Has been cancelled
CI / Build & Test (macos-latest) (push) Has been cancelled
CI / Build & Test (ubuntu-latest) (push) Has been cancelled
CI / Build & Test (windows-latest) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / PowerShell Syntax (push) Has been cancelled
CI / Windows Cross-Target Check (Linux) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
use crate::session::GitState;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
pub(super) fn trace_enabled() -> bool {
|
||||
match std::env::var("JCODE_TRACE") {
|
||||
Ok(value) => {
|
||||
let value = value.trim();
|
||||
!value.is_empty() && value != "0" && value.to_lowercase() != "false"
|
||||
}
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn git_state_for_dir(dir: &Path) -> Option<GitState> {
|
||||
let root = git_output(dir, &["rev-parse", "--show-toplevel"])?;
|
||||
let head = git_output(dir, &["rev-parse", "HEAD"]);
|
||||
let branch = git_output(dir, &["rev-parse", "--abbrev-ref", "HEAD"]);
|
||||
let dirty = git_output(dir, &["status", "--porcelain"]).map(|out| !out.is_empty());
|
||||
|
||||
Some(GitState {
|
||||
root,
|
||||
head,
|
||||
branch,
|
||||
dirty,
|
||||
})
|
||||
}
|
||||
|
||||
fn git_output(dir: &Path, args: &[&str]) -> Option<String> {
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.current_dir(dir)
|
||||
.output()
|
||||
.ok()?;
|
||||
if !output.status.success() {
|
||||
return None;
|
||||
}
|
||||
Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
}
|
||||
Reference in New Issue
Block a user