aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorBernhard Guillon <Bernhard.Guillon@begu.org>2025-09-18 16:17:07 +0200
committerBernhard Guillon <Bernhard.Guillon@begu.org>2025-09-18 16:17:07 +0200
commit52608100d24d2574b37d6a62cdadcdbbfe5fe51c (patch)
tree19ae6cea96d6b798589438dc276c5523b05d4114 /src/main.rs
parent6fc71960d6125d336132b1fe6ca0a5f89d4a0ed4 (diff)
downloadfuture-me-52608100d24d2574b37d6a62cdadcdbbfe5fe51c.tar.gz
future-me-52608100d24d2574b37d6a62cdadcdbbfe5fe51c.zip
future-me: make plans on how to port future-me.sh
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 91ab019..19c63a2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -245,6 +245,58 @@ fn show() {
// ;;
+fn create_new_bug() {
+ // 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
+ // we switch back to that as best as we can if anything went bad.
+ //
+ // get_last_ref (show-ref ref/notes/devtools/future-me)
+ // if empty
+ // call init future-me which creates a new tree
+ // with git read-tree --empty
+ // otherwise read the current tree with git read-tree future-me-hash
+ //
+ // let the user enter the bug report and creat the json string
+ // then
+ // create an git object with git hash-object -w --stdin
+ // collect the output as object hash
+ // create a file path string with dd/fffff
+ // update the index
+ // with git update-index --add --cacheinfo 100644 hash dd/fffff
+ // write a new tree object and collect the hash from the output
+ // git write-tree
+ // reset our changes to the staging area with
+ // git update-index --remove
+ // files_to_unstage=$(git update-index --refresh | cut -d ' ' -f 1 | cut -d ':' -f 1)
+ // git update-index --remove $files_to_unstage // TODO: check if we can just unstage the
+ // file as we know the path?
+ // If we are the first and there is no parent aka future-me ref was empty
+ // commit_id=$(echo 'future-me: created a new bug for you' | git commit-tree $tree_id)
+ // else add the parent
+ // commit_id=$(echo 'future-me: created a new bug for you' | git commit-tree $tree_id -p $add_parent)
+ // cool now update the ref
+ //
+ // git update-ref refs/notes/devtools/future-me $commit_id
+ //
+ // switch back to what ever was the working tree we got from get_current_tree
+ println!("hello new bug");
+}
+
+fn get_last_ref() -> Result<String, GitError> {
+ let cmd = Command::new("git")
+ .arg("show-ref")
+ .arg("refs/notes/devtools/future-me")
+ .output()
+ .expect("Error with git show-ref");
+ if !cmd.status.success() {
+ GitError::GitLog(String::from_utf8_lossy(&cmd.stderr).to_string());
+ }
+ let lines = String::from_utf8_lossy(&cmd.stdout);
+ // TODO: generate GitError
+ Ok(lines.split_whitespace().next().unwrap().to_string())
+}
+
fn get_current_tree() -> Result<String, GitError>{
let cmd = Command::new("git")
.arg("log")
@@ -323,6 +375,7 @@ fn main() {
Cmd::New => new_bug(),
Cmd::Check=> {
let tree = get_current_tree().unwrap();
+ println!("{}", get_last_ref().unwrap());
read_tree(&tree);
}
}