extrawurst / gitui

Blazing 💥 fast terminal-ui for git written in rust 🦀
MIT License
17.98k stars 550 forks source link

installing gitui releases from source results in a "nightly" version string by default #2254

Open decathorpe opened 2 months ago

decathorpe commented 2 months ago

Running cargo install gitui as documented here: https://github.com/extrawurst/gitui?tab=readme-ov-file#cargo-install

Results in gitui --version returning: gitui nightly 2024-06-02 () (replace 2024-06-02 with the current date)

I'm also having trouble making this work sensibly for the Fedora Linux package for gitui.

I can easily set GITUI_RELEASE=1, but then the get_git_hash() function from build.rs will fail hard (with an std::io::Error: No such file or directory) if git is not installed in the build environment. And if git is available, it will either return "" (in the case where the git command fails with no output on stdout) or random garbage if there is an unrelated git repository in any of the parent directories.

Would you accept a PR that adapted build.rs to work better in more cases, for example, when git is not available?

extrawurst commented 2 months ago

please checkout #2187 and the newly introduced BUILD_GIT_COMMIT_ID env var. does this not solve the issue of building from source without git?

the cargo install gitui problem to turning out with a nightly version string is a bit tricky. not sure if this can be fixed. maybe I have to reverse and pick the cargo package version by default and set nightly via env

decathorpe commented 2 months ago

please checkout #2187 and the newly introduced BUILD_GIT_COMMIT_ID env var. does this not solve the issue of building from source without git?

This would work. However, I don't want to introduce another manual step into the process of updating our packages. I'd have to look up the commit hash that corresponds to the tagged release for every new release, and I can't automate that. I could set BUILD_GIT_COMMIT_ID to some garbage data, but that would just end up as garbage in gitui --version :(

If the git commit hash cannot be determined, maybe it would be better to just exclude it from the format string? i.e. something like

if let Some(hash) = commit_hash {
    format!("{} {} ({})", gitui_version, source_date, hash)
} else {
    format!("{} {}", gitui_version, source_date)
}

the cargo install gitui problem to turning out with a nightly version string is a bit tricky. not sure if this can be fixed. maybe I have to reverse and pick the cargo package version by default and set nightly via env

Yeah, I'm not sure how to fix this either. Maybe set the version string to "nightly" only if the git commit hash can be determined and GITUI_RELEASE is not set? That way a build from git could be made a "release" build, but builds from git would be "nightly" by default. I think you already set GITUI_RELEASE in your github workflows, so those would not be affected.