Skip to content

Commit 372601e

Browse files
committed
Auto merge of #4173 - Turbo87:relative-index-file, r=JohnTitor
TestApp: Simplify `crates_from_index_head()` method We can calculate the `path` automatically from the `crate_name`. There is no need for us to manually specify it in the tests.
2 parents 435ccbe + d1f2854 commit 372601e

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

src/git.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ impl Repository {
177177
pub fn index_file(&self, name: &str) -> PathBuf {
178178
self.checkout_path
179179
.path()
180-
.join(self.relative_index_file(name))
180+
.join(Self::relative_index_file(name))
181181
}
182182

183-
pub fn relative_index_file(&self, name: &str) -> PathBuf {
183+
pub fn relative_index_file(name: &str) -> PathBuf {
184184
let name = name.to_lowercase();
185185
match name.len() {
186186
1 => Path::new("1").join(&name),
@@ -244,7 +244,8 @@ impl Repository {
244244
pub fn commit_and_push(&self, message: &str, modified_file: &Path) -> Result<(), PerformError> {
245245
println!("Committing and pushing \"{}\"", message);
246246

247-
self.perform_commit_and_push(message, modified_file)
247+
let relative_path = modified_file.strip_prefix(self.checkout_path.path())?;
248+
self.perform_commit_and_push(message, relative_path)
248249
.map(|_| println!("Commit and push finished for \"{}\"", message))
249250
.map_err(|err| {
250251
eprintln!("Commit and push for \"{}\" errored: {}", message, err);

src/tests/krate/publish.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn new_with_renamed_dependency() {
161161
token.enqueue_publish(crate_to_publish).good();
162162
app.run_pending_background_jobs();
163163

164-
let crates = app.crates_from_index_head("ne/w-/new-krate");
164+
let crates = app.crates_from_index_head("new-krate");
165165
assert_eq!(crates.len(), 1);
166166
assert_eq!(crates[0].name, "new-krate");
167167
assert_eq!(crates[0].vers, "1.0.0");
@@ -187,7 +187,7 @@ fn new_with_underscore_renamed_dependency() {
187187
token.enqueue_publish(crate_to_publish).good();
188188
app.run_pending_background_jobs();
189189

190-
let crates = app.crates_from_index_head("ne/w-/new-krate");
190+
let crates = app.crates_from_index_head("new-krate");
191191
assert_eq!(crates.len(), 1);
192192
assert_eq!(crates[0].name, "new-krate");
193193
assert_eq!(crates[0].vers, "1.0.0");
@@ -528,7 +528,7 @@ fn new_krate_git_upload() {
528528
token.enqueue_publish(crate_to_publish).good();
529529
app.run_pending_background_jobs();
530530

531-
let crates = app.crates_from_index_head("3/f/fgt");
531+
let crates = app.crates_from_index_head("fgt");
532532
assert_eq!(crates.len(), 1);
533533
assert_eq!(crates[0].name, "fgt");
534534
assert_eq!(crates[0].vers, "1.0.0");
@@ -549,7 +549,7 @@ fn new_krate_git_upload_appends() {
549549
token.enqueue_publish(crate_to_publish).good();
550550
app.run_pending_background_jobs();
551551

552-
let crates = app.crates_from_index_head("3/f/fpp");
552+
let crates = app.crates_from_index_head("fpp");
553553
assert!(crates.len() == 2);
554554
assert_eq!(crates[0].name, "FPP");
555555
assert_eq!(crates[0].vers, "0.0.1");

src/tests/krate/yanking.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn yank_works_as_intended() {
4949
token.enqueue_publish(crate_to_publish).good();
5050
app.run_pending_background_jobs();
5151

52-
let crates = app.crates_from_index_head("3/f/fyk");
52+
let crates = app.crates_from_index_head("fyk");
5353
assert_eq!(crates.len(), 1);
5454
assert_some_eq!(crates[0].yanked, false);
5555

@@ -60,7 +60,7 @@ fn yank_works_as_intended() {
6060
// yank it
6161
token.yank("fyk", "1.0.0").good();
6262

63-
let crates = app.crates_from_index_head("3/f/fyk");
63+
let crates = app.crates_from_index_head("fyk");
6464
assert_eq!(crates.len(), 1);
6565
assert_some_eq!(crates[0].yanked, true);
6666

@@ -70,7 +70,7 @@ fn yank_works_as_intended() {
7070
// un-yank it
7171
token.unyank("fyk", "1.0.0").good();
7272

73-
let crates = app.crates_from_index_head("3/f/fyk");
73+
let crates = app.crates_from_index_head("fyk");
7474
assert_eq!(crates.len(), 1);
7575
assert_some_eq!(crates[0].yanked, false);
7676

@@ -80,7 +80,7 @@ fn yank_works_as_intended() {
8080
// yank it
8181
cookie.yank("fyk", "1.0.0").good();
8282

83-
let crates = app.crates_from_index_head("3/f/fyk");
83+
let crates = app.crates_from_index_head("fyk");
8484
assert_eq!(crates.len(), 1);
8585
assert_some_eq!(crates[0].yanked, true);
8686

@@ -90,7 +90,7 @@ fn yank_works_as_intended() {
9090
// un-yank it
9191
cookie.unyank("fyk", "1.0.0").good();
9292

93-
let crates = app.crates_from_index_head("3/f/fyk");
93+
let crates = app.crates_from_index_head("fyk");
9494
assert_eq!(crates.len(), 1);
9595
assert_some_eq!(crates[0].yanked, false);
9696

src/tests/util/test_app.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use cargo_registry::{
1010
};
1111
use std::{rc::Rc, sync::Arc, time::Duration};
1212

13-
use cargo_registry::git::Repository as WorkerRepository;
13+
use cargo_registry::git::{Repository as WorkerRepository, Repository};
1414
use diesel::PgConnection;
1515
use git2::Repository as UpstreamRepository;
1616
use reqwest::{blocking::Client, Proxy};
@@ -134,12 +134,12 @@ impl TestApp {
134134
}
135135

136136
/// Obtain a list of crates from the index HEAD
137-
pub fn crates_from_index_head(&self, path: &str) -> Vec<cargo_registry::git::Crate> {
138-
let path = std::path::Path::new(path);
137+
pub fn crates_from_index_head(&self, crate_name: &str) -> Vec<cargo_registry::git::Crate> {
138+
let path = Repository::relative_index_file(crate_name);
139139
let index = self.upstream_repository();
140140
let tree = index.head().unwrap().peel_to_tree().unwrap();
141141
let blob = tree
142-
.get_path(path)
142+
.get_path(&path)
143143
.unwrap()
144144
.to_object(index)
145145
.unwrap()

src/worker/git.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn add_crate(env: &Environment, krate: Crate) -> Result<(), PerformError> {
2121

2222
let message: String = format!("Updating crate `{}#{}`", krate.name, krate.vers);
2323

24-
repo.commit_and_push(&message, &repo.relative_index_file(&krate.name))
24+
repo.commit_and_push(&message, &dst)
2525
}
2626

2727
/// Yanks or unyanks a crate version. This requires finding the index
@@ -61,7 +61,7 @@ pub fn yank(
6161
version.num
6262
);
6363

64-
repo.commit_and_push(&message, &repo.relative_index_file(&krate))?;
64+
repo.commit_and_push(&message, &dst)?;
6565

6666
Ok(())
6767
}

0 commit comments

Comments
 (0)