✨ revert
This commit is contained in:
parent
e284913941
commit
e85618df84
4 changed files with 36 additions and 28 deletions
15
src/args.rs
15
src/args.rs
|
@ -22,6 +22,11 @@ pub fn get_args() -> clap::ArgMatches {
|
|||
.arg(arg!(<BRANCH> "Branch name").required(true))
|
||||
.alias("n"),
|
||||
)
|
||||
.subcommand(
|
||||
command!("revert")
|
||||
.about("Revert n commits into the past")
|
||||
.arg(arg!(<N> "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")
|
||||
|
|
12
src/git.rs
12
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")
|
||||
|
|
14
src/main.rs
14
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")
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue