From 67830795a400a474e42a6ca598fe52904c0893f0 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 11 Mar 2026 10:23:00 +0200 Subject: [PATCH 1/4] - Prevent running `rush default default` --- rush | 4 ++++ src/commands/default.sh | 5 ++++- test/approvals/rush_default_default | 1 + test/approve | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/approvals/rush_default_default diff --git a/rush b/rush index 1276b2d..94237b9 100755 --- a/rush +++ b/rush @@ -1596,6 +1596,9 @@ rush_default_command() { # src/commands/default.sh repo=${args[repo]} + + [[ $repo != "default" ]] || abort "cannot use 'default' as the source repo" + repo_path=$(config_get "$repo") [[ $repo_path ]] || abort "repo not found: $repo" @@ -1603,6 +1606,7 @@ rush_default_command() { config_set "default" "$repo_path" config_del "$repo" say "default" "$repo ($repo_path)" + } # :command.function diff --git a/src/commands/default.sh b/src/commands/default.sh index 55155e4..8eb568c 100644 --- a/src/commands/default.sh +++ b/src/commands/default.sh @@ -1,5 +1,8 @@ ## Collect variables repo=${args[repo]} + +[[ $repo != "default" ]] || abort "cannot use 'default' as the source repo" + repo_path=$(config_get "$repo") ## Verify we have everything we need @@ -7,4 +10,4 @@ repo_path=$(config_get "$repo") config_set "default" "$repo_path" config_del "$repo" -say "default" "$repo ($repo_path)" \ No newline at end of file +say "default" "$repo ($repo_path)" diff --git a/test/approvals/rush_default_default b/test/approvals/rush_default_default new file mode 100644 index 0000000..98c873c --- /dev/null +++ b/test/approvals/rush_default_default @@ -0,0 +1 @@ +cannot use 'default' as the source repo diff --git a/test/approve b/test/approve index 80d4746..811ba4f 100755 --- a/test/approve +++ b/test/approve @@ -55,6 +55,7 @@ describe "default" approve "rush default" || return 0 approve "rush default -h" approve "rush default sample" + approve "rush default default" || return 0 describe "get" approve "rush add sample ~/rush-repos/sample-repo" From e10e5f7899db904819e50d2d2190bb0188c4f6f9 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 11 Mar 2026 10:39:21 +0200 Subject: [PATCH 2/4] - Improve cleanup in `rush snatch` --- rush | 12 +++++++++--- src/commands/snatch.sh | 12 +++++++++--- test/approve | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/rush b/rush index 94237b9..561f81e 100755 --- a/rush +++ b/rush @@ -1722,13 +1722,19 @@ rush_snatch_command() { [[ -n "${args['--verbose']}" ]] && export VERBOSE=1 cleanup() { - rush remove snatched --purge - rm -r "$tmpdir" + local exitcode="$1" + + if config_has_key "snatched"; then + rush remove snatched --purge || true + fi + + rm -rf "$tmpdir" + return "$exitcode" } say "snatch" "$repo_id $package" - trap cleanup EXIT ERR INT TERM + trap 'exitcode=$?; cleanup "$exitcode"' EXIT rush clone "$repo_id" "$path" --name snatched if [[ $undo ]]; then diff --git a/src/commands/snatch.sh b/src/commands/snatch.sh index f98a6f6..b904d3b 100644 --- a/src/commands/snatch.sh +++ b/src/commands/snatch.sh @@ -9,13 +9,19 @@ path="$tmpdir/snatched" [[ -n "${args['--verbose']}" ]] && export VERBOSE=1 cleanup() { - rush remove snatched --purge - rm -r "$tmpdir" + local exitcode="$1" + + if config_has_key "snatched"; then + rush remove snatched --purge || true + fi + + rm -rf "$tmpdir" + return "$exitcode" } say "snatch" "$repo_id $package" -trap cleanup EXIT ERR INT TERM +trap 'exitcode=$?; cleanup "$exitcode"' EXIT rush clone "$repo_id" "$path" --name snatched if [[ $undo ]]; then diff --git a/test/approve b/test/approve index 811ba4f..f6c4853 100755 --- a/test/approve +++ b/test/approve @@ -56,6 +56,7 @@ describe "default" approve "rush default -h" approve "rush default sample" approve "rush default default" || return 0 + expect_exit_code 1 describe "get" approve "rush add sample ~/rush-repos/sample-repo" From b9612ba17e1f0197d6798eda565e24e05bd02e14 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 11 Mar 2026 11:08:09 +0200 Subject: [PATCH 3/4] - Remove dead search code from `rush list` --- rush | 16 +++++----------- src/commands/list.sh | 5 ++--- src/lib/list_show_repo.sh | 11 +++-------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/rush b/rush index 561f81e..a9fa349 100755 --- a/rush +++ b/rush @@ -1098,9 +1098,8 @@ list_display_item() { # src/lib/list_show_repo.sh list_show_repo() { local repo_or_package="$1" - local search="$2" - local simple="$3" - local all="$4" + local simple="$2" + local all="$3" local repo="$repo_or_package" local package glob repo_path infofile regex package_name @@ -1138,11 +1137,7 @@ list_show_repo() { else for infofile in "${glob[@]}"; do - if [[ $search ]]; then - regex="$repo_path/(.*${search}.*)/info" - else - regex="$repo_path/(.*)/info" - fi + regex="$repo_path/(.*)/info" if [[ $infofile =~ $regex ]]; then package_name="${BASH_REMATCH[1]}" @@ -1830,15 +1825,14 @@ rush_list_command() { # src/commands/list.sh repo_or_package=${args[repo_or_package]} - search=${args[--search]} simple=${args[--simple]} all=${args[--all]} if [[ $repo_or_package ]]; then - list_show_repo "$repo_or_package" "$search" "$simple" "$all" + list_show_repo "$repo_or_package" "$simple" "$all" else for k in $(config_keys); do - list_show_repo "$k" "$search" "$simple" "$all" + list_show_repo "$k" "$simple" "$all" done fi diff --git a/src/commands/list.sh b/src/commands/list.sh index 01d60c9..0044c96 100644 --- a/src/commands/list.sh +++ b/src/commands/list.sh @@ -1,12 +1,11 @@ repo_or_package=${args[repo_or_package]} -search=${args[--search]} simple=${args[--simple]} all=${args[--all]} if [[ $repo_or_package ]]; then - list_show_repo "$repo_or_package" "$search" "$simple" "$all" + list_show_repo "$repo_or_package" "$simple" "$all" else for k in $(config_keys); do - list_show_repo "$k" "$search" "$simple" "$all" + list_show_repo "$k" "$simple" "$all" done fi diff --git a/src/lib/list_show_repo.sh b/src/lib/list_show_repo.sh index 03c77de..072c0ce 100644 --- a/src/lib/list_show_repo.sh +++ b/src/lib/list_show_repo.sh @@ -1,8 +1,7 @@ list_show_repo() { local repo_or_package="$1" - local search="$2" - local simple="$3" - local all="$4" + local simple="$2" + local all="$3" local repo="$repo_or_package" local package glob repo_path infofile regex package_name @@ -40,11 +39,7 @@ list_show_repo() { else for infofile in "${glob[@]}"; do - if [[ $search ]]; then - regex="$repo_path/(.*${search}.*)/info" - else - regex="$repo_path/(.*)/info" - fi + regex="$repo_path/(.*)/info" if [[ $infofile =~ $regex ]]; then package_name="${BASH_REMATCH[1]}" From 89d95747295d00d81da096f8b5bc3661b11efe33 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 11 Mar 2026 11:20:38 +0200 Subject: [PATCH 4/4] - Improve rush list repo/package detection --- rush | 12 +++++++++--- src/lib/list_show_repo.sh | 12 +++++++++--- test/approvals/rush_list_nope_thing | 1 + test/approvals/rush_list_sample_asd | 1 + test/approve | 4 +++- 5 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 test/approvals/rush_list_nope_thing create mode 100644 test/approvals/rush_list_sample_asd diff --git a/rush b/rush index a9fa349..5a5ef0f 100755 --- a/rush +++ b/rush @@ -1101,9 +1101,11 @@ list_show_repo() { local simple="$2" local all="$3" local repo="$repo_or_package" + local explicit_repo= local package glob repo_path infofile regex package_name if [[ $repo_or_package =~ (.*):(.*) ]]; then + explicit_repo=1 repo=${BASH_REMATCH[1]} package=${BASH_REMATCH[2]} fi @@ -1111,9 +1113,13 @@ list_show_repo() { repo_path=$(config_get "$repo") if [[ ! $repo_path ]]; then - package="$repo" - repo="default" - repo_path=$(config_get "$repo") + if [[ $explicit_repo ]]; then + abort "repo not found: $repo" + else + package="$repo" + repo="default" + repo_path=$(config_get "$repo") + fi fi if [[ $package ]]; then diff --git a/src/lib/list_show_repo.sh b/src/lib/list_show_repo.sh index 072c0ce..5032c67 100644 --- a/src/lib/list_show_repo.sh +++ b/src/lib/list_show_repo.sh @@ -3,9 +3,11 @@ list_show_repo() { local simple="$2" local all="$3" local repo="$repo_or_package" + local explicit_repo= local package glob repo_path infofile regex package_name if [[ $repo_or_package =~ (.*):(.*) ]]; then + explicit_repo=1 repo=${BASH_REMATCH[1]} package=${BASH_REMATCH[2]} fi @@ -13,9 +15,13 @@ list_show_repo() { repo_path=$(config_get "$repo") if [[ ! $repo_path ]]; then - package="$repo" - repo="default" - repo_path=$(config_get "$repo") + if [[ $explicit_repo ]]; then + abort "repo not found: $repo" + else + package="$repo" + repo="default" + repo_path=$(config_get "$repo") + fi fi if [[ $package ]]; then diff --git a/test/approvals/rush_list_nope_thing b/test/approvals/rush_list_nope_thing new file mode 100644 index 0000000..faffe13 --- /dev/null +++ b/test/approvals/rush_list_nope_thing @@ -0,0 +1 @@ +repo not found: nope diff --git a/test/approvals/rush_list_sample_asd b/test/approvals/rush_list_sample_asd new file mode 100644 index 0000000..2219270 --- /dev/null +++ b/test/approvals/rush_list_sample_asd @@ -0,0 +1 @@ +nothing in sample repo diff --git a/test/approve b/test/approve index f6c4853..1a5af85 100755 --- a/test/approve +++ b/test/approve @@ -124,7 +124,10 @@ describe "list" approve "rush list --all" approve "rush list --all --simple" approve "rush list hello" + approve "rush list nope:thing" || return 0 + expect_exit_code 1 approve "rush list sample" + approve "rush list sample:asd" approve "rush list nested" approve "rush list sample:nested" approve "rush list no-such-package" @@ -166,4 +169,3 @@ describe "copy" describe "completions" approve "rush completions" approve "rush completions -h" -