diff options
author | Nick Gerace <39320683+nickgerace@users.noreply.github.com> | 2020-08-24 01:59:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-24 01:59:22 -0400 |
commit | d5441613992a45b0fe0a6c8e85b4af9172f6a3ed (patch) | |
tree | 4881d10d541c13b967901639603e875b63c7f98d | |
parent | 236496f3344e467743893f77e7af099e3c5e3684 (diff) | |
download | gfold-d5441613992a45b0fe0a6c8e85b4af9172f6a3ed.zip |
Skip bare repositories during status fetching (#13)
Add error handling for bare repositories. This is a fix to GitHub issue 11. During status fetching
for a given repository object, we will "continue" to the next repository object if the current
object is bare.
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | src/gfold.rs | 11 |
2 files changed, 15 insertions, 4 deletions
@@ -7,9 +7,13 @@ MAKEPATH:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) NAME:=gfold -cargo-tree: +run: + @cd $(MAKEPATH); cargo fmt + @cd $(MAKEPATH); cargo run -- -p .. + +tree: cd $(MAKEPATH); cargo tree -build-static: +static: docker pull clux/muslrust cd $(MAKEPATH); docker run -v $(MAKEPATH):/volume --rm -t clux/muslrust cargo build diff --git a/src/gfold.rs b/src/gfold.rs index 3eb16ed..3c1de77 100644 --- a/src/gfold.rs +++ b/src/gfold.rs @@ -5,7 +5,7 @@ * License: MIT License */ -use git2::{ErrorClass, Repository, StatusOptions}; +use git2::{ErrorClass, ErrorCode, Repository, StatusOptions}; use prettytable::{format, Table}; use std::fs; @@ -65,11 +65,18 @@ pub fn walk_dir(path: &Path) { Some(head) => head, None => "none", }; + + // If the repository is bare, then we skip it altogether. This addresses GitHub + // issue: https://github.com/nickgerace/gfold/issues/11 let mut opts = StatusOptions::new(); let statuses = match repo_obj.statuses(Some(&mut opts)) { Ok(statuses) => statuses, - Err(e) => panic!("failed get statuses: {}", e), + Err(error) => match error.code() { + ErrorCode::BareRepo => continue, + _ => panic!("failed to get statuses: {}", error), + }, }; + let formatted_name = match Path::new(&repo).strip_prefix(path) { Ok(formatted_name) => formatted_name, Err(e) => panic!("failed to format name from Path object: {}", e), |