From f89f44b34099b619b4f37f8947cbd45f2aa988de Mon Sep 17 00:00:00 2001 From: Trevor Bentley Date: Thu, 26 Jan 2023 01:30:20 +0100 Subject: [PATCH] fetch_remote setting to disable remote repo updates --- config.toml | 14 ++++++++++++++ src/generate.rs | 35 ++++++++++++++++++++--------------- src/settings.rs | 5 +++++ 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/config.toml b/config.toml index 7af3374..e45e46d 100644 --- a/config.toml +++ b/config.toml @@ -159,6 +159,20 @@ syntax_highlight = true # syntax_highlight_theme = "base16-ocean.light" +# Whether or not to run 'git fetch' on remote repos +# +# When specified repositories are remote (via HTTPS), this setting +# configures whether Itsy-Gitsy should run the equivalent of `git +# fetch --all` to update the repository first. +# +# Itsy-Gitsy will exit with an error if the fetch fails. If a +# repository is not available, or if Itsy-Gitsy is running in an +# environment without network access, this should be set to 'false'. +# +# This can also be set per-repository. Defaults to 'true' if not +# specified. +fetch_remote = true + # Number of threads to use for parallel processing # # Specify a specify a specific number of threads/cores to split diff --git a/src/generate.rs b/src/generate.rs index 42178b5..b04d1de 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -149,21 +149,26 @@ impl GitsyGenerator { .collect(); match Repository::open(&clone_path) { Ok(r) => { - // Repo already cloned, so update all refs - let refs: Vec = r - .references() - .expect(&format!("Unable to enumerate references for repo [{}]", name)) - .map(|x| { - x.expect(&format!("Found invalid reference in repo [{}]", name)) - .name() - .expect(&format!("Found unnamed reference in repo: [{}]", name)) - .to_string() - }) - .collect(); - r.find_remote("origin") - .expect(&format!("Clone of repo [{}] missing `origin` remote.", name)) - .fetch(&refs, None, None) - .expect(&format!("Failed to fetch updates from remote repo [{}]", name)); + match self.settings.fetch_remote { + Some(false) => {} + _ => { // explicitly true, or unspecified (default) + // Repo already cloned, so update all refs + let refs: Vec = r + .references() + .expect(&format!("Unable to enumerate references for repo [{}]", name)) + .map(|x| { + x.expect(&format!("Found invalid reference in repo [{}]", name)) + .name() + .expect(&format!("Found unnamed reference in repo: [{}]", name)) + .to_string() + }) + .collect(); + r.find_remote("origin") + .expect(&format!("Clone of repo [{}] missing `origin` remote.", name)) + .fetch(&refs, None, None) + .expect(&format!("Failed to fetch updates from remote repo [{}]", name)); + }, + } clone_path.to_string_lossy().to_string() } Err(_) => { diff --git a/src/settings.rs b/src/settings.rs index f0b7edd..cc64eb4 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -364,6 +364,7 @@ pub struct GitsySettingsRepo { pub render_markdown: Option, pub syntax_highlight: Option, pub syntax_highlight_theme: Option, + pub fetch_remote: Option, pub attributes: Option>, pub paginate_history: Option, pub paginate_branches: Option, @@ -406,6 +407,7 @@ pub struct GitsySettings { pub readme_files: Option>, pub asset_files: Option>, pub branch: Option, + pub fetch_remote: Option, pub paginate_history: Option, pub paginate_branches: Option, pub paginate_tags: Option, @@ -491,6 +493,7 @@ impl GitsySettings { global_to_repo!(settings, repo, render_markdown); global_to_repo!(settings, repo, syntax_highlight); global_to_repo!(settings, repo, syntax_highlight_theme); + global_to_repo!(settings, repo, fetch_remote); global_to_repo!(settings, repo, paginate_history); global_to_repo!(settings, repo, paginate_branches); global_to_repo!(settings, repo, paginate_tags); @@ -533,6 +536,7 @@ impl GitsySettings { render_markdown: settings.render_markdown.clone(), syntax_highlight: settings.syntax_highlight.clone(), syntax_highlight_theme: settings.syntax_highlight_theme.clone(), + fetch_remote: settings.fetch_remote.clone(), paginate_history: settings.paginate_history.clone(), paginate_branches: settings.paginate_branches.clone(), paginate_tags: settings.paginate_tags.clone(), @@ -576,6 +580,7 @@ impl GitsySettings { render_markdown: settings.render_markdown.clone(), syntax_highlight: settings.syntax_highlight.clone(), syntax_highlight_theme: settings.syntax_highlight_theme.clone(), + fetch_remote: settings.fetch_remote.clone(), paginate_history: settings.paginate_history.clone(), paginate_branches: settings.paginate_branches.clone(), paginate_tags: settings.paginate_tags.clone(),