Skip to content

Commit 8207c28

Browse files
committed
Add fetch git last commit info example
1 parent 51c377e commit 8207c28

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
use std::process::Command;
1+
#[derive(serde::Deserialize, Debug)]
2+
struct CommitInfo {
3+
hash: String,
4+
date: String,
5+
message: String
6+
}
27

3-
fn main() {
4-
let mut cmd = Command::new("df");
5-
cmd.arg("-h");
6-
match cmd.output() {
7-
Ok(output) => unsafe {
8-
println!("{}", String::from_utf8_unchecked(output.stdout));
9-
},
10-
Err(e) => println!("{}", e),
11-
}
8+
fn main() -> Result<(), Box<dyn std::error::Error>> {
9+
let cmd_res = std::process::Command::new("git")
10+
.arg("log")
11+
.arg("-1")
12+
.arg("--pretty=format:hash=\"%h\"\ndate=\"%ad\"\nmessage=\"%s\"")
13+
.env("DATABASE_URL", "null")
14+
.output()?;
15+
let last_commit_str = String::from_utf8(cmd_res.stdout)?;
16+
let last_commit: CommitInfo = toml::de::from_str(&last_commit_str)?;
17+
dbg!(last_commit);
18+
Ok(())
1219
}

examples/double_linked_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct List<T> {
2323
tail: Node<T>,
2424
}
2525

26-
// impl List<T> {
26+
// impl<T> List<T> {
2727
// fn new(dummy_val: T) -> Self {
2828
// let mut head = Node::new(dummy_val);
2929
// let mut tail = Node::new(dummy_val);
@@ -37,5 +37,5 @@ struct List<T> {
3737
// }
3838

3939
fn main() {
40-
let mut head: Node<i32> = Node::new(-1);
40+
let _head: Node<i32> = Node::new(-1);
4141
}

examples/gzip.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,4 @@ fn main() {
2222
let decode_str = decode_gzip_bytes_to_str(gzip_bytes);
2323
println!("{}", decode_str);
2424
assert_eq!(decode_str.as_str(), s);
25-
26-
use std::collections::BinaryHeap;
2725
}

examples/rust_decimal_lib_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bigdecimal::BigDecimal;
22
use rust_decimal::Decimal;
33
// use rust_decimal::prelude::FromStr;
4-
use rust_decimal::prelude::ToPrimitive;
4+
55
use std::mem::size_of_val;
66
use std::str::FromStr;
77

0 commit comments

Comments
 (0)