commit 0e3d904a4951d2b80b3b812273c9f212ce4ceac3
parent cff9dc19da11dfd808bde070c738a951e6f921bc
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Sat, 2 Nov 2024 10:58:49 +0000
Multi-entry single-line insert is corrected and tested
Diffstat:
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/spec/pashage_extra_spec.sh b/spec/pashage_extra_spec.sh
@@ -143,7 +143,6 @@ Describe 'Integrated Command Functions'
diff() { @diff "$@"; }
dirname() { @dirname "$@"; }
git() { @git "$@"; }
- head() { @head "$@"; }
mkdir() { @mkdir "$@"; }
mktemp() { @mktemp "$@"; }
mv() { @mv "$@"; }
@@ -581,6 +580,36 @@ Describe 'Integrated Command Functions'
MULTILINE=no
OVERWRITE=no
+ It 'inserts several new single-line entries'
+ stty() { false; }
+ Data
+ #|password-1
+ #|n
+ #|password-2
+ #|password-3
+ End
+ When call cmd_insert -e newdir/pass-1 subdir/file newdir/pass-2
+ The status should be success
+ The error should be blank
+ The output should equal 'Enter password for newdir/pass-1: An entry already exists for subdir/file. Overwrite it? [y/n]Enter password for newdir/pass-2: '
+ The contents of file "${PREFIX}/newdir/pass-1.age" \
+ should include "age:password-1"
+ The contents of file "${PREFIX}/newdir/pass-2.age" \
+ should include "age:password-2"
+ expected_log() { %text
+ #|Add given password for newdir/pass-2 to store.
+ #|
+ #| newdir/pass-2.age | 2 ++
+ #| 1 file changed, 2 insertions(+)
+ #|Add given password for newdir/pass-1 to store.
+ #|
+ #| newdir/pass-1.age | 2 ++
+ #| 1 file changed, 2 insertions(+)
+ setup_log
+ }
+ The result of function check_git_log should be successful
+ End
+
It 'inserts a new single-line entry on the second try'
stty() { :; }
Data
diff --git a/src/pashage.sh b/src/pashage.sh
@@ -793,7 +793,11 @@ do_insert() {
|| ! stty >/dev/null 2>&1
then
printf 'Enter password for %s: ' "$1"
- head -n 1 | do_encrypt "$1.age"
+ IFS= read -r LINE
+ do_encrypt "$1.age" <<-EOF
+ ${LINE}
+ EOF
+ unset LINE
else
while true; do