···1818use hexpm::version::{Range, Version};
1919use itertools::Itertools;
2020use sha2::Digest;
2121-use std::{collections::HashMap, io::Write, path::PathBuf};
2121+use std::{
2222+ collections::HashMap,
2323+ io::Write,
2424+ process::{Command, Stdio},
2525+};
22262327use crate::{build, cli, docs, fs, http::HttpClient, new::default_readme};
2428···116120117121 // Prompt the user to make a git tag if they have not.
118122 let has_repo = config.repository.is_some();
119119- let git = PathBuf::from(".git");
120120- let tag_name = config.tag_for_version(&config.version);
121121- let git_tag = git.join("refs").join("tags").join(&tag_name);
122122- if has_repo && git.exists() && !git_tag.exists() {
123123- println!(
124124- "
125125-Please push a git tag for this release so source code links in the
126126-HTML documentation will work:
123123+ let is_repository = Command::new("git")
124124+ .arg("rev-parse")
125125+ .arg("--is-inside-work-tree")
126126+ // We don't need Git's output, since it will exit with code 0 if we are
127127+ // inside work tree
128128+ .stdout(Stdio::null())
129129+ .stderr(Stdio::null())
130130+ .status()
131131+ .map(|s| s.success())
132132+ .unwrap_or(false);
133133+134134+ if has_repo && is_repository {
135135+ let tag_name = config.tag_for_version(&config.version);
136136+ let tag_exists = Command::new("git")
137137+ .args(["rev-parse", "--verify", &tag_name])
138138+ // We don't need Git's output, since it will exit with code 0 if the
139139+ // tag exists
140140+ .stdout(Stdio::null())
141141+ .stderr(Stdio::null())
142142+ .status()
143143+ .map(|s| s.success())
144144+ .unwrap_or(false);
145145+146146+ if !tag_exists {
147147+ println!(
148148+ "
149149+ Please push a git tag for this release so source code links in the
150150+ HTML documentation will work:
127151128128- git tag {tag_name}
129129- git push origin {tag_name}
130130-"
131131- )
152152+ git tag {tag_name}
153153+ git push origin {tag_name}
154154+ "
155155+ )
156156+ }
132157 }
133158 Ok(())
134159}