Skip to content

Commit 0e60862

Browse files
committed
feat: parse git status --porcelain output
1 parent 923199e commit 0e60862

File tree

3 files changed

+165
-19
lines changed

3 files changed

+165
-19
lines changed

Cargo.lock

Lines changed: 114 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ edition = "2021"
99
gix = {version = "0.53", default-features = false, features = ["max-performance-safe", "revision"]}
1010
anyhow = "1.0"
1111
env_logger = "0.10"
12-
log = "0.4"
12+
log = "0.4"
13+
# clap = { version = "4.4", features = ["derive"] }
14+
console = "0.15"

src/main.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use anyhow::{anyhow, Result};
2+
use console::style;
23
use gix::state::InProgress;
34
use gix::{
45
sec::{self, trust::DefaultForLevel},
56
Repository, ThreadSafeRepository,
67
};
78
use log::debug;
9+
use std::process::Command;
810
use std::{path::PathBuf, process::exit};
911

1012
pub struct Repo {
@@ -29,20 +31,62 @@ pub struct Repo {
2931

3032
fn main() {
3133
env_logger::init();
34+
3235
let path = PathBuf::from(".");
3336

34-
match get_output(path) {
35-
Ok(output) => println!("{output}"),
37+
let s = match get_output(path) {
38+
Ok(output) => output,
3639
Err(e) => {
3740
debug!("{e}");
3841
exit(1);
3942
}
4043
};
44+
45+
let cmd = Command::new("git")
46+
.arg("status")
47+
.arg("--porcelain")
48+
.output()
49+
.ok();
50+
51+
if let Some(cmd) = cmd {
52+
if cmd.status.success() {
53+
let out = String::from_utf8_lossy(&cmd.stdout);
54+
let out = out
55+
.trim()
56+
.split('\n')
57+
.map(|x| x.rsplit_once(" ").map(|x| x.0.trim()));
58+
59+
match out {
60+
_ => {
61+
for i in out {
62+
match i {
63+
None => {
64+
println!("{}", style(s).green());
65+
break;
66+
}
67+
Some("M") => {
68+
println!("{}", style(&s).red());
69+
break;
70+
}
71+
Some("??") => {
72+
println!("{}", style(&s).magenta().bold());
73+
break;
74+
}
75+
_ => continue,
76+
}
77+
}
78+
}
79+
}
80+
} else {
81+
println!("{s}")
82+
}
83+
}
4184
}
4285

4386
fn get_output(path: PathBuf) -> Result<String> {
4487
// custom open options
4588
let repo = get_repo(path)?;
89+
4690
let git_repo = repo.repo.to_thread_local();
4791

4892
let display_name = repo
@@ -113,6 +157,8 @@ fn get_repo(path: PathBuf) -> Result<Repo> {
113157
// let remote = get_remote_repository_info(&repository, branch.as_deref());
114158
let path = repository.path().to_path_buf();
115159

160+
// let fs_monitor_value_is_true = repository;
161+
116162
let repo = Repo {
117163
repo: shared_repo,
118164
branch,

0 commit comments

Comments
 (0)