diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-09-10 17:01:26 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-09-10 17:01:26 +0100 |
| commit | 3b0e8e9708993ac13e8ba413249014132e1d0e0b (patch) | |
| tree | e0c6edf07e25e444790fbf3822e34c29fc46fcfa /src/bin/ngit/sub_commands/init.rs | |
| parent | 732567f85383782851d3c0dd43283d29df0c098f (diff) | |
fix(init): when local repo missing origin refs
now we check and fetch them
Diffstat (limited to 'src/bin/ngit/sub_commands/init.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 1b8268c..dc8c673 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -16,6 +16,7 @@ use ngit::{ | |||
| 16 | show_multi_input_prompt_success, | 16 | show_multi_input_prompt_success, |
| 17 | }, | 17 | }, |
| 18 | client::{Params, get_state_from_cache, send_events}, | 18 | client::{Params, get_state_from_cache, send_events}, |
| 19 | fetch::fetch_from_git_server, | ||
| 19 | git::nostr_url::{CloneUrl, NostrUrlDecoded}, | 20 | git::nostr_url::{CloneUrl, NostrUrlDecoded}, |
| 20 | list::list_from_remote, | 21 | list::list_from_remote, |
| 21 | repo_ref::{ | 22 | repo_ref::{ |
| @@ -789,8 +790,27 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 789 | || key.starts_with("refs/tags/") | 790 | || key.starts_with("refs/tags/") |
| 790 | || key.starts_with("HEAD") | 791 | || key.starts_with("HEAD") |
| 791 | }); | 792 | }); |
| 792 | // TODO ngit sync will error if any of these remote refs are not available | 793 | let mut required_oids = vec![]; |
| 793 | // locally | 794 | for tip in origin_state.values() { |
| 795 | if let Ok(exist) = git_repo.does_commit_exist(tip) { | ||
| 796 | if !exist { | ||
| 797 | required_oids.push(tip.clone()); | ||
| 798 | } | ||
| 799 | } | ||
| 800 | } | ||
| 801 | if required_oids.is_empty() { | ||
| 802 | println!("fetching refs missing locally from existing origin..."); | ||
| 803 | if let Err(error) = fetch_from_git_server( | ||
| 804 | &git_repo, | ||
| 805 | &required_oids, | ||
| 806 | url, | ||
| 807 | &nostr_url_decoded, | ||
| 808 | &Term::stdout(), | ||
| 809 | false, | ||
| 810 | ) { | ||
| 811 | println!("error fetching refs which will make ngit sync fail: {error}"); | ||
| 812 | } | ||
| 813 | } | ||
| 794 | let new_state_event = | 814 | let new_state_event = |
| 795 | RepoState::build(repo_ref.identifier.clone(), origin_state, &signer) | 815 | RepoState::build(repo_ref.identifier.clone(), origin_state, &signer) |
| 796 | .await? | 816 | .await? |