Skip to content

Commit

Permalink
feat(changelog, config)!: replace --date-order by --topo-order
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun authored Dec 16, 2022
1 parent 352e884 commit 77731ec
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 44 deletions.
2 changes: 0 additions & 2 deletions .github/fixtures/test-date-order/cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ footer = """
<!-- generated by git-cliff -->
"""

[git]
date_order = true
6 changes: 3 additions & 3 deletions .github/fixtures/test-fixtures-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
SCRIPT_DIR=$(readlink -f "$(dirname "$0")")

if [ -z "$1" ]; then
echo "Please input a fixture name."
exit 1
echo "Please input a fixture name."
exit 1
fi

export FIXTURES_DIR="$SCRIPT_DIR/$1"
Expand All @@ -19,4 +19,4 @@ git init

# Show results
echo -e "\n---Run git-cliff---"
cargo run --manifest-path "$SCRIPT_DIR/../../Cargo.toml" -- --config "$FIXTURES_DIR/cliff.toml" $2
cargo run --manifest-path "$SCRIPT_DIR/../../Cargo.toml" -- --config "$FIXTURES_DIR/cliff.toml" "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

All notable changes to this project will be documented in this file.

## [0.1.1] - 2021-01-23
## [0.2.0] - 2021-01-23

### Feat

- Fix feature 1
- Add feature 2

<!-- generated by git-cliff -->
3 changes: 3 additions & 0 deletions .github/fixtures/test-topo-order/cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ trim = true
footer = """
<!-- generated by git-cliff -->
"""

