aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bin/main.rs14
-rw-r--r--src/git.rs40
2 files changed, 36 insertions, 18 deletions
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<String>,
+ parent: Option<String>,
tags: Option<String>,
version: String
}
-fn new_bug() -> String {
+fn new_bug(parent: Option<String>) -> 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<String>) {
// 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<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");
-}