Skip to content

Commit

Permalink
remove panic for git calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kilork committed Nov 18, 2019
1 parent 8abcffc commit 69032bf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
25 changes: 20 additions & 5 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,26 @@ impl<'a> TargetRepository for GitTargetRepository<'a> {
info!("Resetting Git repo.");
self.git(&["reset", "--hard"], cron)
} else {
panic!("Cannot checkout HEAD revision in Git repo.")
return Err(TargetRepositoryError::GitFailure(
status,
"Cannot checkout HEAD revision in Git repo.".into(),
));
};

let status = if status.success() {
info!("Cleanup Git repo");
self.git(&["clean", "-d", "-x", "-f"], cron)
} else {
panic!("Cannot reset Git repo.")
return Err(TargetRepositoryError::GitFailure(
status,
"Cannot reset Git repo.".into(),
));
};
if !status.success() {
panic!("Cannot cleanup Git repo.");
return Err(TargetRepositoryError::GitFailure(
status,
"Cannot cleanup Git repo.".into(),
));
};

let (target_push, target_pull) = self
Expand All @@ -240,10 +249,16 @@ impl<'a> TargetRepository for GitTargetRepository<'a> {
let status = if status.success() {
self.git(&["push", "--tags"], cron)
} else {
panic!("Cannot push all to Git repo.");
return Err(TargetRepositoryError::GitFailure(
status,
"Cannot push all to Git repo.".into(),
));
};
if !status.success() {
panic!("Cannot push all tags to Git repo.");
return Err(TargetRepositoryError::GitFailure(
status,
"Cannot push all tags to Git repo.".into(),
));
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ pub enum TargetRepositoryError {
CannotConfigRepo(ExitStatus),
#[fail(display = "import failed {}", _0)]
ImportFailed(ExitStatus),
#[fail(display = "git failure {}", _0)]
GitFailure(ExitStatus),
#[fail(display = "git failure {}: {}", _0, _1)]
GitFailure(ExitStatus, String),
#[fail(display = "io error {}", _0)]
IOError(std::io::Error),
#[fail(display = "verification failed")]
Expand Down
2 changes: 2 additions & 0 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub fn build_marks<P: AsRef<Path>, S: ::std::hash::BuildHasher>(
if !git_output.status.success() {
return Err(ErrorKind::Target(TargetRepositoryError::GitFailure(
git_output.status,
"git log failed".into(),
)));
}

Expand Down Expand Up @@ -245,6 +246,7 @@ fn find_matching_sha1_index(
if !git_output.status.success() {
return Err(ErrorKind::Target(TargetRepositoryError::GitFailure(
git_output.status,
"git show failed".into(),
)));
}

Expand Down

0 comments on commit 69032bf

Please sign in to comment.