Skip to content

Commit 3dd2f39

Browse files
committed
fix: add --all does not fail if packages are already installed
1 parent a784125 commit 3dd2f39

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

pkg/lib/commands/do-add.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,17 @@ do-actual-add() {
8484
die "Cannot install packages owned by username 'local' because that conflicts with linked packages"
8585
fi
8686

87-
log.info "Adding '$repoSpec'"
87+
if [ -e "$BPM_PACKAGES_PATH/$site/$package" ]; then
88+
if [ "$BPM_IS_LOCAL" = yes ]; then
89+
log.info "Skipping '$site/$package' as it's already present"
90+
return
91+
else
92+
die "Package '$site/$package' is already present"
93+
fi
94+
else
95+
log.info "Adding '$repoSpec'"
96+
fi
97+
8898
do-plumbing-clone "$uri" "$site/$package" "$ref" "$flag_branch"
8999
do-plumbing-add-deps "$site/$package"
90100
do-plumbing-link-bins "$site/$package"

tests/do-add.bats

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,26 @@ load 'util/init.sh'
310310
assert_failure
311311
assert_line -p "Cannot pass '--all' without a 'bpm.toml' file"
312312
}
313+
314+
@test "--all works if some are already installed" {
315+
local site='github.com'
316+
local pkg1='user/project'
317+
local pkg2='user/project2'
318+
319+
test_util.create_package "$pkg1"
320+
test_util.create_package "$pkg2"
321+
322+
echo "dependencies = [ 'file://$BPM_ORIGIN_DIR/$pkg1' ]" > 'bpm.toml'
323+
BPM_IS_LOCAL='yes' run do-add --all
324+
325+
assert_success
326+
327+
echo "dependencies = [ 'file://$BPM_ORIGIN_DIR/$pkg1', 'file://$BPM_ORIGIN_DIR/$pkg2' ]" > 'bpm.toml'
328+
BPM_IS_LOCAL='yes' run do-add --all
329+
330+
assert_success
331+
assert [ -d "./bpm_packages/packages/$site/$pkg1" ]
332+
assert [ -d "./bpm_packages/packages/$site/$pkg1/.git" ]
333+
assert [ -d "./bpm_packages/packages/$site/$pkg2" ]
334+
assert [ -d "./bpm_packages/packages/$site/$pkg2/.git" ]
335+
}

0 commit comments

Comments
 (0)