summaryrefslogtreecommitdiffstats
path: root/src/modules/git_commit.rs
diff options
context:
space:
mode:
authorLoong Wang <wangl.cc@outlook.com>2022-11-07 05:43:50 +0800
committerGitHub <noreply@github.com>2022-11-06 22:43:50 +0100
commitfd165b96cc9587f81ab68b580d371b71f4e0ff35 (patch)
tree9f16cdc1c3bf5601ec06fca8fa47296710b465ba /src/modules/git_commit.rs
parent1a3d51fe76c5a62d53533f5d14ceb4425d5a33a5 (diff)
fix(git): check `tag_disabled` option (#4527)
* fix(git): check `tag_disabled` option * Check in `map` and test fixes
Diffstat (limited to 'src/modules/git_commit.rs')
-rw-r--r--src/modules/git_commit.rs45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/modules/git_commit.rs b/src/modules/git_commit.rs
index d2fdd68ad..e5ca47448 100644
--- a/src/modules/git_commit.rs
+++ b/src/modules/git_commit.rs
@@ -29,7 +29,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
})
.map(|variable| match variable {
"hash" => Some(Ok(git_hash(context.get_repo().ok()?, &config)?)),
- "tag" => Some(Ok(format!(
+ "tag" if !config.tag_disabled => Some(Ok(format!(
"{}{}",
config.tag_symbol,
git_tag(context.get_repo().ok()?, &config)?
@@ -202,9 +202,50 @@ mod tests {
}
#[test]
+ fn test_render_commit_hash_with_tag_disabled() -> io::Result<()> {
+ let repo_dir = fixture_repo(FixtureProvider::Git)?;
+
+ create_command("git")?
+ .args(&["tag", "v1", "-m", "Testing tags"])
+ .current_dir(&repo_dir.path())
+ .output()?;
+
+ let mut git_commit = create_command("git")?
+ .args(&["rev-parse", "HEAD"])
+ .current_dir(&repo_dir.path())
+ .output()?
+ .stdout;
+ git_commit.truncate(7);
+ let commit_output = str::from_utf8(&git_commit).unwrap().trim();
+
+ let actual = ModuleRenderer::new("git_commit")
+ .config(toml::toml! {
+ [git_commit]
+ only_detached = false
+ })
+ .path(&repo_dir.path())
+ .collect();
+
+ let expected = Some(format!(
+ "{} ",
+ Color::Green
+ .bold()
+ .paint(format!("({})", commit_output.trim()))
+ ));
+
+ assert_eq!(expected, actual);
+ Ok(())
+ }
+
+ #[test]
fn test_render_commit_hash_with_tag_enabled() -> io::Result<()> {
let repo_dir = fixture_repo(FixtureProvider::Git)?;
+ create_command("git")?
+ .args(&["tag", "v1", "-m", "Testing tags"])
+ .current_dir(&repo_dir.path())
+ .output()?;
+
let mut git_commit = create_command("git")?
.args(["rev-parse", "HEAD"])
.current_dir(repo_dir.path())
@@ -227,7 +268,7 @@ mod tests {
[git_commit]
only_detached = false
tag_disabled = false
- tag_symbol = ""
+ tag_symbol = " "
})
.path(repo_dir.path())
.collect();