Skip to content

Commit 078da5a

Browse files
committed
refactor: deduce path from repo for GitCheckout
It was confusing and may lead to inconsistency that people need to pass both `path` and `repo` and ensure they are in sync.
1 parent 8739c0a commit 078da5a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl GitDatabase {
187187
// clone is created.
188188
let checkout = match git2::Repository::open(dest)
189189
.ok()
190-
.map(|repo| GitCheckout::new(dest, self, rev, repo))
190+
.map(|repo| GitCheckout::new(self, rev, repo))
191191
.filter(|co| co.is_fresh())
192192
{
193193
Some(co) => co,
@@ -265,13 +265,13 @@ impl<'a> GitCheckout<'a> {
265265
/// is done. Use [`GitCheckout::is_fresh`] to check.
266266
///
267267
/// * The `database` is where this checkout is from.
268-
/// * The `repo` will be the checked out Git repoistory at `path`.
268+
/// * The `repo` will be the checked out Git repoistory.
269269
fn new(
270-
path: &Path,
271270
database: &'a GitDatabase,
272271
revision: git2::Oid,
273272
repo: git2::Repository,
274273
) -> GitCheckout<'a> {
274+
let path = repo.workdir().unwrap_or_else(|| repo.path());
275275
GitCheckout {
276276
path: path.to_path_buf(),
277277
database,
@@ -335,7 +335,7 @@ impl<'a> GitCheckout<'a> {
335335
})?;
336336
let repo = repo.unwrap();
337337

338-
let checkout = GitCheckout::new(into, database, revision, repo);
338+
let checkout = GitCheckout::new(database, revision, repo);
339339
checkout.reset(config)?;
340340
Ok(checkout)
341341
}

0 commit comments

Comments
 (0)