Skip to content

Commit

Permalink
feat(args): accept glob patterns for --commit-path argument
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Nov 30, 2021
1 parent 6cec37d commit ad11cbf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ git cliff HEAD~2..
Generate a changelog scoped to a specific directory (useful for monorepos):

```sh
git cliff --commit-path project1/
git cliff --commit-path '**/*.toml'
```

Sort the commits inside sections:
Expand Down
1 change: 1 addition & 0 deletions git-cliff-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ regex = "1.5.4"
serde_regex = "1.1.0"
indexmap = "1.7.0"
toml = "0.5.8"
glob = "0.3.0"

[dependencies.git2]
version = "0.13.23"
Expand Down
5 changes: 4 additions & 1 deletion git-cliff-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! A highly customizable changelog generator
#![warn(missing_docs, clippy::unwrap_used)]

/// Export regex crate.
/// Export `glob` crate.
pub use glob;
/// Export `regex` crate.
pub use regex;

/// Git commit.
pub mod commit;
/// Config file parser.
Expand Down
5 changes: 3 additions & 2 deletions git-cliff-core/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use git2::{
Repository as GitRepository,
Sort,
};
use glob::Pattern;
use indexmap::IndexMap;
use std::io;
use std::path::PathBuf;
Expand Down Expand Up @@ -39,7 +40,7 @@ impl Repository {
pub fn commits(
&self,
range: Option<String>,
path: Option<String>,
path: Option<Pattern>,
) -> Result<Vec<Commit>> {
let mut revwalk = self.inner.revwalk()?;
revwalk.set_sorting(Sort::TIME | Sort::TOPOLOGICAL)?;
Expand All @@ -64,7 +65,7 @@ impl Repository {
) {
return diff.deltas().any(|delta| {
delta.new_file().path().map_or(false, |path| {
path.starts_with(&commit_path)
commit_path.matches_path(path)
})
});
}
Expand Down
3 changes: 2 additions & 1 deletion git-cliff/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use git_cliff_core::glob::Pattern;
use git_cliff_core::DEFAULT_CONFIG;
use std::path::PathBuf;
use structopt::clap::AppSettings;
Expand Down Expand Up @@ -38,7 +39,7 @@ pub struct Opt {
pub repository: Option<PathBuf>,
/// Sets the directory to parse commits from.
#[structopt(long, env, value_name = "PATH")]
pub commit_path: Option<String>,
pub commit_path: Option<Pattern>,
/// Prepends entries to the given changelog file.
#[structopt(short, long, env, value_name = "PATH")]
pub prepend: Option<PathBuf>,
Expand Down

0 comments on commit ad11cbf

Please sign in to comment.