Skip to content

Commit

Permalink
fix geode sdk install
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Oct 8, 2023
1 parent 1099774 commit aea12b4
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use path_absolutize::Absolutize;
use crate::config::Config;
use crate::util::logging::ask_confirm;
use git2::build::{RepoBuilder, CheckoutBuilder};
use git2::{FetchOptions, RemoteCallbacks, Repository, SubmoduleUpdateOptions};
use git2::{FetchOptions, RemoteCallbacks, Repository};
use reqwest::header::{USER_AGENT, AUTHORIZATION};
use semver::{Version, Prerelease};
use serde::Deserialize;
Expand Down Expand Up @@ -230,13 +230,43 @@ fn install(config: &mut Config, path: PathBuf, force: bool) {
);
}

fetch_repo_info(&repo);

switch_to_tag(config, &repo);

done!("Successfully installed SDK");
info!("Please restart your command line to have the GEODE_SDK enviroment variable set.");
info!("Use `geode sdk install-binaries` to install pre-built binaries");
}

fn fetch_repo_info(repo: &git2::Repository) -> git2::MergeAnalysis {
let mut remote = repo.find_remote("origin").unwrap();

let mut callbacks = RemoteCallbacks::new();
callbacks.sideband_progress(|x| {
print!(
"{} {}",
"| Info |".bright_cyan(),
std::str::from_utf8(x).unwrap()
);
true
});

remote
.fetch(
&["main"],
Some(FetchOptions::new().remote_callbacks(callbacks)),
None,
)
.nice_unwrap("Could not fetch latest update");

// Check if can fast-forward
let fetch_head = repo.find_reference("FETCH_HEAD").unwrap();
let fetch_commit = repo.reference_to_annotated_commit(&fetch_head).unwrap();

repo.merge_analysis(&[&fetch_commit]).unwrap().0
}

fn update(config: &mut Config, branch: Option<String>) {
// Switch branch if necessary
match branch.as_deref().unwrap_or(if config.sdk_nightly { "nightly" } else { "stable" }) {
Expand Down Expand Up @@ -264,31 +294,7 @@ fn update(config: &mut Config, branch: Option<String>) {
.nice_unwrap("Could not initialize local SDK repository");

// Fetch
let mut remote = repo.find_remote("origin").unwrap();

let mut callbacks = RemoteCallbacks::new();
callbacks.sideband_progress(|x| {
print!(
"{} {}",
"| Info |".bright_cyan(),
std::str::from_utf8(x).unwrap()
);
true
});

remote
.fetch(
&["main"],
Some(FetchOptions::new().remote_callbacks(callbacks)),
None,
)
.nice_unwrap("Could not fetch latest update");

// Check if can fast-forward
let fetch_head = repo.find_reference("FETCH_HEAD").unwrap();
let fetch_commit = repo.reference_to_annotated_commit(&fetch_head).unwrap();

let merge_analysis = repo.merge_analysis(&[&fetch_commit]).unwrap().0;
let merge_analysis = fetch_repo_info(&repo);

if merge_analysis.is_up_to_date() {
switch_to_tag(config, &repo);
Expand Down

0 comments on commit aea12b4

Please sign in to comment.