Skip to content

Commit

Permalink
fallback to calling git process on auth error
Browse files Browse the repository at this point in the history
also dont update on install-binaries command, kinda pointless

fixes #39
  • Loading branch information
matcool committed Feb 25, 2024
1 parent 4dc8d9b commit 7d114ed
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use serde::Deserialize;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;

#[cfg(target_os = "macos")]
use crate::launchctl;
Expand Down Expand Up @@ -282,13 +283,26 @@ fn fetch_repo_info(repo: &git2::Repository) -> git2::MergeAnalysis {
true
});

remote
.fetch(
&["main"],
Some(FetchOptions::new().remote_callbacks(callbacks)),
None,
)
.nice_unwrap("Could not fetch latest update");
let res = remote.fetch(
&["main"],
Some(FetchOptions::new().remote_callbacks(callbacks)),
None,
);
if res.as_ref().is_err_and(|e| {
e.message()
.contains("authentication required but no callback set")
}) {
// Setting the authentication callback is kinda jank, just call the git process lmao
Command::new("git")
.args(&["fetch", "origin", "main"])
.current_dir(Config::sdk_path())
.spawn()
.nice_unwrap("Could not fetch latest update")
.wait()
.nice_unwrap("Could not fetch latest update");
} else {
res.nice_unwrap("Could not fetch latest update");
}

// Check if can fast-forward
let fetch_head = repo.find_reference("FETCH_HEAD").unwrap();
Expand Down Expand Up @@ -414,7 +428,6 @@ fn switch_to_tag(config: &mut Config, repo: &Repository) {
}

fn install_binaries(config: &mut Config, platform: Option<String>) {
update(config, None);
let release_tag: String;
let target_dir: PathBuf;
if config.sdk_nightly {
Expand Down

0 comments on commit 7d114ed

Please sign in to comment.