Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Improve Git tag lookup for

+38 -13
+38 -13
compiler-cli/src/publish.rs
··· 18 18 use hexpm::version::{Range, Version}; 19 19 use itertools::Itertools; 20 20 use sha2::Digest; 21 - use std::{collections::HashMap, io::Write, path::PathBuf}; 21 + use std::{ 22 + collections::HashMap, 23 + io::Write, 24 + process::{Command, Stdio}, 25 + }; 22 26 23 27 use crate::{build, cli, docs, fs, http::HttpClient, new::default_readme}; 24 28 ··· 116 120 117 121 // Prompt the user to make a git tag if they have not. 118 122 let has_repo = config.repository.is_some(); 119 - let git = PathBuf::from(".git"); 120 - let tag_name = config.tag_for_version(&config.version); 121 - let git_tag = git.join("refs").join("tags").join(&tag_name); 122 - if has_repo && git.exists() && !git_tag.exists() { 123 - println!( 124 - " 125 - Please push a git tag for this release so source code links in the 126 - HTML documentation will work: 123 + let is_repository = Command::new("git") 124 + .arg("rev-parse") 125 + .arg("--is-inside-work-tree") 126 + // We don't need Git's output, since it will exit with code 0 if we are 127 + // inside work tree 128 + .stdout(Stdio::null()) 129 + .stderr(Stdio::null()) 130 + .status() 131 + .map(|s| s.success()) 132 + .unwrap_or(false); 133 + 134 + if has_repo && is_repository { 135 + let tag_name = config.tag_for_version(&config.version); 136 + let tag_exists = Command::new("git") 137 + .args(["rev-parse", "--verify", &tag_name]) 138 + // We don't need Git's output, since it will exit with code 0 if the 139 + // tag exists 140 + .stdout(Stdio::null()) 141 + .stderr(Stdio::null()) 142 + .status() 143 + .map(|s| s.success()) 144 + .unwrap_or(false); 145 + 146 + if !tag_exists { 147 + println!( 148 + " 149 + Please push a git tag for this release so source code links in the 150 + HTML documentation will work: 127 151 128 - git tag {tag_name} 129 - git push origin {tag_name} 130 - " 131 - ) 152 + git tag {tag_name} 153 + git push origin {tag_name} 154 + " 155 + ) 156 + } 132 157 } 133 158 Ok(()) 134 159 }