summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md6
-rw-r--r--Cargo.lock24
-rw-r--r--src/driver.rs4
-rw-r--r--src/util.rs61
4 files changed, 56 insertions, 39 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f6da8fa..cbbc926 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,10 +11,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## Added
- `gfold --version` to issue template
+- Unpush functionality (again)
+
+## Changed
+
+- Unpush function to only return boolean
## Removed
- Contributing section from README to reduce requirements
+- Empty results message since it was potentially misleading
## [0.8.1] - 2020-12-01
diff --git a/Cargo.lock b/Cargo.lock
index 22d45c2..8879007 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -90,9 +90,9 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "cc"
-version = "1.0.65"
+version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "95752358c8f7552394baf48cd82695b345628ad3f170d607de3ca03b8dacca15"
+checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
dependencies = [
"jobserver",
]
@@ -315,9 +315,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.80"
+version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
+checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
[[package]]
name = "libgit2-sys"
@@ -394,9 +394,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
[[package]]
name = "openssl-sys"
-version = "0.9.58"
+version = "0.9.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de"
+checksum = "de52d8eabd217311538a39bba130d7dea1f1e118010fee7a033d966845e7d5fe"
dependencies = [
"autocfg",
"cc",
@@ -537,9 +537,9 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "serde"
-version = "1.0.117"
+version = "1.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a"
+checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
[[package]]
name = "strsim"
@@ -573,9 +573,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "1.0.53"
+version = "1.0.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8833e20724c24de12bbaba5ad230ea61c3eafb05b881c7c9d3cfe8638b187e68"
+checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44"
dependencies = [
"proc-macro2",
"quote",
@@ -685,9 +685,9 @@ dependencies = [
[[package]]
name = "vcpkg"
-version = "0.2.10"
+version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c"
+checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb"
[[package]]
name = "vec_map"
diff --git a/src/driver.rs b/src/driver.rs
index 48578ac..4040b25 100644
--- a/src/driver.rs
+++ b/src/driver.rs
@@ -52,9 +52,7 @@ impl Results {
Ordering::Equal => {
self.0[0].table.printstd();
}
- Ordering::Less => {
- println!("There are no results to display.");
- }
+ _ => {}
};
}
diff --git a/src/util.rs b/src/util.rs
index f27ee74..f6ea66e 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -9,7 +9,6 @@ use crate::driver;
use std::path::{Path, PathBuf};
-use eyre::Result;
use log::debug;
#[derive(Debug)]
@@ -18,6 +17,7 @@ enum Condition {
Clean,
Error,
Unclean,
+ Unpushed,
}
pub fn create_table_from_paths(
@@ -72,13 +72,16 @@ pub fn create_table_from_paths(
};
debug!("[+] name: {:#?}", name);
- // FIXME: add back function after being fixed.
- debug!("[+] unpushed: {:#?}", is_unpushed(&repo_obj, &head).ok()?);
-
// FIXME: test using the "is_bare()" method for a repository object.
let mut opts = git2::StatusOptions::new();
let condition = match repo_obj.statuses(Some(&mut opts)) {
- Ok(statuses) if statuses.is_empty() => Condition::Clean,
+ Ok(statuses) if statuses.is_empty() => {
+ if is_unpushed(&repo_obj, &head) {
+ Condition::Unpushed
+ } else {
+ Condition::Clean
+ }
+ }
Ok(_) => Condition::Unclean,
Err(error)
if error.code() == git2::ErrorCode::BareRepo
@@ -104,6 +107,12 @@ pub fn create_table_from_paths(
Condition::Unclean => {
table.add_row(row![Flb->name, Fyl->"unclean", Fl->branch, Fl->url])
}
+ Condition::Unpushed if *no_color => {
+ table.add_row(row![Fl->name, Fl->"unpushed", Fl->branch, Fl->url])
+ }
+ Condition::Unpushed => {
+ table.add_row(row![Flb->name, Fcl->"unpushed", Fl->branch, Fl->url])
+ }
_ if *no_color => table.add_row(row![Fl->name, Fl->"error", Fl->branch, Fl->url]),
_ => table.add_row(row![Flb->name, Frl->"error", Fl->branch, Fl->url]),
};
@@ -120,27 +129,31 @@ pub fn create_table_from_paths(
}
}
-// FIXME: this function does not currently work because "clean", non-main branches can be considered "unpushed".
-fn is_unpushed(repo: &git2::Repository, head: &git2::Reference) -> Result<bool> {
- let local = head.peel_to_commit()?;
+// FIXME: this function may not currently work because "clean", non-main branches can be considered "unpushed".
+fn is_unpushed(repo: &git2::Repository, head: &git2::Reference) -> bool {
+ let local = match head.peel_to_commit() {
+ Ok(local) => local,
+ Err(e) => {
+ debug!("[-] error: {}", e);
+ return false;
+ }
+ };
debug!("[+] local commit: {:#?}", local.id());
- let upstream = repo
- .resolve_reference_from_short_name("origin")?
- .peel_to_commit()?;
+ let upstream = match repo.resolve_reference_from_short_name("origin") {
+ Ok(reference) => match reference.peel_to_commit() {
+ Ok(upstream) => upstream,
+ Err(e) => {
+ debug!("[-] error: {}", e);
+ return false;
+ }
+ },
+ Err(e) => {
+ debug!("[-] error: {}", e);
+ return false;
+ }
+ };
debug!("[+] origin commit: {:#?}", upstream.id());
- match repo.graph_ahead_behind(local.id(), upstream.id())? {
- ahead if ahead.0 > 0 => Ok(true),
- _ => Ok(false),
- }
-}
-
-/*
-Condition::Unpushed if *no_color => {
- table.add_row(row![Fl->name, Fl->"unpushed", Fl->branch, Fl->url])
-}
-Condition::Unpushed => {
- table.add_row(row![Flb->name, Fcl->"unpushed", Fl->branch, Fl->url])
+ matches!(repo.graph_ahead_behind(local.id(), upstream.id()), Ok(ahead) if ahead.0 > 0)
}
-*/