From f57bd1e1314080be721567c87d1bb37831055c34 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH] Fixed issues with migrating components with the same name dirs.plugin.bash was recognized while looking for dirs.completion.bash in the global enabled directory. --- lib/helpers.bash | 10 +++++----- test/lib/helpers.bats | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 779e500b..bd284dd8 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -303,10 +303,10 @@ _disable-thing () return fi - if [ "$file_entity" = "all" ]; then - typeset f $file_type suffix - suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') + typeset f suffix + suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') + if [ "$file_entity" = "all" ]; then # Disable everything that's using the old structure for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"` do @@ -319,13 +319,13 @@ _disable-thing () rm "$f" done else - typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash 2>/dev/null | head -1) + typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2>/dev/null | head -1) if [ -z "$plugin_global" ]; then # Use a glob to search for both possible patterns # 250---node.plugin.bash # node.plugin.bash # Either one will be matched by this glob - typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash,$file_entity.*bash} 2>/dev/null | head -1) + typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2>/dev/null | head -1) if [ -z "$plugin" ]; then printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." return diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 4a92d09e..99cd2501 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -251,6 +251,28 @@ function local_setup { assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } +@test "helpers: migrate plugins and completions that share the same name" { + ln -s $BASH_IT/completion/available/dirs.completion.bash $BASH_IT/completion/enabled/350---dirs.completion.bash + assert [ -L "$BASH_IT/completion/enabled/350---dirs.completion.bash" ] + + ln -s $BASH_IT/plugins/available/dirs.plugin.bash $BASH_IT/plugins/enabled/250---dirs.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---dirs.plugin.bash" ] + + run _bash-it-migrate + assert_line "0" 'Migrating plugin dirs.' + assert_line "1" 'dirs disabled.' + assert_line "2" 'dirs enabled with priority 250.' + assert_line "3" 'Migrating completion dirs.' + assert_line "4" 'dirs disabled.' + assert_line "5" 'dirs enabled with priority 350.' + assert_line "6" 'If any migration errors were reported, please try the following: reload && bash-it migrate' + + assert [ -L "$BASH_IT/enabled/350---dirs.completion.bash" ] + assert [ -L "$BASH_IT/enabled/250---dirs.plugin.bash" ] + assert [ ! -L "$BASH_IT/completion/enabled/350----dirs.completion.bash" ] + assert [ ! -L "$BASH_IT/plugins/enabled/250----dirs.plugin.bash" ] +} + @test "helpers: migrate enabled plugins that don't use the new priority-based configuration" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] @@ -265,6 +287,9 @@ function local_setup { assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] run _bash-it-migrate + assert_line "0" 'Migrating alias todo.txt-cli.' + assert_line "1" 'todo.txt-cli disabled.' + assert_line "2" 'todo.txt-cli enabled with priority 150.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ]