Skip to content

Commit 821037c

Browse files
committed
fix repo initialization
1 parent e8bcb7e commit 821037c

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

crates/uv-git/src/git.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ pub(crate) struct GitDatabase {
130130

131131
/// A local checkout of a particular revision from a [`GitRepository`].
132132
pub(crate) struct GitCheckout {
133-
/// Path to the root of the underlying Git repository on the local filesystem.
134-
path: PathBuf,
135133
/// The git revision this checkout is for.
136134
revision: GitOid,
137135
/// Underlying Git repository instance for this checkout.
@@ -150,7 +148,7 @@ impl GitRepository {
150148
// Make sure there is a Git repository at the specified path.
151149
ProcessBuilder::new("git")
152150
.arg("rev-parse")
153-
.arg("HEAD")
151+
.cwd(path)
154152
.exec_with_streaming(&mut silent, &mut silent, true)?;
155153

156154
Ok(GitRepository {
@@ -293,7 +291,9 @@ impl GitDatabase {
293291
.cwd(&self.repo.path)
294292
.exec_with_streaming(&mut silent, &mut silent, true)?;
295293

296-
Ok(String::from_utf8(output.stdout)?)
294+
let mut result = String::from_utf8(output.stdout)?;
295+
result.truncate(result.trim_end().len());
296+
Ok(result)
297297
}
298298

299299
/// Checks if the database contains the object of this `oid`.
@@ -343,11 +343,7 @@ impl GitCheckout {
343343
///
344344
/// * The `repo` will be the checked out Git repository.
345345
fn new(revision: GitOid, repo: GitRepository) -> GitCheckout {
346-
GitCheckout {
347-
path: repo.path.clone(),
348-
revision,
349-
repo,
350-
}
346+
GitCheckout { revision, repo }
351347
}
352348

353349
/// Clone a repo for a `revision` into a local path from a `database`.
@@ -384,7 +380,7 @@ impl GitCheckout {
384380
match self.repo.rev_parse("HEAD") {
385381
Ok(id) if id == self.revision => {
386382
// See comments in reset() for why we check this
387-
self.path.join(CHECKOUT_READY_LOCK).exists()
383+
self.repo.path.join(CHECKOUT_READY_LOCK).exists()
388384
}
389385
_ => false,
390386
}
@@ -404,7 +400,7 @@ impl GitCheckout {
404400
///
405401
/// [`.cargo-ok`]: CHECKOUT_READY_LOCK
406402
fn reset(&self) -> Result<()> {
407-
let ok_file = self.path.join(CHECKOUT_READY_LOCK);
403+
let ok_file = self.repo.path.join(CHECKOUT_READY_LOCK);
408404
let _ = paths::remove_file(&ok_file);
409405
debug!("reset {} to {}", self.repo.path.display(), self.revision);
410406

@@ -419,7 +415,7 @@ impl GitCheckout {
419415
.arg("reset")
420416
.arg("--hard")
421417
.arg(self.revision.as_str())
422-
.cwd(&self.path)
418+
.cwd(&self.repo.path)
423419
.exec_with_streaming(&mut silent, &mut silent, true)?;
424420

425421
paths::create(ok_file)?;
@@ -433,7 +429,7 @@ impl GitCheckout {
433429
.arg("update")
434430
.arg("--recursive")
435431
.arg("--init")
436-
.cwd(&self.path)
432+
.cwd(&self.repo.path)
437433
.exec_with_streaming(&mut silent, &mut silent, true)
438434
.map(drop)
439435
}

0 commit comments

Comments
 (0)