diff --git a/git-cliff-core/src/changelog.rs b/git-cliff-core/src/changelog.rs index 0094706016..e7f7c6e409 100644 --- a/git-cliff-core/src/changelog.rs +++ b/git-cliff-core/src/changelog.rs @@ -34,8 +34,11 @@ pub struct Changelog<'a> { impl<'a> Changelog<'a> { /// Constructs a new instance. pub fn new(releases: Vec>, config: Config, range: Option<&str>) -> Result { + let is_offline = config.remote.offline; let mut changelog = Changelog::build(releases, config)?; - changelog.add_remote_data(range)?; + if !is_offline { + changelog.add_remote_data(range)?; + } changelog.process_commits()?; changelog.process_releases(); Ok(changelog) @@ -954,6 +957,7 @@ mod test { exclude_paths: Vec::new(), }, remote: RemoteConfig { + offline: false, github: Remote { owner: String::from("coolguy"), repo: String::from("awesome"), diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index f5ec7f6d8d..4f5b9fcc5a 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -177,6 +177,9 @@ mod serde_pattern { /// Remote configuration. #[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct RemoteConfig { + /// Run generation fully offline + #[serde(default)] + pub offline: bool, /// GitHub remote. #[serde(default)] pub github: Remote, diff --git a/git-cliff/src/args.rs b/git-cliff/src/args.rs index 0c2e874246..2b97eeccf5 100644 --- a/git-cliff/src/args.rs +++ b/git-cliff/src/args.rs @@ -359,6 +359,9 @@ pub struct Opt { /// Load TLS certificates from the native certificate store. #[arg(long, help_heading = Some("FLAGS"), hide = !cfg!(feature = "remote"))] pub use_native_tls: bool, + /// Use only local git history in actions + #[arg(long, help_heading = Some("FLAGS"))] + pub offline: bool, } /// Custom type for the remote value. diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index 21abb42b5d..e1f8199c64 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -654,6 +654,9 @@ pub fn run_with_changelog_modifier<'a>( .token .clone_from(&args.azure_devops_token); } + if args.offline { + config.remote.offline = args.offline; + } if let Some(ref remote) = args.github_repo { config.remote.github.owner = remote.0.owner.to_string(); config.remote.github.repo = remote.0.repo.to_string(); diff --git a/git-cliff/src/main.rs b/git-cliff/src/main.rs index f0fb17bf89..7be0ee8cc7 100644 --- a/git-cliff/src/main.rs +++ b/git-cliff/src/main.rs @@ -36,7 +36,9 @@ fn main() -> Result<()> { // Check if there is a new version available. #[cfg(feature = "update-informer")] - git_cliff::check_new_version(); + if !args.offline { + git_cliff::check_new_version(); + } // Create the configuration file if init flag is given. if let Some(path) = &args.init { diff --git a/website/docs/configuration/remote.md b/website/docs/configuration/remote.md index 3a54134f5e..240fc2c3f3 100644 --- a/website/docs/configuration/remote.md +++ b/website/docs/configuration/remote.md @@ -68,6 +68,10 @@ However, in some cases, you may want to use the platform's native certificate st ::: +### offline + +When the `offline` argument or configuration parameter is set `git-cliff` ensures that no external calls or requests are made, despite a remote being configured. This can be useful when running `--bumped-version` or in a limited environment. + --- Here is a complete example for a project hosted on GitLab: