fix(main): fixed commit in quick

Fixed problem introduced by error handling.

This does not fix fast or fix lack of message input.

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-07-02 09:25:00 +02:00
parent c6db4d5a3b
commit df08a1ca2f
Signed by: cafkafk
GPG key ID: CDDC792F655251ED
4 changed files with 15 additions and 7 deletions

View file

@ -6,7 +6,7 @@
- [ ] Version pinning
- [ ] libgit2 (maybe)
* 0.1.0
- [ ] No functionality regressions
- [-] No functionality regressions
- [ ] Repo Flags Finished
- [ ] Category Flags Finished
- [ ] Optional Fields

View file

@ -188,6 +188,9 @@ impl GitRepo {
}
}
/// Tries to commit changes in the repository.
///
/// BUG does not work with output should use status() instead so it opens
/// the editor
#[allow(dead_code)]
fn commit(&self) -> bool {
if self.flags.contains(&RepoFlags::Push) {
@ -196,6 +199,7 @@ impl GitRepo {
.arg("commit")
.output()
.unwrap_or_else(|_| panic!("git repo failed to commit: {:?}", &self,));
println!("{output:?}");
output.status.success()
} else {
info!("{} has clone set to false, not cloned", &self.name);
@ -203,7 +207,7 @@ impl GitRepo {
}
}
/// Tries to commit changes with a message argument.
fn commit_with_msg(&self, msg: &String) -> bool {
fn commit_with_msg(&self, msg: &str) -> bool {
if self.flags.contains(&RepoFlags::Push) {
let output = Command::new("git")
.current_dir(format!("{}{}", &self.path, &self.name))
@ -427,7 +431,7 @@ impl Config {
self.on_all_spinner("commit", |repo| repo.commit());
}
/// Tries to commit all repositories with msg, skips if fail.
pub fn commit_all_msg(&self, msg: &String) {
pub fn commit_all_msg(&self, msg: &str) {
debug!("exectuting clone_all");
self.on_all_spinner("commit", |repo| repo.commit_with_msg(msg));
}
@ -435,7 +439,7 @@ impl Config {
/// repositories, skips if fail.
///
/// FIXME currently msg isn't used
pub fn quick(&self, msg: &String) {
pub fn quick(&self, msg: &'static str) {
debug!("exectuting quick");
let series: Vec<SeriesItem> = vec![
SeriesItem {
@ -448,7 +452,7 @@ impl Config {
},
SeriesItem {
operation: "commit",
closure: Box::new(move |repo: &GitRepo| repo.commit()),
closure: Box::new(move |repo: &GitRepo| repo.commit_with_msg(msg)),
}, // FIXME doesn't take msg
SeriesItem {
operation: "push",
@ -461,7 +465,7 @@ impl Config {
/// repositories, skips if fail.
///
/// FIXME currently msg isn't used
pub fn fast(&self, msg: &String) {
pub fn fast(&self, msg: &str) {
debug!("exectuting fast");
let series: Vec<SeriesItem> = vec![
SeriesItem {

View file

@ -43,6 +43,7 @@ mod utils;
use cli::{Args, Commands};
use git::Config;
use utils::strings::QUICK_COMMIT;
use clap::Parser;
@ -68,7 +69,7 @@ fn main() {
config.link_all();
}
Some(Commands::Quick { msg }) => {
config.quick(msg.as_ref().get_or_insert(&"gg: quick commit".to_string()));
config.quick(QUICK_COMMIT);
}
Some(Commands::Fast { msg }) => {
config.fast(msg.as_ref().get_or_insert(&"gg: fast commit".to_string()));

View file

@ -45,3 +45,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
";
/// Contains the message for quick commit subcommit
pub const QUICK_COMMIT: &'static str = "git: quick commit";