Skip to content

Commit

Permalink
fix(git): sort commits in topological order (#415)
Browse files Browse the repository at this point in the history
Commit a1b4b5b ("fix(git): sort the commits in topological order"), changed
the order from `TIME` to `TIME | TOPOLOGICAL`. According to the docs, this
is equivalent to `git log --date-sort`:

* https://github.com/libgit2/libgit2/blob/v1.7.1/include/git2/revwalk.h#L33-L38

This breaks down in the following scenario:

1. A PR is open.
2. A release v1 is made.
3. A PR is merged.
4. A relase v2 is made.

The git history for this would be:

```
- v2 release
- pr merge commit
- v1 release
- actual pr commit
```

This directly spills into the changelog produced by `git-cliff`, misattributing
commits that were merged in v2 to v1 retroactively when v2 is made.

You can see this with `git log`. If you pass `--topo-order` there:

```
- v2 relase
- pr merge commit
- actual pr commit
- v1 relase
```

With this change we only pass `Sort::TOPOLOGICAL` in `git-cliff`, which
produces the very same results as `git log --topo-order`.
  • Loading branch information
bobrik committed Dec 29, 2023
1 parent bff58d4 commit 29bf355
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion git-cliff-core/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Repository {
exclude_path: Option<Vec<Pattern>>,
) -> Result<Vec<Commit>> {
let mut revwalk = self.inner.revwalk()?;
revwalk.set_sorting(Sort::TIME | Sort::TOPOLOGICAL)?;
revwalk.set_sorting(Sort::TOPOLOGICAL)?;
if let Some(range) = range {
revwalk.push_range(&range)?;
} else {
Expand Down

0 comments on commit 29bf355

Please sign in to comment.