From 8a0b5256492af3e38e4b5a436d951efa4ac665a2 Mon Sep 17 00:00:00 2001 From: Hubert Date: Thu, 15 Jul 2021 07:08:39 +0200 Subject: [PATCH] git init --- Cargo.toml | 1 + src/main.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 8b31c48..989a07e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,4 @@ env_logger = "0.8.4" serde = "1.0.126" futures = "0.3.15" tokio = {version = "0.2.25", features = ["time", "process", "io-util"]} +git2 = "0.13.20" diff --git a/src/main.rs b/src/main.rs index dcc3ff4..0265531 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,7 @@ use actix_web::client::PayloadError; use crate::reader::ToStream; use crate::writer::Writer; use crate::gitust::Gitust; +use git2::{Reference, Commit, Tree}; #[derive(Template)] #[template(path = "hello.html")] @@ -152,6 +153,22 @@ async fn git_main( let owner = Owner { name : owner}; let repo = Repository {name : reponame, owner}; let user = User { name : "Hubert".to_string()}; + let repogit = match git2::Repository::open(format!("{}/{}/{}.git", &gitust.repo_root_path, &repo.owner.name, &repo.name)) { + Ok(repo) => repo, + Err(e) => panic!("failed to open: {}", e), + }; + let head = match repogit.head() { + Ok(head) => head, + Err(e) => panic!("failed to get head: {}", e) + }; + let commit = match head.peel_to_commit() { + Ok(commit) => commit, + Err(e) => panic!("failed to get commit: {}", e) + }; + let tree = match commit.tree() { + Ok(tree) => tree, + Err(e) => panic!("failed to get tree: {}", e) + }; GitMainTemplate { repo, browse : browse, root : path, user_opt : Some(user)} } //#[get("/git/{owner}/{repo}.git/{path:.*}")]