diff --git a/git-cliff-core/src/repo.rs b/git-cliff-core/src/repo.rs index a666a504b6..b7f8cad3ba 100644 --- a/git-cliff-core/src/repo.rs +++ b/git-cliff-core/src/repo.rs @@ -72,21 +72,18 @@ impl Repository { pub fn commits( &self, range: Option<&str>, - include_root: bool, include_path: Option>, exclude_path: Option>, ) -> Result> { let mut revwalk = self.inner.revwalk()?; revwalk.set_sorting(Sort::TOPOLOGICAL)?; if let Some(range) = range { - // Push only the last range commit if we need to start at root. - if include_root { - if let Some(dots_index) = range.find("..") { - revwalk.push(Oid::from_str(&range[dots_index + 2..])?)?; - } - } else { - revwalk.push_range(range)?; - } + if range.contains("..") { + revwalk.push_range(range)?; + } else { + // when we get a single sha as our "range" => start at root. + revwalk.push(Oid::from_str(&range)?)?; + } } else { revwalk.push_head()?; } @@ -508,7 +505,7 @@ mod test { #[test] fn get_latest_commit() -> Result<()> { let repository = get_repository()?; - let commits = repository.commits(None, false, None, None)?; + let commits = repository.commits(None, None, None)?; let last_commit = AppCommit::from(&commits.first().expect("no commits found").clone()); assert_eq!(get_last_commit_hash()?, last_commit.id); @@ -609,7 +606,9 @@ mod test { #[test] fn includes_root_commit() -> Result<()> { let repository = get_repository()?; - let commits = repository.commits(None, true, None, None)?; + // a close descendant of the root commit + let range = Some("eea3914c7ab07472841aa85c36d11bdb2589a234"); + let commits = repository.commits(range, None, None)?; let root_commit = AppCommit::from(&commits.last().expect("no commits found").clone()); assert_eq!(get_root_commit_hash()?, root_commit.id); diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index ff72c343ae..8aa508776b 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -160,20 +160,22 @@ fn process_repository<'a>( // Parse commits. let mut commit_range = args.range.clone(); - let mut include_root = false; if args.unreleased { if let Some(last_tag) = tags.last().map(|(k, _)| k) { commit_range = Some(format!("{last_tag}..HEAD")); } } else if args.latest || args.current { if tags.len() < 2 { - let commits = repository.commits(None, false, None, None)?; + let commits = repository.commits(None, None, None)?; if let (Some(tag1), Some(tag2)) = ( commits.last().map(|c| c.id().to_string()), tags.get_index(0).map(|(k, _)| k), ) { - commit_range = Some(format!("{tag1}..{tag2}")); - include_root = true; + if tags.len() == 1 { + commit_range = Some(tag2.to_owned()); + } else { + commit_range = Some(format!("{tag1}..{tag2}")); + } } } else { let mut tag_index = tags.len() - 2; @@ -210,7 +212,6 @@ fn process_repository<'a>( } let mut commits = repository.commits( commit_range.as_deref(), - include_root, args.include_path.clone(), args.exclude_path.clone(), )?;