🩹 staged files + branch checkout
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
e85618df84
commit
193036fab7
3 changed files with 50 additions and 15 deletions
15
src/args.rs
15
src/args.rs
|
@ -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()
|
||||
}
|
||||
|
|
15
src/git.rs
15
src/git.rs
|
@ -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")
|
||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue