Closed bouk closed 8 months ago
I just had the same need. I programmed this myself:
let has_uncommited_uncached_changes = Command::new("git")
.args(&["diff", "--quiet"])
.status()
.unwrap()
.code()
.unwrap()
!= 0;
let has_uncommited_cached_changes = Command::new("git")
.args(&["diff", "--cached", "--quiet"])
.status()
.unwrap()
.code()
.unwrap()
!= 0;
println!(
"cargo:rustc-env=GIT_DIRTY={}",
if has_uncommited_uncached_changes || has_uncommited_cached_changes {
"uncommited-changes"
} else {
"clean"
}
);
I called it "uncommited-changes" instead of "dirty" because I also wanted to include changes that are staged but not commited yet.
It works mostly, but in some rare cases cargo doesn't notice that the dirty status of some file changed and it needs to rebuild. Any idea how to fix this?
I've just submitted a merge request to address this in #281 .
This has been added as of release 8.2.7 for the git2
and gitcl
feature. gix
support will be added when gix-status
implementation is more complete.
Should have the value 'true' or 'false' depending on whether the git tree was dirty