Skip to content

Commit c1e0236

Browse files
committed
Improve interactivity and feedback for --upgrade
- prompt user to confirm upgrade unless --yes option is given - when prompting, explain what is about to happen and show current and future transcrypt versions - show message when upgrade is complete, not just silence - if user's gitattributes file is changed when the latest recommended settings are applied, tell the user about it and ask them to commit - fix a bug where the new recommended `merge=crypt` setting could be added to gitattributes files multiple times over multiple upgrades.
1 parent ea4aa35 commit c1e0236

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

tests/test_crypt.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function check_repo_is_clean {
163163
[ "${lines[0]}" = "$SECRET_CONTENT" ]
164164

165165
# Perform re-install
166-
run ../transcrypt --upgrade
166+
run ../transcrypt --upgrade --yes
167167
[ "$status" -eq 0 ]
168168

169169
run git config --get --local transcrypt.version

transcrypt

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,27 @@ uninstall_transcrypt() {
626626

627627
# uninstall and re-install transcrypt to upgrade scripts and update configuration
628628
upgrade_transcrypt() {
629+
CURRENT_VERSION=$(git config --get --local transcrypt.version 2>/dev/null)
630+
631+
if [[ $interactive ]]; then
632+
printf 'You are about to upgrade the transcrypt scripts in your repository.\n'
633+
printf 'Your configuration settings will not be changed.\n\n'
634+
printf ' Current version: %s\n' "$CURRENT_VERSION"
635+
printf 'Upgraded version: %s\n\n' "$VERSION"
636+
printf 'Proceed with upgrade? [y/N] '
637+
read -r answer
638+
printf '\n'
639+
640+
if [[ $answer =~ $YES_REGEX ]]; then
641+
# User confirmed, don't prompt again
642+
interactive=''
643+
else
644+
# User did not confirm, exit
645+
# Exit if user did not confirm
646+
die 1 'upgrade has been aborted'
647+
fi
648+
fi
649+
629650
# Keep current cipher and password
630651
cipher=$(git config --get --local transcrypt.cipher)
631652
password=$(git config --get --local transcrypt.password)
@@ -642,12 +663,21 @@ upgrade_transcrypt() {
642663
# Update .gitattributes for transcrypt'ed files to include "merge=crypt" config
643664
case $OSTYPE in
644665
darwin*)
645-
/usr/bin/sed -i '' 's/filter=crypt diff=crypt\(.*\)/filter=crypt diff=crypt merge=crypt\1/' "$GIT_ATTRIBUTES"
666+
/usr/bin/sed -i '' 's/=crypt\(.*\)/=crypt diff=crypt merge=crypt/' "$GIT_ATTRIBUTES"
646667
;;
647668
linux*)
648-
sed -i 's/filter=crypt diff=crypt\(.*\)/filter=crypt diff=crypt merge=crypt\1/' "$GIT_ATTRIBUTES"
669+
sed -i 's/=crypt\(.*\)/=crypt diff=crypt merge=crypt/' "$GIT_ATTRIBUTES"
649670
;;
650671
esac
672+
673+
printf 'Upgrade is complete\n'
674+
675+
LATEST_GITATTRIBUTES=$(cat "$GIT_ATTRIBUTES")
676+
if [[ "$LATEST_GITATTRIBUTES" != "$ORIG_GITATTRIBUTES" ]]; then
677+
printf '\nYour gitattributes file has been updated with the latest recommended values.\n'
678+
printf 'Please review and commit the new values in:\n'
679+
printf '%s\n' "$GIT_ATTRIBUTES"
680+
fi
651681
}
652682

653683
# list all of the currently encrypted files in the repository
@@ -793,8 +823,8 @@ help() {
793823
leave files in the current working copy decrypted
794824
795825
--upgrade
796-
uninstall and re-install transcrypt configuration in the repository
797-
to apply the newest scripts and .gitattributes configuration
826+
apply the latest transcrypt scripts in the repository without
827+
changing your configuration settings
798828
799829
-l, --list
800830
list all of the transparently encrypted files in the repository,
@@ -923,7 +953,6 @@ while [[ "${1:-}" != '' ]]; do
923953
upgrade='true'
924954
requires_existing_config='true'
925955
requires_clean_repo=''
926-
interactive=''
927956
;;
928957
-l | --list)
929958
list='true'

0 commit comments

Comments
 (0)