From ca322277b2628fb20b8a53d16836e683ce4b2520 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Mon, 10 Oct 2022 16:16:50 -0400 Subject: [PATCH] Supress git errors when the pass store is not a git repo --- gocrypt.bash | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gocrypt.bash b/gocrypt.bash index 37cf4ae..f0cacfa 100755 --- a/gocrypt.bash +++ b/gocrypt.bash @@ -32,6 +32,10 @@ gocrypt_die() { exit 1 } +_cmd_git() { + [ -d '.git' ] && cmd_git "$@" +} + gocrypt_derive_password() { local data="$1" local key="$2" @@ -94,10 +98,10 @@ gocrypt_init() { echo "# Gocrypt" >> .gitignore echo "gocrypt" >> .gitignore - cmd_git add .gitignore - $needs_passphrase && cmd_git add "$gocrypt_needs_passphrase_marker" - cmd_git add "$gocrypt_dir" - cmd_git commit -m "Initialized encrypted storage for gocrypt plugin" + _cmd_git add .gitignore + $needs_passphrase && _cmd_git add "$gocrypt_needs_passphrase_marker" + _cmd_git add "$gocrypt_dir" + _cmd_git commit -m "Initialized encrypted storage for gocrypt plugin" } gocrypt_open() { @@ -134,8 +138,8 @@ gocrypt_delegate() { # Delegate command to another `pass` instance that manages what is inside of the mountpoint PASSWORD_STORE_DIR="$PWD/$gocrypt_dec_dir" "$PROGRAM" "$@" # Commit if there has been changes due to this operation - cmd_git add "$gocrypt_dir" - cmd_git commit -m "Encrypted pass operation inside gocrypt" "$gocrypt_dir" || echo "No git commit created" + _cmd_git add "$gocrypt_dir" + _cmd_git commit -m "Encrypted pass operation inside gocrypt" "$gocrypt_dir" || echo "No git commit created" } gocrypt_crypt() {