Brijesh's Git Server — gitcc @ 6d5984e44c3caac3b4552b9f0b0db124a110bca9

failed attempt at automatic git workflow

src/main.rs (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
use git2::{Error, Object, Repository};
use std::env::current_dir;
use std::path::PathBuf;

mod git_actions;
mod inputs;
mod utils;

use git_actions::*;
// use inputs::*;
// use utils::*;

fn main() {
    let cwd: PathBuf = current_dir().unwrap();
    let is_repo: bool = Repository::discover(cwd.clone()).is_ok();

    if is_repo {
        let repo: Repository = Repository::open(cwd.clone()).unwrap();
        let rev_parse_single: Result<Object<'_>, Error> = repo.revparse_single("HEAD");

        if rev_parse_single.is_err() {
            println!("No commits yet");
            make_initial_commit();
        } else {
            print!("There are commits");
        }
    } else {
        println!("Not a git repository");
    }
}