From e26be055fd1d939335c3f0334bb777ded6293ddf Mon Sep 17 00:00:00 2001 From: Bernhard Guillon Date: Mon, 22 Sep 2025 22:34:11 +0200 Subject: future-me: add reply command prototype --- src/git.rs | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src/git.rs') diff --git a/src/git.rs b/src/git.rs index b974375..6c4d188 100644 --- a/src/git.rs +++ b/src/git.rs @@ -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 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 { .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{ .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{ + 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, 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 { let objects = String::from_utf8_lossy(&output.stdout); Ok(objects.to_string()) } - - - -pub fn hello() { - println!("hello from git"); -} -- cgit v1.2.3