commit 5059619f5482624fb6bc553161ad5791631b7e40 parent 589d716fce6586d6db4d3bd26a73dbd6501f7e81 Author: Natasha Kerensikova <natgh@instinctive.eu> Date: Sat, 21 Sep 2024 10:19:04 +0000 Editor exit code is checked by edit command Diffstat:
M | spec/action_spec.sh | | | 15 | +++++++++++++++ |
M | src/pashage.sh | | | 9 | ++++++++- |
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/spec/action_spec.sh b/spec/action_spec.sh @@ -790,6 +790,21 @@ Describe 'Action Functions' The output should equal 'New password for subdir/new not saved.' The error should equal "$(result)" End + + It 'reports EDITOR exit code' + exit42() { mocklog editor "$@"; return 42; } + EDITOR=exit42 + result() { + %text:expand + #|$ mktemp -u ${SECURE_TMPDIR}/XXXXXX + #|$ scm_begin + #|$ editor ${SECURE_TMPDIR}/XXXXXX-subdir-new.txt + #|Editor "exit42" exited with code 42 + } + When run do_edit subdir/new + The status should equal 42 + The error should equal "$(result)" + End End Describe 'do_encrypt' diff --git a/src/pashage.sh b/src/pashage.sh @@ -551,7 +551,14 @@ do_edit() { fi fi - ${EDIT_CMD} "${TMPFILE}" + if ${EDIT_CMD} "${TMPFILE}"; then + : + else + CODE="$?" + printf 'Editor "%s" exited with code %s\n' \ + "${EDIT_CMD}" "${CODE}" >&2 + exit "${CODE}" + fi if ! [ -f "${TMPFILE}" ]; then printf '%s\n' "New password for ${NAME} not saved."