diff --git a/src/args.rs b/src/args.rs index 679a201..67ad9ba 100644 --- a/src/args.rs +++ b/src/args.rs @@ -22,6 +22,11 @@ pub fn get_args() -> clap::ArgMatches { .arg(arg!( "Branch name").required(true)) .alias("n"), ) + .subcommand( + command!("revert") + .about("Revert n commits into the past") + .arg(arg!( "Number of commits")), + ) .subcommand( command!("commit") .about("Commit current changes") @@ -49,8 +54,7 @@ pub fn get_args() -> clap::ArgMatches { command!() .name("push") .about("Push to a remote") - .arg(arg!(-f --force "Force push")) - .alias("p"), + .arg(arg!(-f --force "Force push")), ) .subcommand( command!() @@ -72,12 +76,7 @@ pub fn get_args() -> clap::ArgMatches { .about("Run git fetch --prune") .alias("f"), ) - .subcommand( - command!() - .name("pull") - .about("Run git pull --prune") - .alias("p"), - ) + .subcommand(command!().name("pull").about("Run git pull --prune")) .subcommand( command!() .name("log") diff --git a/src/git.rs b/src/git.rs index 1bbb80e..c0ca396 100644 --- a/src/git.rs +++ b/src/git.rs @@ -193,6 +193,8 @@ pub fn commit(all: bool, done: bool, forced: bool, msg: &str) { } } + // TODO : Add all files in git selection if they got changed + // Laguage specific pre-commit hooks for lang in get_languages() { match lang.as_str() { @@ -223,6 +225,16 @@ pub fn commit(all: bool, done: bool, forced: bool, msg: &str) { .unwrap(); } +pub fn revert_commits(n: u64) { + Exec::cmd("git") + .arg("reset") + .arg(&format!("HEAD~{n}")) + .popen() + .unwrap() + .wait() + .unwrap(); +} + /// Fetch remote state pub fn fetch() { Exec::cmd("git") diff --git a/src/main.rs b/src/main.rs index 1ea1414..809b849 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ -use git::{bootstrap, commit, create_new_branch, delete_branch, fetch, git_add, pull, push}; +use git::{ + bootstrap, commit, create_new_branch, delete_branch, fetch, git_add, pull, push, revert_commits, +}; use gitmoji::{CommitMessage, select_gitmoji}; use std::io::Read; use subprocess::{Exec, Redirection}; @@ -81,8 +83,9 @@ pub fn show_todos(count_only: bool) { 6..=9 => "🙂", 10..=19 => "😅", 20..=49 => "🔥", - 50..100 => "🤯", - 100.. => "💀", + 50..=99 => "🤯", + 100..=149 => "💀", + 150.. => "⚰️", _ => "💀", }; @@ -118,6 +121,11 @@ fn main() { let branch: &String = rm_args.get_one("BRANCH").unwrap(); delete_branch(branch); } + Some(("revert", rev_args)) => { + let n: &String = rev_args.get_one("N").unwrap(); + let n: u64 = n.parse().unwrap(); + revert_commits(n); + } Some(("branch", _)) => { Exec::cmd("git") .arg("branch") diff --git a/src/precommit.rs b/src/precommit.rs index 5941b6e..31b04f3 100644 --- a/src/precommit.rs +++ b/src/precommit.rs @@ -1,22 +1,11 @@ -use crate::{git::git_add, read_stdout}; use subprocess::Exec; pub fn rust_pre_commit() { println!("Running cargo fmt"); - let e = Exec::cmd("cargo").arg("fmt").arg("--verbose"); - let out = read_stdout(e); - - for line in out.lines() { - println!("line {line}"); - if line.starts_with("rustfmt") { - let mut split: Vec<_> = line.split_whitespace().collect(); - split.reverse(); - split.pop(); - split.pop(); - split.pop(); - split.reverse(); - let file = split.join(" "); - git_add(&file); - } - } + Exec::cmd("cargo") + .arg("fmt") + .popen() + .unwrap() + .wait() + .unwrap(); }