mirror of
https://github.com/jnsahaj/lumen.git
synced 2025-08-04 19:08:21 +00:00
fix: Add error handling for invalid range
This commit is contained in:
parent
fece7a8125
commit
45405417ce
1 changed files with 6 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
|||
use crate::error::LumenError;
|
||||
use thiserror::Error;
|
||||
|
||||
use super::commit::Commit;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum DiffError {
|
||||
#[error("diff{} is empty", if *staged { " (staged)" } else { "" })]
|
||||
|
@ -39,11 +41,15 @@ impl Diff {
|
|||
}
|
||||
|
||||
pub fn from_commits_range(from: &str, to: &str) -> Result<Self, LumenError> {
|
||||
let _ = Commit::is_valid_commit(from)?;
|
||||
let _ = Commit::is_valid_commit(to)?;
|
||||
|
||||
let output = std::process::Command::new("git")
|
||||
.args(["diff", from, to])
|
||||
.output()?;
|
||||
|
||||
let diff = String::from_utf8(output.stdout)?;
|
||||
|
||||
if diff.is_empty() {
|
||||
return Err(DiffError::EmptyDiff { staged: false }.into());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue