From e4fd7810937ac6a386d50c4b05bd75b8006125cb Mon Sep 17 00:00:00 2001 From: Tymon <73666325+nomyTx@users.noreply.github.com> Date: Wed, 4 Oct 2023 05:00:10 +0200 Subject: [PATCH] fix updating sdk (this time for real) this code sucks --- src/sdk.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/sdk.rs b/src/sdk.rs index 86dc0bc..16d37de 100644 --- a/src/sdk.rs +++ b/src/sdk.rs @@ -298,9 +298,7 @@ fn update(config: &mut Config, branch: Option) { .nice_unwrap("Could not initialize local SDK repository"); // Fetch - let mut remote = repo - .find_remote(repo.remotes().unwrap().iter().next().unwrap().unwrap()) - .unwrap(); + let mut remote = repo.find_remote("origin").unwrap(); let mut callbacks = RemoteCallbacks::new(); callbacks.sideband_progress(|x| { @@ -346,14 +344,21 @@ fn update(config: &mut Config, branch: Option) { } fn switch_to_ref(repo: &Repository, name: &str) { - let mut reference = repo.find_reference(name).unwrap(); + let mut reference = repo.find_reference("refs/heads/main").unwrap(); let fetch_head = repo.find_reference("FETCH_HEAD").unwrap(); let fetch_commit = repo.reference_to_annotated_commit(&fetch_head).unwrap(); reference.set_target(fetch_commit.id(), "Fast-Forward").unwrap(); - repo.set_head(name).nice_unwrap("Failed to set head"); + repo.set_head("refs/heads/main").unwrap(); repo.checkout_head(Some(CheckoutBuilder::default().force())) - .nice_unwrap("Failed to checkout head"); + .nice_unwrap("Failed to checkout main"); + + let (obj, refer) = repo.revparse_ext(name).unwrap(); + repo.checkout_tree(&obj, None).nice_unwrap("Unable to checkout tree"); + match refer { + Some(refer) => repo.set_head(refer.name().unwrap()), + None => repo.set_head_detached(obj.id()), + }.nice_unwrap("Failed to update head"); } fn switch_to_tag(config: &mut Config, repo: &Repository) {