[PATCH] Die when editing and the editor fails.

Damien Merenne dam at cosinux.org
Wed Mar 22 17:03:24 UTC 2023


This commit makes the pass edit command fail when the invoked
$EDITOR exit with a status different from EXIT_SUCCESS.
---
 src/password-store.sh     | 2 +-
 tests/t0200-edit-tests.sh | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 22e818f..4fdae0a 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -500,7 +500,7 @@ cmd_edit() {
 		$GPG -d -o "$tmp_file" "${GPG_OPTS[@]}" "$passfile" || exit 1
 		action="Edit"
 	fi
-	${EDITOR:-vi} "$tmp_file"
+	${EDITOR:-vi} "$tmp_file" || die "Editor canceled edit."
 	[[ -f $tmp_file ]] || die "New password not saved."
 	$GPG -d -o - "${GPG_OPTS[@]}" "$passfile" 2>/dev/null | diff - "$tmp_file" &>/dev/null && die "Password unchanged."
 	while ! $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" "$tmp_file"; do
diff --git a/tests/t0200-edit-tests.sh b/tests/t0200-edit-tests.sh
index d8d7b64..b32c782 100755
--- a/tests/t0200-edit-tests.sh
+++ b/tests/t0200-edit-tests.sh
@@ -14,4 +14,11 @@ test_expect_success 'Test "edit" command' '
 	[[ $("$PASS" show cred1) == "$FAKE_EDITOR_PASSWORD" ]]
 '
 
+test_expect_success 'Test "edit" command when editor fails' '
+	"$PASS" init $KEY1 &&
+	"$PASS" generate cred1 90 &&
+	export EDITOR="false" &&
+	! "$PASS" edit cred1
+'
+
 test_done
-- 
2.34.1



More information about the Password-Store mailing list