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.
pull/1043/head
Nils Winkler 2017-09-15 08:10:17 +02:00
parent 1a80d892ad
commit f57bd1e131
2 changed files with 30 additions and 5 deletions

View File

@ -303,10 +303,10 @@ _disable-thing ()
return return
fi fi
if [ "$file_entity" = "all" ]; then typeset f suffix
typeset f $file_type suffix suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g')
suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g')
if [ "$file_entity" = "all" ]; then
# Disable everything that's using the old structure # Disable everything that's using the old structure
for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"` for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"`
do do
@ -319,13 +319,13 @@ _disable-thing ()
rm "$f" rm "$f"
done done
else 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 if [ -z "$plugin_global" ]; then
# Use a glob to search for both possible patterns # Use a glob to search for both possible patterns
# 250---node.plugin.bash # 250---node.plugin.bash
# node.plugin.bash # node.plugin.bash
# Either one will be matched by this glob # 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 if [ -z "$plugin" ]; then
printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
return return

View File

@ -251,6 +251,28 @@ function local_setup {
assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] 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" { @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 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" ] 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" ] assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ]
run _bash-it-migrate 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/225---nvm.plugin.bash" ]
assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ]