Skip to content

Commit

Permalink
add match pattern for git-describe
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamg795 committed Mar 24, 2023
1 parent b323d3b commit d8f1015
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 10 additions & 4 deletions vergen/src/feature/git/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ pub(crate) struct Config {
pub(crate) git_commit_message: bool,
// git log -1 --pretty=format:'%cI'
pub(crate) git_commit_timestamp: bool,
// git describe --always (optionally --tags, --dirty)
// git describe --always (optionally --tags, --dirty, --match)
pub(crate) git_describe: bool,
git_describe_dirty: bool,
git_describe_tags: bool,
git_describe_match_pattern: Option<&'static str>,
// git rev-parse HEAD (optionally with --short)
pub(crate) git_sha: bool,
git_sha_short: bool,
Expand Down Expand Up @@ -262,7 +263,7 @@ impl EmitBuilder {
.git_commit_date()
.git_commit_message()
.git_commit_timestamp()
.git_describe(false, false)
.git_describe(false, false, None)
.git_sha(false)
}

Expand Down Expand Up @@ -399,10 +400,11 @@ impl EmitBuilder {
/// Optionally, add the `dirty` or `tags` flag to describe.
/// See [`git describe`](https://git-scm.com/docs/git-describe#_options) for more details
///
pub fn git_describe(&mut self, dirty: bool, tags: bool) -> &mut Self {
pub fn git_describe(&mut self, dirty: bool, tags: bool, match_pattern: Option<&'static str>) -> &mut Self {
self.git_config.git_describe = true;
self.git_config.git_describe_dirty = dirty;
self.git_config.git_describe_tags = tags;
self.git_config.git_describe_match_pattern = match_pattern;
self
}

Expand Down Expand Up @@ -574,6 +576,10 @@ impl EmitBuilder {
if self.git_config.git_describe_tags {
describe_cmd.push_str(" --tags");
}
if let Some(pattern) = self.git_config.git_describe_match_pattern {
describe_cmd.push_str(" --match ");
describe_cmd.push_str(pattern);
}
add_git_cmd_entry(&describe_cmd, VergenKey::GitDescribe, map)?;
}
}
Expand Down Expand Up @@ -890,7 +896,7 @@ mod test {
fn git_all_dirty_tags_short() -> Result<()> {
let config = EmitBuilder::builder()
.all_git()
.git_describe(true, true)
.git_describe(true, true, None)
.git_sha(true)
.test_emit()?;
assert_eq!(9, config.cargo_rustc_env_map.len());
Expand Down
6 changes: 3 additions & 3 deletions vergen/tests/git_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH
let mut stdout_buf = vec![];
let failed = EmitBuilder::builder()
.all_git()
.git_describe(true, true)
.git_describe(true, true, None)
.git_sha(true)
.emit_to_at(&mut stdout_buf, Some(clone_path()))?;
assert!(!failed);
Expand All @@ -343,7 +343,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH
let mut stdout_buf = vec![];
let failed = EmitBuilder::builder()
.all_git()
.git_describe(true, false)
.git_describe(true, false, None)
.emit_to_at(&mut stdout_buf, Some(clone_path()))?;
assert!(!failed);
let output = String::from_utf8_lossy(&stdout_buf);
Expand All @@ -358,7 +358,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH
clone_test_repo();
assert!(EmitBuilder::builder()
.all_git()
.git_describe(true, true)
.git_describe(true, true, None)
.git_sha(true)
.emit_at(clone_path())
.is_ok());
Expand Down

0 comments on commit d8f1015

Please sign in to comment.