🩹 staged files + branch checkout
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2025-02-17 14:04:54 +01:00
parent e85618df84
commit 193036fab7
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 50 additions and 15 deletions

View file

@ -49,7 +49,12 @@ pub fn get_args() -> clap::ArgMatches {
.arg(arg!(<BRANCH> "Branch name").required(true))
.alias("r"),
)
.subcommand(command!("branch").about("Show branches").alias("b"))
.subcommand(
command!("branch")
.about("Show branches or switch to one")
.alias("b")
.arg(arg!(<BRANCH> "Branch name").required(false)),
)
.subcommand(
command!()
.name("push")
@ -60,6 +65,7 @@ pub fn get_args() -> clap::ArgMatches {
command!()
.name("status")
.about("Show git status")
.alias("s")
.alias("stat")
.alias("stats"),
)
@ -83,11 +89,6 @@ pub fn get_args() -> clap::ArgMatches {
.about("Show git commit log")
.alias("l"),
)
.subcommand(
command!()
.name("save")
.about("Create a WIP commit")
.alias("s"),
)
.subcommand(command!().name("save").about("Create a WIP commit"))
.get_matches()
}

View file

@ -143,6 +143,15 @@ pub fn get_languages() -> Vec<String> {
}
}
pub fn git_staged() -> Vec<String> {
let files = read_stdout(Exec::cmd("git").arg("status").arg("--porcelain"));
files
.split("\n")
.map(|x| x.split_whitespace().nth(1).unwrap().to_string())
.collect()
}
/// Commit changes to the repository.
pub fn commit(all: bool, done: bool, forced: bool, msg: &str) {
// Work In Progress Save Commit
@ -193,7 +202,7 @@ pub fn commit(all: bool, done: bool, forced: bool, msg: &str) {
}
}
// TODO : Add all files in git selection if they got changed
let staged = git_staged();
// Laguage specific pre-commit hooks
for lang in get_languages() {
@ -205,6 +214,10 @@ pub fn commit(all: bool, done: bool, forced: bool, msg: &str) {
}
}
for file in staged {
git_add(&file);
}
if all {
Exec::cmd("git")
.arg("add")

View file

@ -126,7 +126,18 @@ fn main() {
let n: u64 = n.parse().unwrap();
revert_commits(n);
}
Some(("branch", _)) => {
Some(("branch", branch_args)) => {
let branch: Option<&String> = branch_args.get_one("BRANCH");
if let Some(branch) = branch {
Exec::cmd("git")
.arg("checkout")
.arg(branch)
.popen()
.unwrap()
.wait()
.unwrap();
} else {
Exec::cmd("git")
.arg("branch")
.popen()
@ -134,6 +145,7 @@ fn main() {
.wait()
.unwrap();
}
}
Some(("push", push_args)) => {
let force = push_args.get_flag("force");
push(force);
@ -145,6 +157,15 @@ fn main() {
let msg: Option<&String> = commit_args.get_one("message");
let interactive = commit_args.get_flag("interactive");
if !forced {
// Impossible commits
if no_commit_amount() > 0 {
println!("{}", "Unable to commit because of:".paint(Color::Red));
show_rg(NO_COMMIT_REGEX);
std::process::exit(1);
}
}
if interactive || msg.is_none() {
let gitmoji = select_gitmoji();
let title = inquire::prompt_text("Commit Title").unwrap();