Skip to content

Commit aaeba3c

Browse files
committed
Init registry repo if it doesn't exist.
1 parent 07b59d9 commit aaeba3c

File tree

6 files changed

+29
-42
lines changed

6 files changed

+29
-42
lines changed

Cargo.lock

+9-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ git2 = "0.10.1"
6969
hex = "0.3.2"
7070
url = "2.1.0"
7171
toml = "0.5.1"
72-
itertools = "0.8.0"
7372

7473
[dependencies.semver]
7574
features = ["serde"]

src/bin/upgrade/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use cargo_edit::{
2020
LocalManifest,
2121
};
2222
use failure::Fail;
23-
use itertools::Itertools;
24-
use std::collections::HashMap;
23+
use std::collections::{HashMap, HashSet};
2524
use std::io::Write;
2625
use std::path::{Path, PathBuf};
2726
use std::process;
@@ -238,6 +237,7 @@ impl Manifests {
238237
}
239238

240239
/// The set of dependencies to be upgraded, alongside the registries returned from cargo metadata, and
240+
/// the desired versions, if specified by the user.
241241
struct DesiredUpgrades(HashMap<Dependency, (Option<String>, Option<String>)>);
242242

243243
/// The complete specification of the upgrades that will be performed. Map of the dependency names
@@ -310,7 +310,7 @@ fn process(args: Args) -> Result<()> {
310310
.0
311311
.values()
312312
.filter_map(|(registry, _)| registry.as_ref())
313-
.unique()
313+
.collect::<HashSet<_>>()
314314
{
315315
update_registry_index(&Url::parse(registry_url).map_err(|_| {
316316
ErrorKind::CargoEditLib(::cargo_edit::ErrorKind::InvalidCargoConfig)

src/dependency.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ impl Dependency {
5454
// store in the cargo toml files. This would cause a warning upon compilation
5555
// ("version requirement […] includes semver metadata which will be ignored")
5656
let version = version.split('+').next().unwrap();
57-
let old_source = self.source;
58-
let (old_path, old_registry) = match old_source {
57+
let (old_path, old_registry) = match self.source {
5958
DependencySource::Version { path, registry, .. } => (path, registry),
6059
_ => (None, None),
6160
};
@@ -75,8 +74,7 @@ impl Dependency {
7574

7675
/// Set dependency to a given path
7776
pub fn set_path(mut self, path: &str) -> Dependency {
78-
let old_source = self.source;
79-
let old_version = match old_source {
77+
let old_version = match self.source {
8078
DependencySource::Version { version, .. } => version,
8179
_ => None,
8280
};
@@ -115,8 +113,7 @@ impl Dependency {
115113

116114
/// Set the value of registry for the dependency
117115
pub fn set_registry(mut self, registry: &str) -> Dependency {
118-
let old_source = self.source;
119-
let old_version = match old_source {
116+
let old_version = match self.source {
120117
DependencySource::Version { version, .. } => version,
121118
_ => None,
122119
};

src/fetch.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,26 @@ fn read_latest_version(
9494
pub fn update_registry_index(registry: &Url) -> Result<()> {
9595
let registry_path = registry_path_from_url(registry)?;
9696

97-
let repo = git2::Repository::open(&registry_path)?;
9897
let colorchoice = if atty::is(atty::Stream::Stdout) {
9998
ColorChoice::Auto
10099
} else {
101100
ColorChoice::Never
102101
};
103102
let mut output = StandardStream::stdout(colorchoice);
103+
104+
if !registry_path.as_path().exists() {
105+
output.set_color(ColorSpec::new().set_fg(Some(Color::Green)).set_bold(true))?;
106+
write!(output, "{:>12}", "Initializing")?;
107+
output.reset()?;
108+
writeln!(output, " '{}' index", registry)?;
109+
110+
let mut opts = git2::RepositoryInitOptions::new();
111+
opts.bare(true);
112+
git2::Repository::init_opts(&registry_path, &opts)?;
113+
return Ok(());
114+
}
115+
116+
let repo = git2::Repository::open(&registry_path)?;
104117
output.set_color(ColorSpec::new().set_fg(Some(Color::Green)).set_bold(true))?;
105118
write!(output, "{:>12}", "Updating")?;
106119
output.reset()?;

tests/utils.rs

-12
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@ pub fn setup_alt_registry_config(path: &std::path::Path) {
2727
path.join(".cargo").join("config"),
2828
)
2929
.unwrap_or_else(|err| panic!("could not copy test cargo config: {}", err));
30-
// Workaround for https://github.com/killercup/cargo-edit/issues/339
31-
let call = process::Command::new("cargo")
32-
.args(&["search", "--registry=alternative", "failure"])
33-
.current_dir(path)
34-
.output()
35-
.unwrap();
36-
if !call.status.success() {
37-
println!("Status code: {:?}", call.status);
38-
println!("STDOUT: {}", String::from_utf8_lossy(&call.stdout));
39-
println!("STDERR: {}", String::from_utf8_lossy(&call.stderr));
40-
panic!("Failed to initialize alternative registry");
41-
}
4230
}
4331

4432
/// Execute local cargo command, includes `--manifest-path`, expect command failed

0 commit comments

Comments
 (0)