File tree Expand file tree Collapse file tree 8 files changed +61
-6
lines changed
fixtures/dummy_plugins_repo/plugins Expand file tree Collapse file tree 8 files changed +61
-6
lines changed Original file line number Diff line number Diff line change 11installs
2- plugins
2+ / plugins
33shims
44repository
55.vagrant
66keyrings
7+ /tmp
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ source $(dirname $(dirname $0))/lib/commands/list-all.sh
1515source $( dirname $( dirname $0 ) ) /lib/commands/reshim.sh
1616source $( dirname $( dirname $0 ) ) /lib/commands/plugin-add.sh
1717source $( dirname $( dirname $0 ) ) /lib/commands/plugin-list.sh
18+ source $( dirname $( dirname $0 ) ) /lib/commands/plugin-list-all.sh
1819source $( dirname $( dirname $0 ) ) /lib/commands/plugin-update.sh
1920source $( dirname $( dirname $0 ) ) /lib/commands/plugin-remove.sh
2021
@@ -49,7 +50,7 @@ case $1 in
4950
5051" which" )
5152 which_command $callback_args ;;
52-
53+
5354" local" )
5455 local_command $callback_args ;;
5556
@@ -74,6 +75,9 @@ case $1 in
7475" plugin-list" )
7576 plugin_list_command $callback_args ;;
7677
78+ " plugin-list-all" )
79+ plugin_list_all_command $callback_args ;;
80+
7781" plugin-update" )
7882 plugin_update_command $callback_args ;;
7983
Original file line number Diff line number Diff line change 1+ plugin_list_all_command () {
2+ initialize_or_update_repository
3+
4+ local plugins_path=$( asdf_dir) /repository/plugins
5+ for plugin in $plugins_path /* ; do
6+ local plugin_name=" $( basename $plugin ) "
7+ echo " $plugin_name "
8+ done
9+ }
Original file line number Diff line number Diff line change @@ -261,20 +261,31 @@ asdf_repository_url() {
261261 echo " https://github.com/asdf-vm/asdf-plugins.git"
262262}
263263
264+ repository_needs_update () {
265+ local update_file_dir=" $( asdf_dir) /tmp"
266+ local update_file_name=" repo-updated"
267+ # `find` outputs filename if it has not been modified in the last day
268+ local find_result=$( find $update_file_dir -name " $update_file_name " -type f -mtime +1 -print)
269+ [ -n " $find_result " ]
270+ }
271+
264272initialize_or_update_repository () {
265273 local repository_url
266274 local repository_path
267275
268276 repository_url=$( asdf_repository_url)
269277 repository_path=$( asdf_dir) /repository
270278
271- if [ -d " $repository_path " ]; then
272- echo " updating plugin repository..."
273- (cd " $repository_path " && git fetch && git reset --hard origin/master)
274- else
279+ if [ ! -d " $repository_path " ]; then
275280 echo " initializing plugin repository..."
276281 git clone " $repository_url " " $repository_path "
282+ elif repository_needs_update; then
283+ echo " updating plugin repository..."
284+ (cd " $repository_path " && git fetch && git reset --hard origin/master)
277285 fi
286+
287+ mkdir -p " $( asdf_dir) /tmp"
288+ touch " $( asdf_dir) /tmp/repo-updated"
278289}
279290
280291get_plugin_source_url () {
Original file line number Diff line number Diff line change 1+ repository = http://example.com/bar
Original file line number Diff line number Diff line change 1+ repository = http://example.com/foo
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bats
2+
3+ load test_helpers
4+
5+ . $( dirname $BATS_TEST_DIRNAME ) /lib/commands/plugin-list-all.sh
6+
7+ setup () {
8+ setup_asdf_dir
9+ setup_repo
10+ }
11+
12+ teardown () {
13+ clean_asdf_dir
14+ }
15+
16+ @test " plugin_list_all list all plugins in the repository" {
17+ run plugin_list_all_command
18+ local expected=" bar
19+ foo"
20+ [ " $status " -eq 0 ]
21+ [ " $output " = " $expected " ]
22+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ setup_asdf_dir() {
77 mkdir -p $ASDF_DIR /plugins
88 mkdir -p $ASDF_DIR /installs
99 mkdir -p $ASDF_DIR /shims
10+ mkdir -p $ASDF_DIR /tmp
1011 PATH=$ASDF_DIR /shims:$PATH
1112}
1213
@@ -33,3 +34,8 @@ clean_asdf_dir() {
3334 rm -rf $BASE_DIR
3435 unset ASDF_DIR
3536}
37+
38+ setup_repo () {
39+ cp -r $BATS_TEST_DIRNAME /fixtures/dummy_plugins_repo $ASDF_DIR /repository
40+ touch " $( asdf_dir) /tmp/repo-updated"
41+ }
You can’t perform that action at this time.
0 commit comments