diff options
Diffstat (limited to 'src/git.rs')
| -rw-r--r-- | src/git.rs | 40 |
1 files changed, 27 insertions, 13 deletions
@@ -1,3 +1,8 @@ +// TODO: fix error handling +// TODO: fix cloning +// TODO: consistant naming +// TODO: check matchers + use std::num::ParseIntError; use std::fmt; use std::process::Command; @@ -26,7 +31,6 @@ impl From<ParseIntError> for GitError { } impl std::error::Error for GitError {} -////// TODO pub fn get_files_to_unstage() -> String { let cmd = Command::new("git") .arg("update-index") @@ -149,8 +153,7 @@ pub fn get_last_ref() -> Result<String, GitError> { .output() .expect("Error with git show-ref"); if !cmd.status.success() { - //return GitError::GitLog(String::from_utf8_lossy(&cmd.stderr).to_string()); - GitError::GitLog(String::from_utf8_lossy(&cmd.stderr).to_string()); + return Err(GitError::GitLog(String::from_utf8_lossy(&cmd.stderr).to_string())); } let lines = String::from_utf8_lossy(&cmd.stdout); @@ -168,12 +171,29 @@ pub fn get_current_tree() -> Result<String, GitError>{ .output() .expect("Error with git log"); if !cmd.status.success() { - GitError::GitLog(String::from_utf8_lossy(&cmd.stderr).to_string()); + return Err(GitError::GitLog(String::from_utf8_lossy(&cmd.stderr).to_string())); + } + let lines = String::from_utf8_lossy(&cmd.stdout); + Ok(lines.trim().to_string()) +} + +pub fn short_to_long_hash(short: String) -> Result<String, GitError>{ + let cmd = Command::new("git") + .arg("log") + .arg("-1") // TODO: don't limit the output and check if the output is more then one + .arg("--format=%H") + .arg(short) + .output() + .expect("Error with git log"); + if !cmd.status.success() { + return Err(GitError::GitLog(String::from_utf8_lossy(&cmd.stderr).to_string())); } let lines = String::from_utf8_lossy(&cmd.stdout); Ok(lines.trim().to_string()) } + + pub fn write_tree() -> String { let cmd = Command::new("git") .arg("write-tree") @@ -215,7 +235,8 @@ pub fn check_status() { .output() .expect("Error with git status"); if !logs.status.success() { - GitError::GitLog(String::from_utf8_lossy(&logs.stderr).to_string()); + panic!("{}", String::from_utf8_lossy(&logs.stderr).to_string()); + //Err(GitError::GitLog(String::from_utf8_lossy(&logs.stderr).to_string())); } let lines = String::from_utf8_lossy(&logs.stdout); for line in lines.lines() { @@ -255,8 +276,7 @@ pub fn collect_reachable_objects() -> Result<(Vec<GitLog>, String), GitError> { .output() .expect("Error with git log"); if !logs.status.success() { - GitError::GitLog(String::from_utf8_lossy(&logs.stderr).to_string()); - //return GitError::GitLog(String::from_utf8_lossy(&logs.stderr).to_string()); + return Err(GitError::GitLog(String::from_utf8_lossy(&logs.stderr).to_string())); } let lines = String::from_utf8_lossy(&logs.stdout); let mut git_log = GitLog::default(); @@ -309,9 +329,3 @@ pub fn cat_files(blobs: String) -> Result<String, GitError> { let objects = String::from_utf8_lossy(&output.stdout); Ok(objects.to_string()) } - - - -pub fn hello() { - println!("hello from git"); -} |
