diff --git a/Cargo.toml b/Cargo.toml index 8617be54..4f9916a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT/Apache-2.0" name = "vergen" readme = "README.md" repository = "https://github.com/rustyhorde/vergen" -version = "3.0.1" +version = "3.0.2" [dependencies] bitflags = "1" diff --git a/README.md b/README.md index 32b58868..96585e0b 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,17 @@ [![Crates.io](https://img.shields.io/crates/l/vergen.svg)](https://crates.io/crates/vergen) [![Crates.io](https://img.shields.io/crates/d/vergen.svg)](https://crates.io/crates/vergen) -## Version 3.x.x -[![Build -Status](https://travis-ci.org/rustyhorde/vergen.svg?branch=master)](https://travis-ci.org/rustyhorde/vergen) +## Build Status +| | | +---------------|-----------------------------------------------------------------------------------| +| Travis | [![Build Status](https://travis-ci.org/rustyhorde/vergen.svg?branch=master)](https://travis-ci.org/rustyhorde/vergen)| +| GitLab CI/CD | [![pipeline status](https://gitlab.com/rustyhorde/vergen/badges/master/pipeline.svg)](https://gitlab.com/rustyhorde/vergen/commits/master)| +| Appveyor | [![Build status](https://ci.appveyor.com/api/projects/status/rcdjlx0sxvk3wnww/branch/master?svg=true)](https://ci.appveyor.com/project/CraZySacX/vergen/branch/master)| + +## Code Coverage +[![codecov](https://codecov.io/gh/rustyhorde/vergen/branch/master/graph/badge.svg)](https://codecov.io/gh/rustyhorde/vergen) +## Version 3.x.x Introduces `generate_cargo_keys()` and support for rebuild when `.git/HEAD` changes. Internally converted to use `failure` so `Result` is no longer exported and changed to the Rust 2018 edition. @@ -16,7 +23,7 @@ edition. hits stable (12/06/18)** ## Version 2.1.x -[![Build Status](https://travis-ci.org/rustyhorde/vergen.svg?branch=v2.1.0)](https://travis-ci.org/rustyhorde/vergen) +[![Build Status](https://travis-ci.org/rustyhorde/vergen.svg?branch=v2.1.1)](https://travis-ci.org/rustyhorde/vergen) Backport of the 3.x.x changes to work on stable until Rust 2018 hits stable. diff --git a/src/output/envvar.rs b/src/output/envvar.rs index c754ac93..acec2830 100644 --- a/src/output/envvar.rs +++ b/src/output/envvar.rs @@ -44,31 +44,57 @@ pub fn generate_cargo_keys(flags: ConstantsFlags) -> Fallible<()> { let git_dir_or_file = PathBuf::from(".git"); let metadata = fs::metadata(&git_dir_or_file)?; - let mut f = if metadata.is_dir() { + if metadata.is_dir() { + // Echo the HEAD path let git_head_path = git_dir_or_file.join("HEAD"); println!("cargo:rerun-if-changed={}", git_head_path.display()); - File::open(&git_head_path)? + + // Determine where HEAD points and echo that path also. + let mut f = File::open(&git_head_path)?; + let mut git_head_contents = String::new(); + let _ = f.read_to_string(&mut git_head_contents)?; + let ref_vec: Vec<&str> = git_head_contents.split(": ").collect(); + + if ref_vec.len() == 2 { + let current_head_file = ref_vec[1]; + let git_refs_path = PathBuf::from(".git").join(current_head_file); + println!("cargo:rerun-if-changed={}", git_refs_path.display()); + } else { + return Err(failure::err_msg("Invalid HEAD file")); + } } else if metadata.is_file() { + // We are in a worktree, so find out where the actual worktrees//HEAD file is. let mut git_file = File::open(&git_dir_or_file)?; let mut git_contents = String::new(); let _ = git_file.read_to_string(&mut git_contents)?; let dir_vec: Vec<&str> = git_contents.split(": ").collect(); - let git_head_path = PathBuf::from(dir_vec[1].trim()).join("HEAD"); + let git_path = dir_vec[1].trim(); + + // Echo the HEAD psth + let git_head_path = PathBuf::from(git_path).join("HEAD"); println!("cargo:rerun-if-changed={}", git_head_path.display()); - File::open(&git_head_path)? + + // Find out what the full path to the .git dir is. + let mut actual_git_dir = PathBuf::from(git_path); + actual_git_dir.pop(); + actual_git_dir.pop(); + + // Determine where HEAD points and echo that path also. + let mut f = File::open(&git_head_path)?; + let mut git_head_contents = String::new(); + let _ = f.read_to_string(&mut git_head_contents)?; + let ref_vec: Vec<&str> = git_head_contents.split(": ").collect(); + + if ref_vec.len() == 2 { + let current_head_file = ref_vec[1]; + let git_refs_path = actual_git_dir.join(current_head_file); + println!("cargo:rerun-if-changed={}", git_refs_path.display()); + } else { + return Err(failure::err_msg("Invalid HEAD file")); + } } else { return Err(failure::err_msg("Invalid .git format")); }; - let mut git_head_contents = String::new(); - let _ = f.read_to_string(&mut git_head_contents)?; - let ref_vec: Vec<&str> = git_head_contents.split(": ").collect(); - - if ref_vec.len() == 2 { - let current_head_file = ref_vec[1]; - let git_refs_path = PathBuf::from(".git").join(current_head_file); - println!("cargo:rerun-if-changed={}", git_refs_path.display()); - } - Ok(()) }