feat(git): add Commit, Add flags
This also fixes behaviour of all flags. Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
d2353fe435
commit
e6f597e08b
3 changed files with 30 additions and 26 deletions
|
@ -9,7 +9,7 @@
|
||||||
- [X] No functionality regressions
|
- [X] No functionality regressions
|
||||||
- [X] commit works in quick, fast
|
- [X] commit works in quick, fast
|
||||||
- [X] commit with edit works
|
- [X] commit with edit works
|
||||||
- [ ] Repo Flags Finished
|
- [-] Repo Flags Finished
|
||||||
- [ ] Category Flags Finished
|
- [ ] Category Flags Finished
|
||||||
- [ ] Optional Fields
|
- [ ] Optional Fields
|
||||||
- [ ] Subcommands
|
- [ ] Subcommands
|
||||||
|
|
14
src/git.rs
14
src/git.rs
|
@ -28,12 +28,16 @@ use std::{fs, process::Command};
|
||||||
/// An enum containing flags that change behaviour of repos and categories
|
/// An enum containing flags that change behaviour of repos and categories
|
||||||
#[derive(PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, Debug)]
|
#[derive(PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, Debug)]
|
||||||
pub enum RepoFlags {
|
pub enum RepoFlags {
|
||||||
/// If push is set, the repository should respond to the push subcommand
|
|
||||||
Push,
|
|
||||||
/// If clone is set, the repository should respond to the clone subcommand
|
/// If clone is set, the repository should respond to the clone subcommand
|
||||||
Clone,
|
Clone,
|
||||||
/// If pull is set, the repository should respond to the pull subcommand
|
/// If pull is set, the repository should respond to the pull subcommand
|
||||||
Pull,
|
Pull,
|
||||||
|
/// If add is set, the repository should respond to the add subcommand
|
||||||
|
Add,
|
||||||
|
/// If commit is set, the repository should respond to the commit subcommand
|
||||||
|
Commit,
|
||||||
|
/// If push is set, the repository should respond to the push subcommand
|
||||||
|
Push,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the config.toml file.
|
/// Represents the config.toml file.
|
||||||
|
@ -174,7 +178,7 @@ impl GitRepo {
|
||||||
}
|
}
|
||||||
/// Adds all files in the repository.
|
/// Adds all files in the repository.
|
||||||
fn add_all(&self) -> bool {
|
fn add_all(&self) -> bool {
|
||||||
if self.flags.contains(&RepoFlags::Push) {
|
if self.flags.contains(&RepoFlags::Add) {
|
||||||
let output = Command::new("git")
|
let output = Command::new("git")
|
||||||
.current_dir(format!("{}{}", &self.path, &self.name))
|
.current_dir(format!("{}{}", &self.path, &self.name))
|
||||||
.arg("add")
|
.arg("add")
|
||||||
|
@ -196,7 +200,7 @@ impl GitRepo {
|
||||||
/// easy
|
/// easy
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn commit(&self) -> bool {
|
fn commit(&self) -> bool {
|
||||||
if self.flags.contains(&RepoFlags::Push) {
|
if self.flags.contains(&RepoFlags::Commit) {
|
||||||
let status = Command::new("git")
|
let status = Command::new("git")
|
||||||
.current_dir(format!("{}{}", &self.path, &self.name))
|
.current_dir(format!("{}{}", &self.path, &self.name))
|
||||||
.arg("commit")
|
.arg("commit")
|
||||||
|
@ -210,7 +214,7 @@ impl GitRepo {
|
||||||
}
|
}
|
||||||
/// Tries to commit changes with a message argument.
|
/// Tries to commit changes with a message argument.
|
||||||
fn commit_with_msg(&self, msg: &str) -> bool {
|
fn commit_with_msg(&self, msg: &str) -> bool {
|
||||||
if self.flags.contains(&RepoFlags::Push) {
|
if self.flags.contains(&RepoFlags::Commit) {
|
||||||
let output = Command::new("git")
|
let output = Command::new("git")
|
||||||
.current_dir(format!("{}{}", &self.path, &self.name))
|
.current_dir(format!("{}{}", &self.path, &self.name))
|
||||||
.arg("commit")
|
.arg("commit")
|
||||||
|
|
|
@ -1,24 +1,14 @@
|
||||||
categories:
|
categories:
|
||||||
utils:
|
|
||||||
flags: []
|
|
||||||
repos:
|
|
||||||
li:
|
|
||||||
name: li
|
|
||||||
path: /home/ces/org/src/git/
|
|
||||||
url: git@github.com:cafkafk/li.git
|
|
||||||
flags:
|
|
||||||
- Clone
|
|
||||||
- Push
|
|
||||||
gg:
|
|
||||||
name: gg
|
|
||||||
path: /home/ces/.dots/
|
|
||||||
url: git@github.com:cafkafk/gg.git
|
|
||||||
flags:
|
|
||||||
- Clone
|
|
||||||
- Push
|
|
||||||
config:
|
config:
|
||||||
flags: []
|
flags: []
|
||||||
repos:
|
repos:
|
||||||
|
starship:
|
||||||
|
name: starship
|
||||||
|
path: /home/ces/org/src/git/
|
||||||
|
url: https://github.com/starship/starship.git
|
||||||
|
flags:
|
||||||
|
- Clone
|
||||||
|
- Push
|
||||||
qmk_firmware:
|
qmk_firmware:
|
||||||
name: qmk_firmware
|
name: qmk_firmware
|
||||||
path: /home/ces/org/src/git/
|
path: /home/ces/org/src/git/
|
||||||
|
@ -26,10 +16,20 @@ categories:
|
||||||
flags:
|
flags:
|
||||||
- Clone
|
- Clone
|
||||||
- Push
|
- Push
|
||||||
starship:
|
utils:
|
||||||
name: starship
|
flags: []
|
||||||
|
repos:
|
||||||
|
gg:
|
||||||
|
name: gg
|
||||||
|
path: /home/ces/.dots/
|
||||||
|
url: git@github.com:cafkafk/gg.git
|
||||||
|
flags:
|
||||||
|
- Clone
|
||||||
|
- Push
|
||||||
|
li:
|
||||||
|
name: li
|
||||||
path: /home/ces/org/src/git/
|
path: /home/ces/org/src/git/
|
||||||
url: https://github.com/starship/starship.git
|
url: git@github.com:cafkafk/li.git
|
||||||
flags:
|
flags:
|
||||||
- Clone
|
- Clone
|
||||||
- Push
|
- Push
|
||||||
|
|
Loading…
Reference in a new issue