feat(git): made repo flags optional

This finalizes the roadmap item of making certain fields optional.

Very nice!

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-07-02 11:37:23 +02:00
parent 1c6793f8e4
commit ee8e546b22
Signed by: cafkafk
GPG key ID: CDDC792F655251ED
6 changed files with 61 additions and 23 deletions

View file

@ -2,7 +2,7 @@
name = "gg"
version = "0.0.6"
edition = "2021"
authors = ["Christina Sørensen <christina@cafkafk.com>"]
authors = ["Christina Sørensen"]
repository = "https://github.com/cafkafk/gg"
license = "GPL-3.0-only"

View file

@ -5,11 +5,11 @@
- [ ] Generic repositories
- [ ] Version pinning
- [ ] libgit2 (maybe)
* 0.1.0 [40%] [2/5]
* 0.1.0 [60%] [3/5]
- [X] No functionality regressions
- [X] commit works in quick, fast
- [X] commit with edit works
- [X] Repo Flags Finished
- [ ] Category Flags Finished
- [-] Optional Fields
- [X] Optional Fields
- [ ] Subcommands

View file

@ -92,7 +92,8 @@ pub struct GitRepo {
pub name: String,
pub path: String,
pub url: String,
pub flags: Vec<RepoFlags>,
#[serde(skip_serializing_if = "Option::is_none")]
pub flags: Option<Vec<RepoFlags>>,
}
////////////////////////////////////
@ -157,7 +158,12 @@ impl Links {
impl GitRepo {
/// Clones the repository to its specified folder.
fn clone(&self) -> bool {
if self.flags.contains(&RepoFlags::Clone) {
if self
.flags
.as_ref()
.expect("failed to unwrap flags")
.contains(&RepoFlags::Clone)
{
// TODO: check if &self.name already exists in dir
let output = Command::new("git")
.current_dir(&self.path)
@ -176,6 +182,8 @@ impl GitRepo {
fn pull(&self) -> bool {
if self
.flags
.as_ref()
.expect("failed to unwrap flags")
.iter()
.any(|s| s == &RepoFlags::Pull || s == &RepoFlags::Fast)
{
@ -194,6 +202,8 @@ impl GitRepo {
fn add_all(&self) -> bool {
if self
.flags
.as_ref()
.expect("failed to unwrap flags")
.iter()
.any(|s| s == &RepoFlags::Add || s == &RepoFlags::Quick || s == &RepoFlags::Fast)
{
@ -220,6 +230,8 @@ impl GitRepo {
fn commit(&self) -> bool {
if self
.flags
.as_ref()
.expect("failed to unwrap flags")
.iter()
.any(|s| s == &RepoFlags::Commit || s == &RepoFlags::Quick || s == &RepoFlags::Fast)
{
@ -238,6 +250,8 @@ impl GitRepo {
fn commit_with_msg(&self, msg: &str) -> bool {
if self
.flags
.as_ref()
.expect("failed to unwrap flags")
.iter()
.any(|s| s == &RepoFlags::Commit || s == &RepoFlags::Quick || s == &RepoFlags::Fast)
{
@ -258,6 +272,8 @@ impl GitRepo {
fn push(&self) -> bool {
if self
.flags
.as_ref()
.expect("failed to unwrap flags")
.iter()
.any(|s| s == &RepoFlags::Push || s == &RepoFlags::Quick || s == &RepoFlags::Fast)
{

View file

@ -150,7 +150,7 @@ mod config {
name: "test repo".to_string(),
path: "/tmp".to_string(),
url: "https://github.com/cafkafk/gg".to_string(),
flags: vec![Clone, Push],
flags: Some(vec![Clone, Push]),
},
);
}

View file

@ -25,6 +25,17 @@ categories:
url: git@github.com:cafkafk/li.git
flags: [Clone, Push]
empty:
stuff:
flags: []
repos:
gg:
name: gg
path: /home/ces/.dots/
url: git@github.com:cafkafk/gg.git
li:
name: li
path: /home/ces/org/src/git/
url: git@github.com:cafkafk/li.git
links:
- name: gg
rx: /home/ces/.config/gg

View file

@ -1,5 +1,31 @@
categories:
empty: {}
utils:
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
stuff:
flags: []
repos:
li:
name: li
path: /home/ces/org/src/git/
url: git@github.com:cafkafk/li.git
gg:
name: gg
path: /home/ces/.dots/
url: git@github.com:cafkafk/gg.git
config:
flags: []
repos:
@ -17,22 +43,7 @@ categories:
flags:
- Clone
- Push
utils:
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
empty: {}
links:
- name: gg
rx: /home/ces/.config/gg