Skip to content

Commit 751a120

Browse files
committed
fix sdk installation stuff not checking out properly
1 parent a2014f3 commit 751a120

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/sdk.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,20 @@ fn update(config: &mut Config, branch: Option<Branch>) {
340340
}
341341
}
342342

343+
fn switch_to_ref(repo: &Repository, name: &str) {
344+
let (obj, refer) = repo.revparse_ext(name).unwrap();
345+
repo.checkout_tree(&obj, None).expect("Unable to checkout tree");
346+
match refer {
347+
Some(gref) => repo.set_head(gref.name().unwrap()),
348+
None => repo.set_head_detached(obj.id()),
349+
}.expect("Failed to update head");
350+
}
351+
343352
fn switch_to_tag(config: &mut Config, repo: &Repository) {
344353
info!("Updating head");
345354

346355
if config.sdk_nightly {
347-
let fetch_head = repo.find_reference("FETCH_HEAD").unwrap();
348-
let fetch_commit = repo.reference_to_annotated_commit(&fetch_head).unwrap();
349-
repo.set_head("refs/heads/main").unwrap();
350-
let mut refer = repo.find_reference("refs/heads/main").unwrap();
351-
refer.set_target(fetch_commit.id(), "Fast-Forward").unwrap();
352-
repo.checkout_head(None)
353-
.expect("Unable to switch to latest commit");
356+
switch_to_ref(repo, "refs/heads/main");
354357
info!("Switched to latest commit");
355358
return;
356359
}
@@ -374,11 +377,8 @@ fn switch_to_tag(config: &mut Config, repo: &Repository) {
374377
return;
375378
}
376379

377-
// Change head and checkout
378-
let refname = format!("refs/tags/v{}", latest_version.as_ref().unwrap());
379-
repo.set_head(&refname).unwrap();
380-
repo.checkout_head(None).unwrap();
381-
380+
let tag_name = latest_version.as_ref().unwrap().to_string();
381+
switch_to_ref(repo, &format!("refs/tags/v{}", tag_name));
382382
done!("Updated head to v{}", latest_version.unwrap());
383383
}
384384

@@ -388,7 +388,7 @@ fn install_binaries(config: &mut Config) {
388388
let target_dir: PathBuf;
389389
if config.sdk_nightly {
390390
info!("Installing nightly binaries");
391-
release_tag = "Nightly".into();
391+
release_tag = "nightly".into();
392392
target_dir = Config::sdk_path().join("bin/nightly");
393393
} else {
394394
let ver = get_version();
@@ -413,7 +413,10 @@ fn install_binaries(config: &mut Config) {
413413
.send()
414414
.expect("Unable to get download info from GitHub")
415415
.json::<GithubReleaseResponse>()
416-
.expect("Unable to parse GitHub response");
416+
.unwrap_or_else(|_| fatal!(
417+
"It appears that \"{}\" is not a valid Geode release",
418+
release_tag
419+
));
417420

418421
let mut target_url: Option<String> = None;
419422
for asset in res.assets {

0 commit comments

Comments
 (0)