diff --git a/README.md b/README.md index 712a5cdbc0..0ea818768a 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,7 @@ git-cliff [FLAGS] [OPTIONS] [RANGE] -r, --repository Sets the git repository [env: REPOSITORY=] --include-path ... Sets the path to include related commits [env: INCLUDE_PATH=] --exclude-path ... Sets the path to exclude related commits [env: EXCLUDE_PATH=] + --with-commit ... Sets custom commit messages to include in the changelog [env: WITH_COMMIT=] -p, --prepend Prepends entries to the given changelog file [env: PREPEND= -o, --output Writes output to the given file [env: OUTPUT=] -t, --tag Sets the tag for the latest version [env: TAG=] @@ -221,6 +222,18 @@ git cliff --include-path "**/*.toml" --include-path "*.md" git cliff --exclude-path ".github/*" ``` +Generate a changelog that includes yet unexisting commit messages: + +```sh +commit_msg="chore(release): update CHANGELOG.md for 1.0.0" + +# You might need to include the commit messages that do not exist +# for testing purposes or solving the chicken-egg problem. +git cliff --with-commit "$commit_msg" + +git commit -m "$commit_msg" +``` + Sort the commits inside sections: ```sh diff --git a/git-cliff/src/args.rs b/git-cliff/src/args.rs index 3972e7c4f2..b033e634af 100644 --- a/git-cliff/src/args.rs +++ b/git-cliff/src/args.rs @@ -43,6 +43,9 @@ pub struct Opt { /// Sets the path to exclude related commits. #[structopt(long, env, value_name = "PATTERN")] pub exclude_path: Option>, + /// Sets custom commit messages to include in the changelog. + #[structopt(long, env, value_name = "MSG")] + pub with_commit: Option>, /// Prepends entries to the given changelog file. #[structopt(short, long, env, value_name = "PATH")] pub prepend: Option, diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index 97485781ff..9fa63d4b34 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -217,6 +217,17 @@ pub fn run(mut args: Opt) -> Result<()> { } } + // Add custom commit messages to the latest release. + if let Some(custom_commits) = args.with_commit { + if let Some(latest_release) = releases.iter_mut().last() { + custom_commits.iter().for_each(|commit_message| { + latest_release + .commits + .push(Commit::new(String::new(), commit_message.to_string())) + }); + } + } + // Set the previous release if needed. if args.latest { if let Some((commit_id, version)) = tags.get_index(tags.len() - 2) {