[git]
topo_order = true
4 changes: 2 additions & 2 deletions .github/workflows/test-fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
command: --latest
- fixtures-name: test-date-order
command: --latest
- fixtures-name: test-date-order-arg
command: --latest --date-order
- fixtures-name: test-topo-order-arg
command: --latest --topo-order
- fixtures-name: test-latest-with-one-tag
command: --latest
- fixtures-name: test-commit-preprocessors
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
- [tag_pattern](#tag_pattern)
- [skip_tags](#skip_tags)
- [ignore_tags](#ignore_tags)
- [date_order](#date_order)
- [topo_order](#topo_order)
- [sort_commits](#sort_commits)
- [link_parsers](#link_parsers)
- [Project Integration](#project-integration)
Expand Down Expand Up @@ -164,7 +164,7 @@ git-cliff [FLAGS] [OPTIONS] [--] [RANGE]
-l, --latest Processes the commits starting from the latest tag
--current Processes the commits that belong to the current tag
-u, --unreleased Processes the commits that do not belong to a tag
-d, --date-order Sorts the tags chronologically
--topo-order Sorts the tags topologically
--context Prints changelog context as JSON
-h, --help Prints help information
-V, --version Prints version information
Expand Down Expand Up @@ -270,11 +270,11 @@ git cliff --sort oldest
git cliff --sort newest
```

Sort the tags in chronological order:
Sort the tags in topological order:

```sh
# Process in chronological order instead of topological.
git cliff --date-order
# Process in topological order instead of chronological.
git cliff --topo-order
```

Save the changelog file to the specified file:
Expand Down Expand Up @@ -463,7 +463,7 @@ filter_commits = false
tag_pattern = "v[0-9]*"
skip_tags = "v0.1.0-beta.1"
ignore_tags = ""
date_order = false
topo_order = false
sort_commits = "oldest"
link_parsers = [
{ pattern = "#(\\d+)", href = "https://github.com/orhun/git-cliff/issues/$1"},
Expand Down Expand Up @@ -625,11 +625,11 @@ A regex for ignore processing the matched tags.

While `skip_tags` drop commits from the changelog, `ignore_tags` include ignored commits into the next tag.

#### date_order
#### topo_order

If set to `true`, tags are processed in chronological order instead of topological.
If set to `true`, tags are processed in topological order instead of chronological.

This can also be achieved by using the `--date-order` command line flag.
This can also be achieved by using the `--topo-order` command line flag.

#### sort_commits

Expand Down
4 changes: 2 additions & 2 deletions config/cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ tag_pattern = "v[0-9]*"
skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = ""
# sort the tags chronologically
date_order = false
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
# limit the number of commits included in the changelog.
Expand Down
4 changes: 2 additions & 2 deletions examples/detailed.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ tag_pattern = "v[0-9]*"
skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = ""
# sort the tags chronologically
date_order = false
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
4 changes: 2 additions & 2 deletions examples/keepachangelog.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ tag_pattern = "v[0-9]*"
skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = ""
# sort the tags chronologically
date_order = false
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
4 changes: 2 additions & 2 deletions examples/scoped.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ tag_pattern = "v[0-9]*"
skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = ""
# sort the tags chronologically
date_order = false
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
4 changes: 2 additions & 2 deletions examples/scopesorted.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ tag_pattern = "v[0-9]*"
skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = ""
# sort the tags chronologically
date_order = false
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
4 changes: 2 additions & 2 deletions examples/unconventional.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ tag_pattern = "v[0-9]*"
skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = ""
# sort the tags chronologically
date_order = false
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
4 changes: 2 additions & 2 deletions git-cliff-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ pub struct GitConfig {
#[serde(with = "serde_regex", default)]
/// Regex to ignore matched tags.
pub ignore_tags: Option<Regex>,
/// Whether to sort tags chronologically.
pub date_order: Option<bool>,
/// Whether to sort tags topologically.
pub topo_order: Option<bool>,
/// Sorting of the commits inside sections.
pub sort_commits: Option<String>,
/// Limit the number of commits included in the changelog.
Expand Down
4 changes: 2 additions & 2 deletions git-cliff-core/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Repository {
pub fn tags(
&self,
pattern: &Option<String>,
date_order: bool,
topo_order: bool,
) -> Result<IndexMap<String, String>> {
let mut tags: Vec<(Commit, String)> = Vec::new();
let tag_names = self.inner.tag_names(pattern.as_deref())?;
Expand All @@ -121,7 +121,7 @@ impl Repository {
}
}
}
if date_order {
if !topo_order {
tags.sort_by(|a, b| a.0.time().seconds().cmp(&b.0.time().seconds()));
}
Ok(tags
Expand Down
2 changes: 1 addition & 1 deletion git-cliff-core/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn generate_changelog() -> Result<()> {
tag_pattern: None,
skip_tags: None,
ignore_tags: None,
date_order: None,
topo_order: None,
sort_commits: None,
link_parsers: Some(vec![
LinkParser {
Expand Down
6 changes: 3 additions & 3 deletions git-cliff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ pub struct Opt {
/// Processes the commits that do not belong to a tag.
#[clap(short, long, help_heading = Some("FLAGS"))]
pub unreleased: bool,
/// Sorts the tags chronologically.
#[clap(short, long, help_heading = Some("FLAGS"))]
pub date_order: bool,
/// Sorts the tags topologically.
#[clap(long, help_heading = Some("FLAGS"))]
pub topo_order: bool,
/// Prints changelog context as JSON.
#[clap(long, help_heading = Some("FLAGS"))]
pub context: bool,
Expand Down
2 changes: 1 addition & 1 deletion git-cliff/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ mod test {
tag_pattern: None,
skip_tags: Regex::new("v3.*").ok(),
ignore_tags: None,
date_order: Some(false),
topo_order: Some(false),
sort_commits: Some(String::from("oldest")),
link_parsers: None,
limit_commits: None,
Expand Down
10 changes: 5 additions & 5 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ pub fn run(mut args: Opt) -> Result<()> {
.expect("Incorrect config value for 'sort_commits'");
}
}
if !args.date_order {
if let Some(date_order) = config.git.date_order {
args.date_order = date_order;
if !args.topo_order {
if let Some(topo_order) = config.git.topo_order {
args.topo_order = topo_order;
}
}

Expand All @@ -143,7 +143,7 @@ pub fn run(mut args: Opt) -> Result<()> {
Repository::init(args.repository.clone().unwrap_or(env::current_dir()?))?;

// Parse tags.
let mut tags = repository.tags(&config.git.tag_pattern, args.date_order)?;
let mut tags = repository.tags(&config.git.tag_pattern, args.topo_order)?;

// Skip tags.
config.git.skip_tags = config.git.skip_tags.filter(|r| !r.as_str().is_empty());
Expand Down Expand Up @@ -207,7 +207,7 @@ pub fn run(mut args: Opt) -> Result<()> {
None => {
return Err(Error::ChangelogError(String::from(
"No suitable tags found. Maybe run with \
'--date-order'?",
'--topo-order'?",
)));
}
}
Expand Down

0 comments on commit 77731ec

Please sign in to comment.