Skip to content

Commit d2fa0e9

Browse files
committed
feat: add --hidden/--no-ignore flags
1 parent 4113cd7 commit d2fa0e9

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

CHANGELOG.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
# Changelog
22

3+
All notable changes to this project will be documented in this file.
4+
35
## Unreleased
46

5-
- Process repositories in parallel
7+
- Nothing yet!
8+
9+
## Version 0.2.0 - 2024-06-05
10+
11+
- Implemented parallel processing of repositories.
12+
- Introduced `--hidden` flag to include hidden directories in the repository search.
13+
- Introduced `--no-ignore` flag to bypass `.gitignore` files when searching for repositories.
614

7-
## Version 0.1.1
15+
## Version 0.1.1 - 2024-06-04
816

9-
- Add Powershell and Homebrew installers
17+
- Added support for Powershell and Homebrew installers.
1018

11-
## Version 0.1.0
19+
## Version 0.1.0 - 2024-06-04
1220

13-
- Initial release
21+
- Initial release of `git-foreach`.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "git-foreach"
33
description = "Run a command in each git repository in a directory"
4-
version = "0.1.1"
4+
version = "0.2.0"
55
edition = "2021"
66
license-file = "LICENSE"
77
homepage = "https://github.com/marcfrederick/git-foreach"

src/main.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::env;
55
use std::path::PathBuf;
66

77
use clap::Parser;
8-
use ignore::{DirEntry, Walk};
8+
use ignore::{DirEntry, WalkBuilder};
99
use rayon::prelude::*;
1010

1111
use crate::error::Error;
@@ -30,6 +30,15 @@ struct Options {
3030
)]
3131
directory: PathBuf,
3232

33+
#[arg(long, help = "Search hidden files and directories.")]
34+
hidden: bool,
35+
36+
#[arg(
37+
long,
38+
help = "When set, ignore files such as .gitignore will not be respected."
39+
)]
40+
no_ignore: bool,
41+
3342
#[arg(trailing_var_arg = true, required = true)]
3443
command: Vec<String>,
3544
}
@@ -42,7 +51,8 @@ fn main() {
4251
/// subdirectories.
4352
fn repository_foreach<T: Iterator<Item = String>>(args: T) -> Result<(), Error> {
4453
let options = parse_options(args)?;
45-
find_repositories(&options.directory)
54+
dbg!(&options);
55+
find_repositories(&options)
4656
.par_iter()
4757
.map(|repository| run_command_in_directory(&options, repository))
4858
.collect()
@@ -54,9 +64,14 @@ fn parse_options<T: Iterator<Item = String>>(args: T) -> Result<Options, Error>
5464
}
5565

5666
/// Find all git repositories in a directory and its subdirectories.
57-
fn find_repositories(path: &PathBuf) -> HashSet<PathBuf> {
58-
Walk::new(path)
59-
.flatten()
67+
fn find_repositories(options: &Options) -> HashSet<PathBuf> {
68+
let walk = WalkBuilder::new(&options.directory)
69+
.hidden(options.hidden)
70+
.ignore(!options.no_ignore)
71+
.git_ignore(!options.no_ignore)
72+
.build();
73+
74+
walk.flatten()
6075
.map(DirEntry::into_path)
6176
.filter(|path| path.is_dir() && path.join(".git").exists())
6277
.collect()

0 commit comments

Comments
 (0)