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/bin/main.rs | 14 +++++++++----- src/git.rs | 40 +++++++++++++++++++++++++++------------- 2 files changed, 36 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/bin/main.rs b/src/bin/main.rs index c4e1b1f..ad61872 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -28,11 +28,12 @@ struct BugReport { status: String, title: String, description: Vec, + parent: Option, tags: Option, version: String } -fn new_bug() -> String { +fn new_bug(parent: Option) -> String { let editor = var("EDITOR").unwrap(); let mut file_path = temp_dir(); // TODO: figgure out how to get .git dir in a save manner file_path.push("NEW_BUG_REPORT"); @@ -62,6 +63,7 @@ fn new_bug() -> String { title: header.to_owned(), description: description.to_owned(), status: "new".to_owned(), + parent: parent, tags: None, version: "v1".to_owned(), }; @@ -104,7 +106,7 @@ fn hash_to_path(hash: &str) -> String { format!("{}/{}", &hash[..2], &hash[2..]) } -fn create_new_bug() { +fn create_new_bug(parent: Option) { // first of all check if there is anything staged as we mess with the trees and staging area // use check_status for that // after that get the current tree get_current_tree and save it. We need to guarantee that @@ -148,7 +150,7 @@ fn create_new_bug() { Err(GitError::UnknownRef) => {create_new_tree(); None}, Err(_) => panic!("fixme"), }; - let bug_report = new_bug(); + let bug_report = new_bug(parent); let bug_object = create_object(bug_report.clone()).unwrap(); let path = hash_to_path(&bug_object); stage_object(&bug_object, &path); @@ -192,10 +194,12 @@ fn main() { show(); } Commands::New => { - create_new_bug(); + create_new_bug(None); } Commands::Reply { hash } => { - println!("Replying with: {}", hash); + let parent = short_to_long_hash(hash).unwrap(); + println!("Replying with: long: {}", parent); + create_new_bug(Some(parent)); } } } 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