Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put newest commit on top in CHANGELOG.md #15

Merged
merged 3 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ git-cliff [FLAGS] [OPTIONS] [RANGE]
-t, --tag <TAG> Sets the tag for the latest version [env: TAG=]
-b, --body <TEMPLATE> Sets the template for the changelog body [env: TEMPLATE=]
-s, --strip <PART> Strips the given parts from the changelog [possible values: header, footer, all]
--sort <sort> Sets sorting of the commits inside sections [default: oldest] [possible values: oldest, newest]
```

**Args:**
Expand Down Expand Up @@ -185,6 +186,17 @@ Generate a changelog scoped to a specific directory (useful for monorepos):
git cliff --commit-path project1/
```

Sort the commits inside sections:

```sh
# The oldest commit will be on top.
# (default)
git cliff --sort oldest

# The newest commit will be on top.
git cliff --sort newest
```

Save the changelog file to the specified file:

```sh
Expand Down
8 changes: 8 additions & 0 deletions git-cliff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,12 @@ pub struct Opt {
/// Sets the commit range to process.
#[structopt(value_name = "RANGE")]
pub range: Option<String>,

/// Sets sorting of the commits inside sections.
#[structopt(
long,
possible_values = &["oldest", "newest"],
default_value = "oldest"
)]
pub sort: String,
}
6 changes: 5 additions & 1 deletion git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ pub fn run(mut args: Opt) -> Result<()> {
for git_commit in commits.into_iter().rev() {
let commit = Commit::from(&git_commit);
let commit_id = commit.id.to_string();
releases[release_index].commits.push(commit);
if args.sort == "newest" {
releases[release_index].commits.insert(0, commit);
} else {
releases[release_index].commits.push(commit);
}
if let Some(tag) = tags.get(&commit_id) {
releases[release_index].version = Some(tag.to_string());
releases[release_index].commit_id = Some(commit_id);
Expand Down