From 3a2187b5ded01ce5f5a92d42777ee98ee6efe546 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Tue, 15 Aug 2023 16:06:54 +0200 Subject: [PATCH] Fix harder --- src/git.rs | 27 +++++++-------------------- tests/sync_git.rs | 21 ++++++++++++++------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/git.rs b/src/git.rs index 3533b39..ca060cb 100644 --- a/src/git.rs +++ b/src/git.rs @@ -263,6 +263,13 @@ fn reset(repo: &mut gix::Repository, rev: gix::ObjectId) -> Result<()> { .write(Default::default()) .context("failed to write index")?; + // cargo uses the head oid to check if it needs to update the submodule + // so force set HEAD to the appropriate commit, since we don't really + // care about updates for the head we just set it directly rather than + // via reference + let head_path = repo.path().join("HEAD"); + std::fs::write(head_path, format!("{}\n", rev.to_hex()))?; + Ok(()) } @@ -487,26 +494,6 @@ pub(crate) fn prepare_submodules(src: PathBuf, target: PathBuf, rev: gix::Object .context("failed to write FETCH_HEAD")?; reset(&mut repo, head)?; - - // cargo uses the head oid to check if it needs to update the submodule - // so force set HEAD to the appropriate commit, since we don't really - // care about updates for the head we just set it directly rather than - // via reference - use gix::refs::transaction as tx; - repo.edit_reference(tx::RefEdit { - change: tx::Change::Update { - log: tx::LogChange { - mode: tx::RefLog::AndReference, - force_create_reflog: false, - message: "".into(), - }, - expected: tx::PreviousValue::Any, - new: gix::refs::Target::Peeled(head), - }, - name: "HEAD".try_into().unwrap(), - deref: true, - })?; - update_submodules(&mut repo, head) } diff --git a/tests/sync_git.rs b/tests/sync_git.rs index df6f107..d73b6a2 100644 --- a/tests/sync_git.rs +++ b/tests/sync_git.rs @@ -139,18 +139,25 @@ async fn proper_head() { let rev = "1bbec17"; // Ensure that gilrs's checkout matches what cargo expects - let checkout = fs_ctx.root_dir.join(format!( - "{}/gilrs-{ident}/{rev}/gilrs/SDL_GameControllerDB", - cf::sync::GIT_CO_DIR - )); + let mut checkout = fs_ctx + .root_dir + .join(format!("{}/gilrs-{ident}/{rev}", cf::sync::GIT_CO_DIR)); - let output = { + let head = |path| { let mut cmd = std::process::Command::new("git"); - cmd.current_dir(&checkout); + cmd.current_dir(path); cmd.args(["rev-parse", "HEAD"]); cmd.stdout(std::process::Stdio::piped()); String::from_utf8(cmd.output().unwrap().stdout).unwrap() }; - assert_eq!(output.trim(), "c3517cf0d87b35ebe6ae4f738e1d96166e44b58f"); + assert_eq!( + head(checkout.clone()).trim(), + "1bbec17c9ecb6884f96370064b34544f132c93af" + ); + checkout.push("gilrs/SDL_GameControllerDB"); + assert_eq!( + head(checkout).trim(), + "c3517cf0d87b35ebe6ae4f738e1d96166e44b58f" + ); }