Permalink
Browse files

add --ignore-uncommited-repos

  • Loading branch information...
tshepang committed Jan 16, 2018
1 parent 4b079d9 commit 0bb76224978fca2324ae7b673472b68033db5a78
Showing with 25 additions and 0 deletions.
  1. +1 −0 README.md
  2. +18 −0 src/lib.rs
  3. +6 −0 src/main.rs
View
@@ -14,6 +14,7 @@ It reports if those repos have:
- deleted files
- renamed files
- untracked files (can be disabled)
- uncommitted repos (can be disabled)
- untagged HEAD (optional)
- unpushed tags (optional)
- unpulled tags (optional)
View
@@ -10,6 +10,7 @@
//! - deleted files
//! - renamed files
//! - untracked files (can be disabled)
//! - uncommitted repos (can be disabled)
//! - untagged HEAD (optional)
//! - unpushed tags (optional)
//! - unpulled tags (optional)
@@ -53,6 +54,7 @@ pub struct Output {
pub struct Crawler<'a> {
pending: bool,
ignore_untracked: bool,
ignore_uncommitted_repos: bool,
absolute_paths: bool,
untagged_heads: bool,
access_remote: bool,
@@ -66,6 +68,7 @@ impl<'a> Crawler<'a> {
Crawler {
pending: false,
ignore_untracked: false,
ignore_uncommitted_repos: false,
absolute_paths: false,
untagged_heads: false,
access_remote: false,
@@ -93,6 +96,15 @@ impl<'a> Crawler<'a> {
self
}
/// Decide if you want to exclude repos that have no commits
///
/// This will happen when a `git init` is executed,
/// and one forgets to commit.
pub fn ignore_uncommitted_repos(mut self, answer: bool) -> Self {
self.ignore_uncommitted_repos = answer;
self
}
/// Display absolute paths (instead of relative ones)
pub fn absolute_paths(mut self, answer: bool) -> Self {
self.absolute_paths = answer;
@@ -137,6 +149,12 @@ impl<'a> Crawler<'a> {
let local_ref = match repo.head() {
Ok(head) => head,
Err(why) => {
if self.ignore_uncommitted_repos
&& why.class() == git2::ErrorClass::Reference
&& why.code() == git2::ErrorCode::UnbornBranch
{
return None;
}
return Some(Output {
path: path,
pending: None,
View
@@ -33,6 +33,11 @@ struct Opt {
help = "Do not include untracked files in output",
)]
ignore_untracked: bool,
#[structopt(
long = "ignore-uncommited-repos",
help = "Do not include repos that have no commits",
)]
ignore_uncommitted_repos: bool,
#[structopt(
long = "absolute-paths",
help = "Display absolute paths for repos",
@@ -85,6 +90,7 @@ fn main() {
let crawler = Crawler::new(&current_dir)
.pending(cli.pending)
.ignore_untracked(cli.ignore_untracked)
.ignore_uncommitted_repos(cli.ignore_uncommitted_repos)
.access_remote(cli.access_remote)
.absolute_paths(cli.absolute_paths)
.untagged_heads(cli.untagged_heads);

0 comments on commit 0bb7622

Please sign in to comment.