Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
};
use semver::VersionReq;
use std::{
collections::{BTreeMap, HashMap},
collections::{btree_map, BTreeMap, HashMap},
env, fmt,
};
use toml::Value;
Expand Down Expand Up @@ -275,7 +275,22 @@ impl ConfigFile {

fn fill_from(&mut self, other: ConfigFile) {
for (tool_name, tool_source) in other.tools {
self.tools.entry(tool_name).or_insert(tool_source);
match self.tools.entry(tool_name) {
btree_map::Entry::Occupied(entry) => {
if *entry.get() != tool_source {
log::warn!(
"tool `{}` is defined in multiple configuration files; \
using `{}` (ignoring `{}`)",
entry.key(),
entry.get(),
tool_source
);
}
}
btree_map::Entry::Vacant(entry) => {
entry.insert(tool_source);
}
}
}

for (host_name, host_source) in other.hosts {
Expand Down Expand Up @@ -381,6 +396,28 @@ mod test {
VersionReq::parse(string).unwrap()
}

#[test]
fn duplicate_tool_definitions_keep_the_first_one() {
let mut first = BTreeMap::new();
first.insert(
"tool_alias".to_owned(),
new_github("user/repo", version("0.1.0")),
);
let mut second = BTreeMap::new();
second.insert(
"tool_alias".to_owned(),
new_github("user/other-repo", version("2.0.0")),
);

let mut config = new_config(first.clone(), HashMap::new());
config.fill_from(ConfigFile {
tools: second,
hosts: HashMap::new(),
});

assert_eq!(config.tools, first);
}

fn new_host(source: Url, protocol: Protocol) -> Host {
Host { source, protocol }
}
Expand Down