Skip to content

Commit bdacf49

Browse files
committed
feat: Support specifying package to upgrade with directory
1 parent 854b25f commit bdacf49

File tree

3 files changed

+58
-17
lines changed

3 files changed

+58
-17
lines changed

pkg/lib/commands/do-remove.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ do-remove() {
77

88
for repoSpec; do
99
# If is local directory
10-
# TODO: do this for upgrade as well
1110
if [ -d "$repoSpec" ]; then
1211
local dir=
1312
dir="$(util.readlink "$repoSpec")"

pkg/lib/commands/do-upgrade.sh

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,39 @@ do-upgrade() {
3434
fi
3535

3636
for repoSpec; do
37-
util.construct_clone_url "$repoSpec"
38-
local uri="$REPLY1"
39-
local site="$REPLY2"
40-
local package="$REPLY3"
41-
local ref="$REPLY4"
42-
43-
log.info "Upgrading '$repoSpec'"
44-
do-plumbing-remove-deps "$site/$package"
45-
do-plumbing-unlink-bins "$site/$package"
46-
do-plumbing-unlink-completions "$site/$package"
47-
do-plumbing-unlink-man "$site/$package"
48-
git -C "$BPM_PACKAGES_PATH/$site/$package" pull
49-
do-plumbing-add-deps "$site/$package"
50-
do-plumbing-link-bins "$site/$package"
51-
do-plumbing-link-completions "$site/$package"
52-
do-plumbing-link-man "$site/$package"
37+
# If is local directory
38+
if [ -d "$repoSpec" ]; then
39+
local dir=
40+
dir="$(util.readlink "$repoSpec")"
41+
dir="${dir%/}"
42+
43+
util.extract_data_from_package_dir "$dir"
44+
local site="$REPLY1"
45+
local package="$REPLY2/$REPLY3"
46+
47+
do_actual_upgrade "$site/$package"
48+
else
49+
util.construct_clone_url "$repoSpec"
50+
local site="$REPLY2"
51+
local package="$REPLY3"
52+
local ref="$REPLY4"
53+
54+
do_actual_upgrade "$site/$package"
55+
fi
5356
done
5457
}
58+
59+
do_actual_upgrade() {
60+
local id="$1"
61+
62+
log.info "Upgrading '$id'"
63+
do-plumbing-remove-deps "$id"
64+
do-plumbing-unlink-bins "$id"
65+
do-plumbing-unlink-completions "$id"
66+
do-plumbing-unlink-man "$id"
67+
git -C "$BPM_PACKAGES_PATH/$id" pull
68+
do-plumbing-add-deps "$id"
69+
do-plumbing-link-bins "$id"
70+
do-plumbing-link-completions "$id"
71+
do-plumbing-link-man "$id"
72+
}

tests/do-upgrade.bats

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@ load 'util/init.sh'
2525
assert [ -f "$BPM_PACKAGES_PATH/$site/$pkg/script2.sh" ]
2626
}
2727

28+
@test "simple upgrade (specifying with directory)" {
29+
local site='github.com'
30+
local pkg='username/package'
31+
32+
test_util.setup_pkg "$pkg"; {
33+
touch 'script.sh'
34+
}; test_util.finish_pkg
35+
test_util.fake_install "$pkg"
36+
37+
cd "$BPM_ORIGIN_DIR/$site/$pkg"
38+
touch 'script2.sh'
39+
git add .
40+
git commit -m 'Add script'
41+
cd "$BPM_CWD"
42+
43+
do-upgrade "$BPM_ORIGIN_DIR/$site/$pkg"
44+
45+
run do-list --outdated
46+
assert_output ""
47+
48+
assert [ -f "$BPM_PACKAGES_PATH/$site/$pkg/script2.sh" ]
49+
}
50+
51+
2852
@test "symlinks stay valid after upgrade" {
2953
local site='github.com'
3054
local pkg='username/package'

0 commit comments

Comments
 (0)