Skip to content

Commit aea12b4

Browse files
committed
fix geode sdk install
1 parent 1099774 commit aea12b4

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

src/sdk.rs

+32-26
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use path_absolutize::Absolutize;
44
use crate::config::Config;
55
use crate::util::logging::ask_confirm;
66
use git2::build::{RepoBuilder, CheckoutBuilder};
7-
use git2::{FetchOptions, RemoteCallbacks, Repository, SubmoduleUpdateOptions};
7+
use git2::{FetchOptions, RemoteCallbacks, Repository};
88
use reqwest::header::{USER_AGENT, AUTHORIZATION};
99
use semver::{Version, Prerelease};
1010
use serde::Deserialize;
@@ -230,13 +230,43 @@ fn install(config: &mut Config, path: PathBuf, force: bool) {
230230
);
231231
}
232232

233+
fetch_repo_info(&repo);
234+
233235
switch_to_tag(config, &repo);
234236

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

242+
fn fetch_repo_info(repo: &git2::Repository) -> git2::MergeAnalysis {
243+
let mut remote = repo.find_remote("origin").unwrap();
244+
245+
let mut callbacks = RemoteCallbacks::new();
246+
callbacks.sideband_progress(|x| {
247+
print!(
248+
"{} {}",
249+
"| Info |".bright_cyan(),
250+
std::str::from_utf8(x).unwrap()
251+
);
252+
true
253+
});
254+
255+
remote
256+
.fetch(
257+
&["main"],
258+
Some(FetchOptions::new().remote_callbacks(callbacks)),
259+
None,
260+
)
261+
.nice_unwrap("Could not fetch latest update");
262+
263+
// Check if can fast-forward
264+
let fetch_head = repo.find_reference("FETCH_HEAD").unwrap();
265+
let fetch_commit = repo.reference_to_annotated_commit(&fetch_head).unwrap();
266+
267+
repo.merge_analysis(&[&fetch_commit]).unwrap().0
268+
}
269+
240270
fn update(config: &mut Config, branch: Option<String>) {
241271
// Switch branch if necessary
242272
match branch.as_deref().unwrap_or(if config.sdk_nightly { "nightly" } else { "stable" }) {
@@ -264,31 +294,7 @@ fn update(config: &mut Config, branch: Option<String>) {
264294
.nice_unwrap("Could not initialize local SDK repository");
265295

266296
// Fetch
267-
let mut remote = repo.find_remote("origin").unwrap();
268-
269-
let mut callbacks = RemoteCallbacks::new();
270-
callbacks.sideband_progress(|x| {
271-
print!(
272-
"{} {}",
273-
"| Info |".bright_cyan(),
274-
std::str::from_utf8(x).unwrap()
275-
);
276-
true
277-
});
278-
279-
remote
280-
.fetch(
281-
&["main"],
282-
Some(FetchOptions::new().remote_callbacks(callbacks)),
283-
None,
284-
)
285-
.nice_unwrap("Could not fetch latest update");
286-
287-
// Check if can fast-forward
288-
let fetch_head = repo.find_reference("FETCH_HEAD").unwrap();
289-
let fetch_commit = repo.reference_to_annotated_commit(&fetch_head).unwrap();
290-
291-
let merge_analysis = repo.merge_analysis(&[&fetch_commit]).unwrap().0;
297+
let merge_analysis = fetch_repo_info(&repo);
292298

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

0 commit comments

Comments
 (0)