Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VERGEN_GIT_DIRTY #237

Closed
bouk opened this issue Aug 8, 2023 · 3 comments
Closed

Add VERGEN_GIT_DIRTY #237

bouk opened this issue Aug 8, 2023 · 3 comments

Comments

@bouk
Copy link

bouk commented Aug 8, 2023

Should have the value 'true' or 'false' depending on whether the git tree was dirty

@bouk bouk changed the title All VERGEN_GIT_DIRTY Add VERGEN_GIT_DIRTY Aug 9, 2023
@kwinz
Copy link

kwinz commented Oct 12, 2023

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?

@hgomersall
Copy link
Contributor

I've just submitted a merge request to address this in #281 .

@CraZySacX
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants