summary history branches tags files
commit:f89f44b34099b619b4f37f8947cbd45f2aa988de
author:Trevor Bentley
committer:Trevor Bentley
date:Thu Jan 26 01:30:20 2023 +0100
parents:08b075e29d1dee8046cc8ae0f015b7ba5073d606
fetch_remote setting to disable remote repo updates
diff --git a/config.toml b/config.toml
line changes: +14/-0
index 7af3374..e45e46d
--- 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
line changes: +20/-15
index 42178b5..b04d1de
--- 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<String> = 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<String> = 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
line changes: +5/-0
index f0b7edd..cc64eb4
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -364,6 +364,7 @@ pub struct GitsySettingsRepo {
     pub render_markdown: Option<bool>,
     pub syntax_highlight: Option<bool>,
     pub syntax_highlight_theme: Option<String>,
+    pub fetch_remote: Option<bool>,
     pub attributes: Option<BTreeMap<String, toml::Value>>,
     pub paginate_history: Option<usize>,
     pub paginate_branches: Option<usize>,
@@ -406,6 +407,7 @@ pub struct GitsySettings {
     pub readme_files: Option<Vec<String>>,
     pub asset_files: Option<Vec<String>>,
     pub branch: Option<String>,
+    pub fetch_remote: Option<bool>,
     pub paginate_history: Option<usize>,
     pub paginate_branches: Option<usize>,
     pub paginate_tags: Option<usize>,
@@ -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(),