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

add a only_first_parent option to only consider commits on current branch #324

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/git/revspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
pub fn all_commits(&self) -> Result<CommitRange, Git2Error> {
let mut revwalk = self.0.revwalk()?;
revwalk.push_head()?;
if SETTINGS.only_first_parent {
revwalk.simplify_first_parent()?;
}
let mut commits = vec![];

for oid in revwalk {
Expand Down Expand Up @@ -331,6 +334,9 @@
let mut revwalk = self.0.revwalk()?;

revwalk.push_range(spec)?;
if SETTINGS.only_first_parent {
revwalk.simplify_first_parent()?;

Check warning on line 338 in src/git/revspec.rs

View check run for this annotation

Codecov / codecov/patch

src/git/revspec.rs#L338

Added line #L338 was not covered by tests
}

let mut commits: Vec<Commit> = vec![];

Expand Down
2 changes: 2 additions & 0 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct Settings {
pub from_latest_tag: bool,
pub ignore_merge_commits: bool,
pub generate_mono_repository_global_tag: bool,
pub only_first_parent: bool,
pub monorepo_version_separator: Option<String>,
pub branch_whitelist: Vec<String>,
pub tag_prefix: Option<String>,
Expand All @@ -55,6 +56,7 @@ impl Default for Settings {
from_latest_tag: false,
ignore_merge_commits: false,
generate_mono_repository_global_tag: true,
only_first_parent: false,
monorepo_version_separator: None,
branch_whitelist: vec![],
tag_prefix: None,
Expand Down
29 changes: 29 additions & 0 deletions tests/lib_tests/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use cocogitto::CocoGitto;
use crate::helpers::*;

use anyhow::Result;
use cmd_lib::run_cmd;
use sealed_test::prelude::*;
use speculoos::prelude::*;

Expand Down Expand Up @@ -48,3 +49,31 @@ fn get_log_with_no_errors() -> Result<()> {

Ok(())
}

#[sealed_test]
fn get_log_on_master_only() -> Result<()> {
// Arrange
git_init()?;
let settings = r#"only_first_parent = true"#;
run_cmd!(echo $settings > cog.toml;)?;
git_commit("chore: initial commit")?;

run_cmd!(git checkout -b feature)?;
git_commit("feat: a commit on feature branch")?;
git_commit("fix: a commit on feature branch")?;
run_cmd!(
git checkout master;
git merge --no-ff -m "feat: feature" feature;
)?;

let filters = CommitFilters(vec![CommitFilter::NoError]);
let cocogitto = CocoGitto::get()?;

// Act
let logs = cocogitto.get_log(filters)?;

// Assert we don't see feature branch commit
assert_that!(logs).does_not_contain("a commit on feature branch");

Ok(())
}