walk through git tree
This commit is contained in:
parent
56a1de384a
commit
b51dfc1626
30
src/main.rs
30
src/main.rs
@ -1,3 +1,29 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use clap::Parser;
|
||||
use git2::Repository;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
struct Opt {
|
||||
#[arg(required = true)]
|
||||
repository: PathBuf,
|
||||
|
||||
#[arg(default_value = "HEAD")]
|
||||
branch: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let opt = Opt::parse();
|
||||
|
||||
let repo = Repository::open(opt.repository).unwrap();
|
||||
let commit = repo.revparse_single(&opt.branch).unwrap();
|
||||
let id = commit.short_id().unwrap();
|
||||
let id = id.as_str().unwrap();
|
||||
let commit = commit.into_commit().unwrap();
|
||||
let tree = commit.tree().unwrap();
|
||||
|
||||
tree.walk(git2::TreeWalkMode::PostOrder, move |dir, entry| {
|
||||
dbg!(&id, dir, entry.name().unwrap());
|
||||
0
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user