Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 68 additions & 62 deletions src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,11 @@ fn install(config: &mut Config, path: PathBuf, force: bool) {
fetch_repo_info(&repo);

switch_to_tag(config, &repo);
install_binaries(config, None, None);

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");
info!("Pre-built binaries have been automatically installed. However, if you would like to install them yourself in the future, you can run `geode sdk install-binaries`.");
}

fn fetch_repo_info(repo: &git2::Repository) -> git2::MergeAnalysis {
Expand Down Expand Up @@ -441,67 +442,72 @@ fn fetch_repo_info(repo: &git2::Repository) -> git2::MergeAnalysis {
}

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"
}) {
"nightly" => {
info!("Switching to nightly");
config.sdk_nightly = true;
config.sdk_version = None;
}
"stable" => {
info!("Switching to stable");
config.sdk_nightly = false;
config.sdk_version = None;
}
ver => {
info!("Switching to {}", ver);
config.sdk_nightly = false;
config.sdk_version = Some(ver.into());
}
};

info!("Updating SDK");

// Initialize repository
let repo = Repository::open(Config::sdk_path())
.nice_unwrap("Could not initialize local SDK repository");

// Fetch
let merge_analysis = fetch_repo_info(&repo);

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

done!("SDK is up to date");
} else if merge_analysis.is_fast_forward() {
// Change head and checkout

switch_to_tag(config, &repo);

done!("Successfully updated SDK.");
} else {
let mut opts = StatusOptions::new();
opts.renames_head_to_index(true)
.include_untracked(true)
.recurse_untracked_dirs(true);

let statuses = repo.statuses(Some(&mut opts));
if statuses.is_ok_and(|x| !x.is_empty()) {
fail!("Cannot update SDK, it has local changes");
info!(
"Go into the repository at {} and manually run `git pull`",
Config::sdk_path().to_str().unwrap()
);
} else {
switch_to_tag(config, &repo);

done!("Successfully updated SDK.");
}
}
// Switch branch if necessary
match branch.as_deref().unwrap_or(if config.sdk_nightly {
"nightly"
} else {
"stable"
}) {
"nightly" => {
info!("Switching to nightly");
config.sdk_nightly = true;
config.sdk_version = None;
}
"stable" => {
info!("Switching to stable");
config.sdk_nightly = false;
config.sdk_version = None;
}
ver => {
info!("Switching to {}", ver);
config.sdk_nightly = false;
config.sdk_version = Some(ver.into());
}
};

info!("Updating SDK");

// Initialize repository
let repo = Repository::open(Config::sdk_path())
.nice_unwrap("Could not initialize local SDK repository");

// Fetch
let merge_analysis = fetch_repo_info(&repo);

if merge_analysis.is_up_to_date() {
switch_to_tag(config, &repo);
install_binaries(config, None, None);

done!("SDK is up to date");
} else if merge_analysis.is_fast_forward() {
// Change head and checkout

switch_to_tag(config, &repo);
install_binaries(config, None, None);

done!("Successfully updated SDK.");
info!("Pre-built binaries have been automatically installed as well, but if you wish to install them manually in the future, run `geode sdk install-binaries`.")
} else {
let mut opts = StatusOptions::new();
opts.renames_head_to_index(true)
.include_untracked(true)
.recurse_untracked_dirs(true);

let statuses = repo.statuses(Some(&mut opts));
if statuses.is_ok_and(|x| !x.is_empty()) {
fail!("Cannot update SDK, it has local changes");
info!(
"Go into the repository at {} and manually run `git pull`",
Config::sdk_path().to_str().unwrap()
);
} else {
switch_to_tag(config, &repo);
install_binaries(config, None, None);

done!("Successfully updated SDK.");
info!("Pre-built binaries have been automatically installed as well, but if you wish to install them manually in the future, run `geode sdk install-binaries`.")
}
}
}

fn switch_to_ref(repo: &Repository, name: &str) {
Expand Down