From f84b658530c0c0eaaaa0473add8c8c359fa6b09e Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 16 Feb 2026 22:39:51 +0000 Subject: feat: add --offline flag to list, checkout, apply commands Skip network fetch when --offline is set, using only local cache --- src/bin/ngit/sub_commands/apply.rs | 12 +++++++----- src/bin/ngit/sub_commands/checkout.rs | 12 +++++++----- src/bin/ngit/sub_commands/list.rs | 16 +++++++++------- 3 files changed, 23 insertions(+), 17 deletions(-) (limited to 'src/bin/ngit/sub_commands') diff --git a/src/bin/ngit/sub_commands/apply.rs b/src/bin/ngit/sub_commands/apply.rs index 2d5d8d5..4b13975 100644 --- a/src/bin/ngit/sub_commands/apply.rs +++ b/src/bin/ngit/sub_commands/apply.rs @@ -73,7 +73,7 @@ fn run_git_fetch(remote_name: &str) -> Result<()> { Ok(()) } -pub async fn launch(id: &str, stdout: bool) -> Result<()> { +pub async fn launch(id: &str, stdout: bool, offline: bool) -> Result<()> { let event_id = parse_event_id(id)?; let git_repo = Repo::discover().context("failed to find a git repository")?; @@ -91,10 +91,12 @@ pub async fn launch(id: &str, stdout: bool) -> Result<()> { .ok() .flatten(); - if let Some((remote_name, _)) = &nostr_remote { - run_git_fetch(remote_name)?; - } else { - fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; + if !offline { + if let Some((remote_name, _)) = &nostr_remote { + run_git_fetch(remote_name)?; + } else { + fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; + } } let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; diff --git a/src/bin/ngit/sub_commands/checkout.rs b/src/bin/ngit/sub_commands/checkout.rs index 2fc9a09..19e39d0 100644 --- a/src/bin/ngit/sub_commands/checkout.rs +++ b/src/bin/ngit/sub_commands/checkout.rs @@ -28,7 +28,7 @@ use crate::{ repo_ref::get_repo_coordinates_when_remote_unknown, }; -pub async fn launch(id: &str) -> Result<()> { +pub async fn launch(id: &str, offline: bool) -> Result<()> { let event_id = parse_event_id(id)?; let git_repo = Repo::discover().context("failed to find a git repository")?; @@ -44,10 +44,12 @@ pub async fn launch(id: &str) -> Result<()> { .ok() .flatten(); - if let Some((remote_name, _)) = &nostr_remote { - run_git_fetch(remote_name)?; - } else { - fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; + if !offline { + if let Some((remote_name, _)) = &nostr_remote { + run_git_fetch(remote_name)?; + } else { + fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; + } } let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs index fc0883a..80eec21 100644 --- a/src/bin/ngit/sub_commands/list.rs +++ b/src/bin/ngit/sub_commands/list.rs @@ -95,7 +95,7 @@ fn run_git_fetch(remote_name: &str) -> Result<()> { } #[allow(clippy::too_many_lines)] -pub async fn launch(status: String, json: bool, id: Option) -> Result<()> { +pub async fn launch(status: String, json: bool, id: Option, offline: bool) -> Result<()> { if std::env::var("NGIT_INTERACTIVE_MODE").is_ok() { return launch_interactive().await; } @@ -113,14 +113,16 @@ pub async fn launch(status: String, json: bool, id: Option) -> Result<() .ok() .flatten(); - if let Some((remote_name, _)) = &nostr_remote { - if std::env::var("NGITTEST").is_ok() { - fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; + if !offline { + if let Some((remote_name, _)) = &nostr_remote { + if std::env::var("NGITTEST").is_ok() { + fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; + } else { + run_git_fetch(remote_name)?; + } } else { - run_git_fetch(remote_name)?; + fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; } - } else { - fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; } let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; -- cgit v1.2.3