summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Gerace <nickagerace@gmail.com>2022-02-11 22:12:04 -0500
committerNick Gerace <nickagerace@gmail.com>2022-02-11 22:26:53 -0500
commit3b2c1071ec111f6367786f54daa41d20fe46c68e (patch)
tree6b1d555768023e0330fb1b7ab60dd1190f47ab06
parenta87606983071f83c8cc863f886363eb796a4576b (diff)
downloadgfold-3b2c1071ec111f6367786f54daa41d20fe46c68e.zip
Fix shorthand error if origin not found
- Fix shorthand reference resolution error if origin is not found - Update misc deps - Standardize logging on installer and uninstaller Signed-off-by: Nick Gerace <nickagerace@gmail.com>
-rw-r--r--Cargo.lock20
-rwxr-xr-xscripts/install.sh30
-rwxr-xr-xscripts/uninstall.sh22
-rw-r--r--src/report.rs28
4 files changed, 66 insertions, 34 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ab30a99..a6bf69d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -50,9 +50,9 @@ dependencies = [
[[package]]
name = "autocfg"
-version = "1.0.1"
+version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
+checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
@@ -98,9 +98,9 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
-version = "0.9.6"
+version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "97242a70df9b89a65d0b6df3c4bf5b9ce03c5b7309019777fbde37e7537f8762"
+checksum = "c00d6d2ea26e8b151d99093005cb442fb9a37aeaca582a03ec70946f49ab5ed9"
dependencies = [
"cfg-if",
"crossbeam-utils",
@@ -111,9 +111,9 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
-version = "0.8.6"
+version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120"
+checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6"
dependencies = [
"cfg-if",
"lazy_static",
@@ -265,9 +265,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.114"
+version = "0.2.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b0005d08a8f7b65fb8073cb697aa0b12b631ed251ce73d862ce50eeb52ce3b50"
+checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c"
[[package]]
name = "libgit2-sys"
@@ -516,9 +516,9 @@ dependencies = [
[[package]]
name = "unicode-segmentation"
-version = "1.8.0"
+version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
+checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
[[package]]
name = "unicode-xid"
diff --git a/scripts/install.sh b/scripts/install.sh
index be0bc7c..56de771 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -1,11 +1,25 @@
#!/usr/bin/env bash
set -e
+function log {
+ if [ ! "$1" ] || [ "$1" == "" ]; then
+ die "internal error: log message empty: please file an issue: https://github.com/nickgerace/gfold/issues/new"
+ fi
+ echo "[gfold-installer] $1"
+}
+
+function die {
+ if [ ! "$1" ] || [ "$1" == "" ]; then
+ die "internal error: error message empty: please file an issue: https://github.com/nickgerace/gfold/issues/new"
+ fi
+ log "error: $1"
+ exit 1
+}
+
function check-dependencies {
for BINARY in "jq" "wget" "curl"; do
if ! [ "$(command -v ${BINARY})" ]; then
- echo "[install-gfold] 🚫 \"$BINARY\" must be installed and in PATH"
- exit 1
+ die "\"$BINARY\" must be installed and in PATH"
fi
done
}
@@ -17,9 +31,7 @@ function perform-install {
elif [ "$(uname -s)" = "Darwin" ] && [ "$(uname -m)" = "x86_64" ]; then
INSTALL_OS="darwin"
else
- echo "[install-gfold] 🚫 must execute on Linux or Darwin x86_64 host"
- echo "[install-gfold] 🚫 for more installation methods: https://github.com/nickgerace/gfold"
- exit 1
+ die "must execute on Linux or Darwin x86_64 host (for more installation methods, refer to the docs: https://github.com/nickgerace/gfold)"
fi
LATEST=$(curl -s https://api.github.com/repos/nickgerace/gfold/releases/latest | jq -r ".tag_name")
@@ -34,12 +46,12 @@ function perform-install {
fi
mv /tmp/gfold /usr/local/bin/gfold
- echo "[install-gfold] ✅ gfold has been installed to /usr/local/bin/gfold"
if [ $INSTALL_OS = "linux-gnu" ]; then
- echo "[install-gfold] ⚠️ assuming glibc (GNU) and not another libc (e.g. musl-libc)"
- echo "[install-gfold] ⚠️ if using another libc, you may need to choose another installation method"
- echo "[install-gfold] ⚠️ for more information: https://github.com/nickgerace/gfold"
+ log "assuming glibc (GNU) and not another libc (e.g. musl-libc)"
+ log "if using another libc, you may need to choose another installation method"
+ log "for more information, refer to the docs: https://github.com/nickgerace/gfold"
fi
+ log "gfold has been installed to /usr/local/bin/gfold"
}
check-dependencies
diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh
index a9e7fc4..f14a12d 100755
--- a/scripts/uninstall.sh
+++ b/scripts/uninstall.sh
@@ -1,18 +1,32 @@
#!/usr/bin/env bash
set -e
+function log {
+ if [ ! "$1" ] || [ "$1" == "" ]; then
+ die "internal error: log message empty: please file an issue: https://github.com/nickgerace/gfold/issues/new"
+ fi
+ echo "[gfold-uninstaller] $1"
+}
+
+function die {
+ if [ ! "$1" ] || [ "$1" == "" ]; then
+ die "internal error: error message empty: please file an issue: https://github.com/nickgerace/gfold/issues/new"
+ fi
+ log "error: $1"
+ exit 1
+}
+
function perform-uninstall {
for FILE in "/tmp/gfold" "/usr/local/bin/gfold"; do
if [ -f "$FILE" ]; then
rm "$FILE"
- echo "[uninstall-gfold] ✅ deleted $FILE"
+ log "deleted $FILE"
fi
done
- echo "[uninstall-gfold] ✅ uninstallation/cleanup has completed successfully"
+ log "uninstallation and cleanup has completed successfully"
if [ -f $HOME/.config/gfold/gfold.json ]; then
- echo "[uninstall-gfold] ⚠️ you may want to delete or backup the config file"
- echo "[uninstall-gfold] ⚠️ config file path: $HOME/.config/gfold/gfold.json"
+ log "you may want to delete or backup the config file: $HOME/.config/gfold/gfold.json"
fi
}
diff --git a/src/report.rs b/src/report.rs
index 6f10008..18ee8d0 100644
--- a/src/report.rs
+++ b/src/report.rs
@@ -10,7 +10,7 @@ use std::fs::DirEntry;
use std::path::{Path, PathBuf};
use std::{fs, io};
-// Use a BTreeMap over a HashMap for sorted keys.
+/// "Reports" uses a BTreeMap over a HashMap for sorted keys.
pub type Reports = BTreeMap<Option<String>, Vec<Report>>;
#[derive(Clone, Debug)]
@@ -19,11 +19,12 @@ pub struct Report {
pub branch: String,
pub status: Status,
- // Fields that can report NONE with impeding execution.
+ /// Parent can report "NONE" without impeding execution.
pub parent: Option<String>,
+ /// URL can report "NONE" without impeding execution.
pub url: Option<String>,
- // Optional field that's only used in DisplayMode::Standard.
+ /// Optional field that's only used in DisplayMode::Standard.
pub email: Option<String>,
}
@@ -111,9 +112,9 @@ fn recursive_target_gen(path: &Path) -> io::Result<Vec<PathBuf>> {
Ok(results)
}
-// Ensure the entry is a directory and is not hidden. Then, check if a Git sub directory exists,
-// which will indicate if the entry is a repository. Finally, generate targets based on that
-// repository.
+/// Ensure the entry is a directory and is not hidden. Then, check if a Git sub directory exists,
+/// which will indicate if the entry is a repository. Finally, generate targets based on that
+/// repository.
fn process_entry(entry: &DirEntry) -> Target {
match entry.file_type()?.is_dir()
&& !entry
@@ -185,8 +186,13 @@ fn is_unpushed(repo: &Repository, head: &Reference) -> Result<bool> {
let local_head = head.peel_to_commit()?;
let remote = format!(
"origin/{}",
- head.shorthand()
- .ok_or(Error::GitReferenceShorthandInvalid)?
+ match head.shorthand() {
+ Some(v) => v,
+ None => {
+ trace!("assuming unpushed; could not determine shorthand for head");
+ return Ok(true);
+ }
+ }
);
let remote_head = repo
.resolve_reference_from_short_name(&remote)?
@@ -196,9 +202,9 @@ fn is_unpushed(repo: &Repository, head: &Reference) -> Result<bool> {
)
}
-// Find the "user.email" value in the local or global Git config. The "config" method for a
-// "git2::Repository" object will look for a local config first and fallback to global, as needed.
-// Absorb and log any and all errors as the email field is non-critical to our final results.
+/// Find the "user.email" value in the local or global Git config. The "config" method for a
+/// "git2::Repository" object will look for a local config first and fallback to global, as needed.
+/// Absorb and log any and all errors as the email field is non-critical to our final results.
fn get_email(repository: &Repository) -> Option<String> {
let config = match repository.config() {
Ok(v) => v,