Brijesh's Git Server — gitcc @ e842b23b5d9b80521bf8425c845deb83efb13d9f

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
 31
 32
 33
 34
 35
 36
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 {
            let commit_type: String = get_commit_type();
            let commit_message: String = get_commit_message();

            confirm_and_stage_all();
            make_commit(commit_type, commit_message);

            confirm_and_push_to_remote();
        }
    } else {
        println!("Not a git repository");
    }
}