Skip to content

Commit

Permalink
fix(check): check should not fail if read from stdin
Browse files Browse the repository at this point in the history
Refs: #130
  • Loading branch information
hdevalke committed Jul 21, 2023
1 parent 951253f commit 69ace8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/conventional/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ fn host_info_from_url(url: Url) -> Result<HostOwnerRepo, Error> {
Ok((host, owner, repository))
}

pub(crate) fn make_cl_config(git: &GitHelper, path: impl AsRef<Path>) -> Config {
pub(crate) fn make_cl_config(git: Option<GitHelper>, path: impl AsRef<Path>) -> Config {
let mut config: Config = (std::fs::read(path))
.ok()
.and_then(|versionrc| (serde_yaml::from_reader(versionrc.as_slice())).ok())
Expand All @@ -272,10 +272,12 @@ pub(crate) fn make_cl_config(git: &GitHelper, path: impl AsRef<Path>) -> Config
..
} = config
{
if let Ok((host, owner, repository)) = host_info(git) {
config.host = host;
config.owner = owner;
config.repository = repository;
if let Some(ref git) = git {
if let Ok((host, owner, repository)) = host_info(git) {
config.host = host;
config.owner = owner;
config.repository = repository;
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ fn main() -> anyhow::Result<()> {
}
let git = GitHelper::new("v").map_err(|e|
if e.message().contains("config value 'safe.directory' was not found") {
anyhow::Error::new(e).context("Could not open the git repository.\nIf run from docker set the right user id and group id.\nE.g. `docker run -u \"$(id -u):$(id -g)\" -v \"$PWD:/tmp\" --workdir /tmp --rm convco/convco`")
eprintln!("Could not open the git repository.\nIf run from docker set the right user id and group id.\nE.g. `docker run -u \"$(id -u):$(id -g)\" -v \"$PWD:/tmp\" --workdir /tmp --rm convco/convco`")
} else {
anyhow::Error::new(e)
eprintln!("{e}")
}
)?;
let config = make_cl_config(&git, opt.config.unwrap_or_else(|| ".versionrc".into()));
).ok();
let config = make_cl_config(git, opt.config.unwrap_or_else(|| ".versionrc".into()));
let res = match opt.cmd {
cli::Command::Config(cmd) => cmd.exec(config),
cli::Command::Check(cmd) => cmd.exec(config),
Expand Down

0 comments on commit 69ace8d

Please sign in to comment.