Skip to content

Commit

Permalink
Fix harder
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Aug 15, 2023
1 parent 8597f7e commit 3a2187b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
27 changes: 7 additions & 20 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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)
}

Expand Down
21 changes: 14 additions & 7 deletions tests/sync_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}

0 comments on commit 3a2187b

Please sign in to comment.