Skip to content

Commit 9746a9c

Browse files
committed
feat: adding error on no commits in range
1 parent 43e7203 commit 9746a9c

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

conventional_commits_linter/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "conventional_commits_linter"
3-
version = "0.9.0"
3+
version = "0.10.0"
44
description = "A tooling and language agnostic utility to lint Git commits against the Conventional Commits specification."
55
authors = ["C <DeveloperC@protonmail.com>"]
66
edition = "2021"
@@ -26,7 +26,7 @@ git2 = { version = "0.13.25", default-features = false, features=[] }
2626
strum = "0.23.0"
2727
strum_macros = "0.23.1"
2828

29-
conventional_commits_linter_lib = "0.1.0"
29+
conventional_commits_linter_lib = "0.2.0"
3030

3131

3232
[dev-dependencies]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: When the range of commits from to lint are empty, then an error is returned.
2+
3+
4+
Scenario Outline:
5+
Given the repository "<repository>" is cloned and checked out at the commit "<checkout_commit>".
6+
When the argument --from-commit-hash is provided as "<checkout_commit>".
7+
Then their is a no commits error.
8+
9+
10+
Examples:
11+
| repository | checkout_commit |
12+
| https://github.com/danielduarte/diffparse.git | df6be23b79af66d3684fb27719020e1ce587f4b8 |

conventional_commits_linter/end-to-end-tests/features/steps/then.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,15 @@ def then_ambiguous_shortened_commit_hash_error(context, shortened_commit_hash):
141141
# Then
142142
assert ambiguous_shortened_commit_hash_error.match(
143143
context.stderr) is not None
144+
145+
146+
@then('their is a no commits error.')
147+
def then_no_commits_error(context):
148+
# Given
149+
no_commits_error = " ERROR conventional_commits_linter_lib::commits > No Git commits within the provided range.\n"
150+
151+
# When/Then
152+
then_linting_fails(context)
153+
154+
# Then
155+
assert context.stderr == no_commits_error

conventional_commits_linter_lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "conventional_commits_linter_lib"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = "A tooling and language agnostic library to lint Git commits against the Conventional Commits specification."
55
authors = ["C <DeveloperC@protonmail.com>"]
66
edition = "2021"

conventional_commits_linter_lib/src/commits/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,14 @@ fn get_commits_till_head_from_oid(
169169
commits.push_front(commit);
170170
}
171171

172-
debug!("Operating upon {} commits.", commits.len());
173-
174-
Ok(commits)
172+
if commits.is_empty() {
173+
let error_message = "No Git commits within the provided range.".to_string();
174+
error!("{error_message}");
175+
Err(git2::Error::from_str(&error_message))
176+
} else {
177+
debug!("Operating upon {} commits.", commits.len());
178+
Ok(commits)
179+
}
175180
}
176181

177182
fn get_reference_oid(repository: &Repository, matching: &str) -> Result<Oid, git2::Error> {

0 commit comments

Comments
 (0)