Skip to content

Commit 00e6875

Browse files
committed
Use gitoxide for fetching in test
This proves at least to some extend that it works, nice!
1 parent 759ff30 commit 00e6875

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/index/diff/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Index {
139139
.and_then(|r| r.try_id().map(|id| id.detach()))
140140
.unwrap_or_else(|| git::hash::ObjectId::empty_tree(repo.object_hash()));
141141
let to = {
142-
let remote = self
142+
let mut remote = self
143143
.remote_name
144144
.and_then(|name| {
145145
self.repo.find_remote(name).ok().or_else(|| {
@@ -171,20 +171,21 @@ impl Index {
171171
.map(|r| r.map_err(Error::from))
172172
})
173173
.unwrap_or_else(|| {
174-
let spec = format!(
175-
"+refs/heads/{branch}:refs/remotes/{remote}/{branch}",
176-
remote = self.remote_name.unwrap_or("origin"),
177-
branch = self.branch_name,
178-
);
179174
self.repo
180175
.remote_at("https://github.com/rust-lang/crates.io-index")
181176
.map_err(Into::into)
182-
.map(|r| {
183-
r.with_refspec(spec.as_str(), git::remote::Direction::Fetch)
184-
.expect("valid refspec")
185-
})
186177
})
187178
})?;
179+
if remote.refspecs(git::remote::Direction::Fetch).is_empty() {
180+
let spec = format!(
181+
"+refs/heads/{branch}:refs/remotes/{remote}/{branch}",
182+
remote = self.remote_name.unwrap_or("origin"),
183+
branch = self.branch_name,
184+
);
185+
remote
186+
.replace_refspecs(Some(spec.as_str()), git::remote::Direction::Fetch)
187+
.expect("valid statically known refspec");
188+
}
188189
let res: git::remote::fetch::Outcome<'_> = remote
189190
.connect(git::remote::Direction::Fetch, progress)?
190191
.prepare_fetch(Default::default())?

tests/index/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crates_index_diff::Index;
2+
use git_repository as git;
23
use git_testtools::tempfile::TempDir;
34
use std::path::PathBuf;
5+
use std::sync::atomic::AtomicBool;
46

57
mod changes_between_commits;
68

@@ -14,7 +16,8 @@ fn peek_changes() -> crate::Result {
1416
index.last_seen_reference().is_err(),
1517
"marker ref doesn't exist"
1618
);
17-
let (changes, last_seen_revision) = index.peek_changes()?;
19+
let (changes, last_seen_revision) =
20+
index.peek_changes_with_options2(git::progress::Discard, &AtomicBool::default())?;
1821
assert_eq!(
1922
changes.len(),
2023
NUM_CHANGES_SINCE_EVER,

0 commit comments

Comments
 (0)