Skip to content

Commit 7574cec

Browse files
committed
fix: Do not allow 'add', 'remove', 'upgrade' in local mode
Script prints (somewhat verbose) message
1 parent 3dd2f39 commit 7574cec

13 files changed

+107
-50
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ See [Installation](./docs/installation.md) and [Getting Started](./docs/getting-
3838
- Local and user-wide package installation
3939
- Configure (optionally) exactly which directories are used for completions, binaries, or man pages
4040
- Works with essentially all popular Bash projects out of the box
41-
- 250+ Tests
41+
- 260+ Tests
4242

4343
## Alternatives Comparison
4444

pkg/lib/commands/do-add.sh

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,21 @@ do-add() {
3232
esac
3333
done
3434

35+
if [ "$flag_all" = yes ] && (( ${#pkgs[@]} > 0 )); then
36+
die "No packages may be supplied when using '--all'"
37+
fi
38+
39+
if [ "$BPM_IS_LOCAL" = yes ] && (( ${#pkgs[@]} > 0 )); then
40+
die "Cannot specify individual packages for subcommand 'add' in local projects. Please edit your 'bpm.toml' and use either 'add --all' or 'remove --all'"
41+
fi
42+
3543
if [[ "$BPM_IS_LOCAL" == no && "$flag_all" == yes ]]; then
3644
die "Cannot pass '--all' without a 'bpm.toml' file"
3745
fi
3846

3947
if [ "$flag_all" = yes ]; then
4048
local bpm_toml_file="$BPM_ROOT/bpm.toml"
4149

42-
if (( ${#pkgs[@]} > 0 )); then
43-
die "No packages may be supplied when using '--all'"
44-
fi
45-
4650
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
4751
log.info "Adding all dependencies"
4852

@@ -58,11 +62,11 @@ do-add() {
5862

5963
if (( ${#pkgs[@]} == 0 )); then
6064
die "At least one package must be supplied"
65+
else
66+
for repoSpec in "${pkgs[@]}"; do
67+
do-actual-add "$repoSpec" "$flag_ssh" "$flag_branch"
68+
done
6169
fi
62-
63-
for repoSpec in "${pkgs[@]}"; do
64-
do-actual-add "$repoSpec" "$flag_ssh" "$flag_branch"
65-
done
6670
}
6771

6872
do-actual-add() {
@@ -100,23 +104,4 @@ do-actual-add() {
100104
do-plumbing-link-bins "$site/$package"
101105
do-plumbing-link-completions "$site/$package"
102106
do-plumbing-link-man "$site/$package"
103-
104-
# Install transitive dependencies
105-
local subDep="$BPM_PACKAGES_PATH/$site/$package"
106-
107-
if [[ ! -d "$subDep" && -n "${BPM_MODE_TEST+x}" ]]; then
108-
# During some tests, plumbing-* or Git commands may be stubbed,
109-
# so the package may not actually be cloned
110-
return
111-
fi
112-
113-
local oldWd="$PWD"
114-
ensure.cd "$subDep"
115-
local bpm_toml_file="$subDep/bpm.toml"
116-
if [ -f "$bpm_toml_file" ]; then
117-
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
118-
do-add --all
119-
fi
120-
fi
121-
ensure.cd "$oldWd"
122107
}

pkg/lib/commands/do-plumbing-add-deps.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ do-plumbing-add-deps() {
1616
local bpm_toml_file="$BPM_PACKAGES_PATH/$id/bpm.toml"
1717
local package_sh_file="$BPM_PACKAGES_PATH/$id/package.sh"
1818

19+
# Install transitive dependencies
20+
local subDep="$BPM_PACKAGES_PATH/$id"
21+
if [[ ! -d "$subDep" && -n "${BPM_MODE_TEST+x}" ]]; then
22+
# During some tests, plumbing-* or Git commands may be stubbed,
23+
# so the package may not actually be cloned
24+
return
25+
fi
26+
1927
if [ -f "$bpm_toml_file" ]; then
2028
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
2129
deps=("${REPLIES[@]}")
@@ -31,6 +39,13 @@ do-plumbing-add-deps() {
3139
fi
3240

3341
for dep in "${deps[@]}"; do
34-
do-add "$dep"
42+
local oldWd="$PWD"
43+
ensure.cd "$subDep"
44+
util.setup_mode
45+
46+
do-actual-add "$dep"
47+
48+
ensure.cd "$oldWd"
49+
util.setup_mode
3550
done
3651
}

pkg/lib/commands/do-remove.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@ do-remove() {
2424
esac
2525
done
2626

27+
if [ "$flag_all" = yes ] && (( ${#pkgs[@]} > 0 )); then
28+
die "No packages may be supplied when using '--all'"
29+
fi
30+
31+
if [ "$BPM_IS_LOCAL" = yes ] && (( ${#pkgs[@]} > 0 )); then
32+
die "Cannot specify individual packages for subcommand 'remove' in local projects. Please edit your 'bpm.toml' and use either 'add --all' or 'remove --all'"
33+
fi
34+
2735
if [[ $flag_all == yes && $flag_force == yes ]]; then
2836
die "Flags '--all' and '--force' are mutually exclusive"
2937
fi
3038

3139
if [ "$flag_all" = yes ]; then
3240
local bpm_toml_file="$BPM_ROOT/bpm.toml"
3341

34-
if (( ${#pkgs[@]} > 0 )); then
35-
die "No packages may be supplied when using '--all'"
36-
fi
37-
3842
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
3943
log.info "Removing all dependencies"
4044

pkg/lib/commands/do-upgrade.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ do-upgrade() {
2424
esac
2525
done
2626

27+
if [ "$flag_all" = yes ] && (( ${#pkgs[@]} > 0 )); then
28+
die "No packages may be supplied when using '--all'"
29+
fi
30+
31+
if [ "$BPM_IS_LOCAL" = yes ] && (( ${#pkgs[@]} > 0 )); then
32+
die "Cannot specify individual packages for subcommand 'upgrade' in local projects. Please edit your 'bpm.toml' and use either 'add --all' or 'remove --all'"
33+
fi
34+
2735
if [[ $upgrade_bpm == yes && "$flag_all" = yes ]]; then
2836
die "Upgrading bpm and using '--all' are mutually exclusive behaviors"
2937
fi
@@ -54,10 +62,6 @@ do-upgrade() {
5462

5563
# TODO: test this
5664
if [ "$flag_all" = yes ]; then
57-
if (( ${#pkgs[@]} > 0 )); then
58-
die "No packages may be supplied when using '--all'"
59-
fi
60-
6165
local bpm_toml_file="$BPM_ROOT/bpm.toml"
6266

6367
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then

pkg/lib/util/ensure.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ ensure.package_exists() {
3636
local id="$1"
3737

3838
if [ ! -d "$BPM_PACKAGES_PATH/$id" ]; then
39-
die "Package '$id' does not exist"
39+
log.error "Package '$id' does not exist"
40+
printf " --> %s" "'$BPM_PACKAGES_PATH/$id'"
41+
exit 1
4042
fi
4143
}
4244

pkg/lib/util/util.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ util.setup_mode() {
273273
if project_root_dir="$(util.get_project_root_dir)"; then
274274
# Output to standard error because some subcommands may be scriptable (ex. list)
275275
log.info "Operating in context of local bpm.toml" >&2
276+
if [ "${BPM_MODE_TEST+x}" ]; then
277+
printf " -> %s\n" "'$project_root_dir'"
278+
fi
276279

277280
BPM_ROOT="$project_root_dir"
278281
BPM_PREFIX="$project_root_dir/bpm_packages"

tests/do-add.bats

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,17 @@ load 'util/init.sh'
333333
assert [ -d "./bpm_packages/packages/$site/$pkg2" ]
334334
assert [ -d "./bpm_packages/packages/$site/$pkg2/.git" ]
335335
}
336+
337+
@test "fails if in local mode" {
338+
local site='github.com'
339+
local pkg1='user/project'
340+
341+
touch 'bpm.toml'
342+
343+
test_util.create_package "$pkg1"
344+
345+
BPM_IS_LOCAL='yes' run do-add "$pkg1"
346+
347+
assert_failure
348+
assert_line -p "Cannot specify individual packages for subcommand 'add' in local projects. Please edit your 'bpm.toml' and use either 'add --all' or 'remove --all'"
349+
}

tests/do-plumbing-add-deps.bats

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ load 'util/init.sh'
2323
local site='github.com'
2424
local pkg='username/package'
2525

26-
test_util.stub_command 'do-add'
26+
test_util.stub_command 'do-actual-add'
2727

2828
test_util.setup_pkg "$pkg"; {
2929
echo 'DEPS=user/dep1:user/dep2' > 'package.sh'
@@ -33,15 +33,15 @@ load 'util/init.sh'
3333
run do-plumbing-add-deps "$site/$pkg"
3434

3535
assert_success
36-
assert_line "do-add user/dep1"
37-
assert_line "do-add user/dep2"
36+
assert_line "do-actual-add user/dep1"
37+
assert_line "do-actual-add user/dep2"
3838
}
3939

4040
@test "on bpm.toml dependencies, installs properly" {
4141
local site='github.com'
4242
local pkg='username/package'
4343

44-
test_util.stub_command 'do-add'
44+
test_util.stub_command 'do-actual-add'
4545

4646
test_util.setup_pkg "$pkg"; {
4747
echo 'dependencies = [ "user/dep1", "user/dep2" ]' > 'bpm.toml'
@@ -51,15 +51,17 @@ load 'util/init.sh'
5151
run do-plumbing-add-deps "$site/$pkg"
5252

5353
assert_success
54-
assert_line "do-add user/dep1"
55-
assert_line "do-add user/dep2"
54+
assert_line "do-actual-add user/dep1"
55+
assert_line "do-actual-add user/dep2"
5656
}
5757

5858
@test "bpm.toml has presidence over package.sh add deps" {
5959
local site='github.com'
6060
local pkg='username/package'
6161

62-
test_util.stub_command do-add
62+
touch 'bpm.toml'
63+
64+
test_util.stub_command 'do-actual-add'
6365

6466
test_util.setup_pkg "$pkg"; {
6567
echo 'DEPS=user/bad_dep' > 'package.sh'
@@ -70,6 +72,6 @@ load 'util/init.sh'
7072
run do-plumbing-add-deps "$site/$pkg"
7173

7274
assert_success
73-
refute_line "do-add user/bad_dep"
74-
assert_line "do-add user/good_dep"
75+
refute_line "do-actual-add user/bad_dep"
76+
assert_line "do-actual-add user/good_dep"
7577
}

tests/do-plumbing-remove-deps.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ load 'util/init.sh'
66
local site='github.com'
77
local pkg='username/package'
88

9-
test_util.stub_command 'do-add'
9+
test_util.stub_command 'do-actual-add'
1010

1111
test_util.setup_pkg "$pkg"; {
1212
echo 'DEPS=user/dep1:user/dep2' > 'package.sh'
@@ -24,7 +24,7 @@ load 'util/init.sh'
2424
local site='github.com'
2525
local pkg='username/package'
2626

27-
test_util.stub_command 'do-add'
27+
test_util.stub_command 'do-actual-add'
2828

2929
test_util.setup_pkg "$pkg"; {
3030
echo 'dependencies = [ "user/dep1", "user/dep2" ]' > 'bpm.toml'

0 commit comments

Comments
 (0)