diff --git a/README.md b/README.md index 4caf4a867c..2b70907eda 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ git-cliff [FLAGS] [OPTIONS] [RANGE] -i, --init Writes the default configuration file to cliff.toml -l, --latest Processes the commits starting from the latest tag -u, --unreleased Processes the commits that do not belong to a tag + --topo-order Sorts the tags topologically -h, --help Prints help information -V, --version Prints version information ``` @@ -218,6 +219,13 @@ git cliff --sort oldest git cliff --sort newest ``` +Sort the tags in topological order: + +```sh +# Process in topological order instead of chronological. +git cliff --topo-order +``` + Save the changelog file to the specified file: ```sh diff --git a/git-cliff-core/src/repo.rs b/git-cliff-core/src/repo.rs index b29e68fb32..31979b72c4 100644 --- a/git-cliff-core/src/repo.rs +++ b/git-cliff-core/src/repo.rs @@ -82,6 +82,7 @@ impl Repository { pub fn tags( &self, pattern: &Option, + topo_order: bool, ) -> Result> { let mut tags: Vec<(Commit, String)> = Vec::new(); let tag_names = self.inner.tag_names(pattern.as_deref())?; @@ -100,7 +101,9 @@ impl Repository { } } } - tags.sort_by(|a, b| a.0.time().seconds().cmp(&b.0.time().seconds())); + if !topo_order { + tags.sort_by(|a, b| a.0.time().seconds().cmp(&b.0.time().seconds())); + } Ok(tags .into_iter() .map(|(a, b)| (a.id().to_string(), b)) @@ -164,7 +167,7 @@ mod test { } } } - let tags = repository.tags(&None)?; + let tags = repository.tags(&None, false)?; assert_eq!(&get_last_tag()?, tags.last().unwrap().1); Ok(()) } diff --git a/git-cliff/src/args.rs b/git-cliff/src/args.rs index 62c00704ab..69b0842c1e 100644 --- a/git-cliff/src/args.rs +++ b/git-cliff/src/args.rs @@ -66,6 +66,9 @@ pub struct Opt { /// Processes the commits that do not belong to a tag. #[structopt(short, long)] pub unreleased: bool, + /// Sorts the tags topologically. + #[structopt(long)] + pub topo_order: bool, /// Strips the given parts from the changelog. #[structopt( short, @@ -77,12 +80,11 @@ pub struct Opt { /// Sets the commit range to process. #[structopt(value_name = "RANGE")] pub range: Option, - /// Sets sorting of the commits inside sections. #[structopt( long, possible_values = &["oldest", "newest"], default_value = "oldest" )] - pub sort: String, + pub sort: String, } diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index 84420aa78f..03cd32fbb6 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -102,7 +102,7 @@ pub fn run(mut args: Opt) -> Result<()> { Repository::init(args.repository.unwrap_or(env::current_dir()?))?; // Parse tags. - let mut tags = repository.tags(&config.git.tag_pattern)?; + let mut tags = repository.tags(&config.git.tag_pattern, args.topo_order)?; // Parse commits. let mut commit_range = args.range;