aboutsummaryrefslogtreecommitdiffstats
path: root/src/git.rs
diff options
context:
space:
mode:
authorBernhard Guillon <Bernhard.Guillon@begu.org>2025-09-22 22:34:11 +0200
committerBernhard Guillon <Bernhard.Guillon@begu.org>2025-09-22 22:34:11 +0200
commite26be055fd1d939335c3f0334bb777ded6293ddf (patch)
treef81510c62d668a2c6247a17c42907fa85f33828f /src/git.rs
parent6d19fca75510df17d6a14e35ac44845b8f43a695 (diff)
downloadfuture-me-main.tar.gz
future-me-main.zip
future-me: add reply command prototypeHEADmain
Diffstat (limited to 'src/git.rs')
-rw-r--r--src/git.rs40
1 files changed, 27 insertions, 13 deletions
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");
-}