Skip to content

Commit

Permalink
Install a specific branch or tag with @ syntax
Browse files Browse the repository at this point in the history
Modify install command to take `package@ref` style syntax. This should
be idiomatic for everyone.

The ref selection is permanent, theres no way to switch the package
to a different ref without re-installing it.

Sort of related to basherpm#20 in terms of versioning packages
  • Loading branch information
YarekTyshchenko committed Mar 27, 2017
1 parent 278243b commit d0131af
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
13 changes: 10 additions & 3 deletions libexec/basher-_clone
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
#
# Summary: Clones a package from a site, but doesn't install it
#
# Usage: basher _clone <use_ssh> <site> <package>
# Usage: basher _clone <use_ssh> <site> <package> [<ref>]

set -e

if [ "$#" -ne 3 ]; then
if [ "$#" -ne 3 -a "$#" -ne 4 ]; then
basher-help _clone
exit 1
fi

use_ssh="$1"
site="$2"
package="$3"
ref="$4"

if [ -z "$use_ssh" ]; then
basher-help _clone
Expand All @@ -30,6 +31,12 @@ if [ -z "$package" ]; then
exit 1
fi

if [ -z "$ref" ]; then
BRANCH_OPTION=""
else
BRANCH_OPTION="-b $ref"
fi

IFS=/ read -r user name <<< "$package"

if [ -z "$user" ]; then
Expand Down Expand Up @@ -59,4 +66,4 @@ else
URI="https://${site}/$package.git"
fi

git clone ${DEPTH_OPTION} --recursive "$URI" "${BASHER_PACKAGES_PATH}/$package"
git clone ${DEPTH_OPTION} ${BRANCH_OPTION} --recursive "$URI" "${BASHER_PACKAGES_PATH}/$package"
14 changes: 12 additions & 2 deletions libexec/basher-install
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Summary: Installs a package from github (or a custom site)
#
# Usage: basher install [--ssh] [site]/<package>
# Usage: basher install [--ssh] [site]/<package>[@ref]

set -e

Expand Down Expand Up @@ -47,7 +47,17 @@ if [ -z "$name" ]; then
exit 1
fi

basher-_clone "$use_ssh" "$site" "$package"
if [[ "$package" = */*@* ]]; then
IFS=@ read -r package ref <<< "$package"
else
ref=""
fi

if [ -z "$ref" ]; then
basher-_clone "$use_ssh" "$site" "$package"
else
basher-_clone "$use_ssh" "$site" "$package" "$ref"
fi
basher-_deps "$package"
basher-_link-bins "$package"
basher-_link-man "$package"
Expand Down
16 changes: 12 additions & 4 deletions tests/basher-_clone.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ load test_helper
@test "without arguments prints usage" {
run basher-_clone
assert_failure
assert_line "Usage: basher _clone <use_ssh> <site> <package>"
assert_line "Usage: basher _clone <use_ssh> <site> <package> [<ref>]"
}

@test "invalid package prints usage" {
run basher-_clone false github.com invalid_package
assert_failure
assert_line "Usage: basher _clone <use_ssh> <site> <package>"
assert_line "Usage: basher _clone <use_ssh> <site> <package> [<ref>]"
}

@test "too many arguments prints usage" {
run basher-_clone false site a/b third_arg
run basher-_clone false site a/b ref fourth_arg
assert_failure
assert_line "Usage: basher _clone <use_ssh> <site> <package>"
assert_line "Usage: basher _clone <use_ssh> <site> <package> [<ref>]"
}

@test "install a specific version" {
mock_command git

run basher-_clone false site username/package version
assert_success
assert_output "git clone --depth=1 -b version --recursive https://site/username/package.git ${BASHER_PACKAGES_PATH}/username/package"
}

@test "does nothing if package is already present" {
Expand Down
6 changes: 3 additions & 3 deletions tests/basher-install.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ load test_helper
@test "without arguments prints usage" {
run basher-install
assert_failure
assert_line "Usage: basher install [--ssh] [site]/<package>"
assert_line "Usage: basher install [--ssh] [site]/<package>[@ref]"
}

@test "incorrect argument prints usage" {
run basher-install first_arg
assert_failure
assert_line "Usage: basher install [--ssh] [site]/<package>"
assert_line "Usage: basher install [--ssh] [site]/<package>[@ref]"
}

@test "too many arguments prints usage" {
run basher-install a/b wrong
assert_failure
assert_line "Usage: basher install [--ssh] [site]/<package>"
assert_line "Usage: basher install [--ssh] [site]/<package>[@ref]"
}

@test "executes install steps in right order" {
Expand Down

0 comments on commit d0131af

Please sign in to comment.