🩹 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)) .arg(arg!(<BRANCH> "Branch name").required(true))
.alias("r"), .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( .subcommand(
command!() command!()
.name("push") .name("push")
@ -60,6 +65,7 @@ pub fn get_args() -> clap::ArgMatches {
command!() command!()
.name("status") .name("status")
.about("Show git status") .about("Show git status")
.alias("s")
.alias("stat") .alias("stat")
.alias("stats"), .alias("stats"),
) )
@ -83,11 +89,6 @@ pub fn get_args() -> clap::ArgMatches {
.about("Show git commit log") .about("Show git commit log")
.alias("l"), .alias("l"),
) )
.subcommand( .subcommand(command!().name("save").about("Create a WIP commit"))
command!()
.name("save")
.about("Create a WIP commit")
.alias("s"),
)
.get_matches() .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. /// Commit changes to the repository.
pub fn commit(all: bool, done: bool, forced: bool, msg: &str) { pub fn commit(all: bool, done: bool, forced: bool, msg: &str) {
// Work In Progress Save Commit // 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 // Laguage specific pre-commit hooks
for lang in get_languages() { 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 { if all {
Exec::cmd("git") Exec::cmd("git")
.arg("add") .arg("add")

View file

@ -126,7 +126,18 @@ fn main() {
let n: u64 = n.parse().unwrap(); let n: u64 = n.parse().unwrap();
revert_commits(n); 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") Exec::cmd("git")
.arg("branch") .arg("branch")
.popen() .popen()
@ -134,6 +145,7 @@ fn main() {
.wait() .wait()
.unwrap(); .unwrap();
} }
}
Some(("push", push_args)) => { Some(("push", push_args)) => {
let force = push_args.get_flag("force"); let force = push_args.get_flag("force");
push(force); push(force);
@ -145,6 +157,15 @@ fn main() {
let msg: Option<&String> = commit_args.get_one("message"); let msg: Option<&String> = commit_args.get_one("message");
let interactive = commit_args.get_flag("interactive"); 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() { if interactive || msg.is_none() {
let gitmoji = select_gitmoji(); let gitmoji = select_gitmoji();
let title = inquire::prompt_text("Commit Title").unwrap(); let title = inquire::prompt_text("Commit Title").unwrap();