From 0194dee3a61ee734de58e486d4c2ffcc2b2ac04a Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Tue, 11 Aug 2020 16:43:23 -0500 Subject: [PATCH] Updated version hashing and bumped nu-cli to 0.18.1 (#2331) * Updated version hashing and bumped nu-cli to 0.18.1 * made code pertyer * Update version.rs * Update version.rs Co-authored-by: Jonathan Turner --- Cargo.lock | 12 +++++++- Cargo.toml | 2 +- crates/nu-cli/Cargo.toml | 3 +- crates/nu-cli/build.rs | 41 --------------------------- crates/nu-cli/src/commands/version.rs | 20 ++++++++----- crates/nu_plugin_textview/Cargo.toml | 2 +- 6 files changed, 28 insertions(+), 52 deletions(-) delete mode 100644 crates/nu-cli/build.rs diff --git a/Cargo.lock b/Cargo.lock index c17a2735b6..b23e8a8d62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2095,6 +2095,15 @@ dependencies = [ "log", ] +[[package]] +name = "last-git-commit" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f2e5243385b2ea0443d79fd6f5ea97b0509f2571e8f39e99d1ead2bcc1c89c0" +dependencies = [ + "git2", +] + [[package]] name = "lazy_static" version = "0.2.11" @@ -2627,7 +2636,7 @@ dependencies = [ [[package]] name = "nu-cli" -version = "0.18.0" +version = "0.18.1" dependencies = [ "ansi_term 0.12.1", "app_dirs2", @@ -2664,6 +2673,7 @@ dependencies = [ "ichwh", "indexmap", "itertools", + "last-git-commit", "log", "meval", "natural", diff --git a/Cargo.toml b/Cargo.toml index 09676d349f..57e733dc41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ members = ["crates/*/"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -nu-cli = {version = "0.18.0", path = "./crates/nu-cli"} +nu-cli = {version = "0.18.1", path = "./crates/nu-cli"} nu-errors = {version = "0.18.0", path = "./crates/nu-errors"} nu-parser = {version = "0.18.0", path = "./crates/nu-parser"} nu-plugin = {version = "0.18.0", path = "./crates/nu-plugin"} diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index db5f6e776f..e509082fe9 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -4,7 +4,7 @@ description = "CLI for nushell" edition = "2018" license = "MIT" name = "nu-cli" -version = "0.18.0" +version = "0.18.1" [lib] doctest = false @@ -52,6 +52,7 @@ ical = "0.6.*" ichwh = {version = "0.3.4", optional = true} indexmap = {version = "1.4.0", features = ["serde-1"]} itertools = "0.9.0" +last-git-commit = "0.2.0" log = "0.4.8" meval = "0.2" natural = "0.5.0" diff --git a/crates/nu-cli/build.rs b/crates/nu-cli/build.rs deleted file mode 100644 index 7b255bec32..0000000000 --- a/crates/nu-cli/build.rs +++ /dev/null @@ -1,41 +0,0 @@ -use std::path::Path; -use std::{env, fs, io}; - -use git2::Repository; - -#[derive(Debug)] -enum Error { - IoError(io::Error), - GitError(git2::Error), -} - -impl From for Error { - fn from(git_error: git2::Error) -> Self { - Self::GitError(git_error) - } -} - -impl From for Error { - fn from(io_error: io::Error) -> Self { - Self::IoError(io_error) - } -} - -fn main() -> Result<(), Error> { - let out_dir = env::var_os("OUT_DIR").expect( - "\ - OUT_DIR environment variable not found. \ - OUT_DIR is guaranteed to to exist in a build script by cargo - see \ - https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts\ - "); - let latest_commit_hash = Repository::discover(env::current_dir()?)? - .head()? - .peel_to_commit()? - .id() - .to_string(); - - let commit_hash_path = Path::new(&out_dir).join("git_commit_hash"); - fs::write(commit_hash_path, latest_commit_hash)?; - - Ok(()) -} diff --git a/crates/nu-cli/src/commands/version.rs b/crates/nu-cli/src/commands/version.rs index 7d013d2134..cfd9fe9541 100644 --- a/crates/nu-cli/src/commands/version.rs +++ b/crates/nu-cli/src/commands/version.rs @@ -1,11 +1,10 @@ use crate::commands::WholeStreamCommand; use crate::prelude::*; use indexmap::IndexMap; +use last_git_commit::LastGitCommit; use nu_errors::ShellError; use nu_protocol::{Dictionary, Signature, UntaggedValue}; -const GIT_COMMIT_HASH: &str = include_str!(concat!(env!("OUT_DIR"), "/git_commit_hash")); - pub struct Version; #[async_trait] @@ -42,16 +41,23 @@ impl WholeStreamCommand for Version { pub fn version(args: CommandArgs, _registry: &CommandRegistry) -> Result { let tag = args.call_info.args.span; - let mut indexmap = IndexMap::with_capacity(2); + let mut indexmap = IndexMap::with_capacity(3); indexmap.insert( "version".to_string(), UntaggedValue::string(clap::crate_version!()).into_value(&tag), ); - indexmap.insert( - "commit_hash".to_string(), - UntaggedValue::string(GIT_COMMIT_HASH).into_value(&tag), - ); + + if let Ok(lgc) = LastGitCommit::new().build() { + indexmap.insert( + "short_commit_hash".to_string(), + UntaggedValue::string(lgc.id().short()).into_value(&tag), + ); + indexmap.insert( + "long_commit_hash".to_string(), + UntaggedValue::string(lgc.id().long()).into_value(&tag), + ); + } let value = UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag); Ok(OutputStream::one(value)) diff --git a/crates/nu_plugin_textview/Cargo.toml b/crates/nu_plugin_textview/Cargo.toml index 85cad9de9f..921d93d2dd 100644 --- a/crates/nu_plugin_textview/Cargo.toml +++ b/crates/nu_plugin_textview/Cargo.toml @@ -10,7 +10,7 @@ version = "0.18.0" doctest = false [dependencies] -nu-cli = {path = "../nu-cli", version = "0.18.0"} +nu-cli = {path = "../nu-cli", version = "0.18.1"} nu-errors = {path = "../nu-errors", version = "0.18.0"} nu-plugin = {path = "../nu-plugin", version = "0.18.0"} nu-protocol = {path = "../nu-protocol", version = "0.18.0"}