Skip to content

Commit

Permalink
Install a specific branch or tag with @ syntax
Browse files Browse the repository at this point in the history
- Use idiomatic `username/package@ref` style syntax.
- Check for upstream changes in a more portable way
- Disable outdated check on packages cloned by ref or tag

The ref selection is permanent at install time. Theres no way to
switch the package to a different ref without re-installing it.

Tags in git are effectively non-updatable. If you checked out a package
on a tag or commit hash its very likely that you'll never expect that
tag to change and want to pin the package to that specific version

Thanks to osse from #git for quick help ❤️
  • Loading branch information
YarekTyshchenko authored and juanibiapina committed Aug 17, 2017
1 parent 81e38bf commit e683443
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 14 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
6 changes: 4 additions & 2 deletions libexec/basher-outdated
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ do
if [ ! -L "$package_path" ]; then
cd $package_path
git remote update > /dev/null 2>&1
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/HEAD)" ]; then
echo "$package"
if git symbolic-ref --short -q HEAD > /dev/null; then
if [ "$(git rev-list --count HEAD...HEAD@{upstream})" -gt 0 ]; then
echo "$package"
fi
fi
fi
done
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
30 changes: 27 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 Expand Up @@ -71,6 +71,30 @@ basher-_link-completions username/package"
assert_line "basher-_clone true github.com username/package"
}

@test "installs with custom version" {
mock_command basher-_clone
mock_command basher-_deps
mock_command basher-_link-bins
mock_command basher-_link-man
mock_command basher-_link-completions

run basher-install username/package@v1.2.3

assert_line "basher-_clone false github.com username/package v1.2.3"
}

@test "empty version is ignored" {
mock_command basher-_clone
mock_command basher-_deps
mock_command basher-_link-bins
mock_command basher-_link-man
mock_command basher-_link-completions

run basher-install username/package@

assert_line "basher-_clone false github.com username/package"
}

@test "doesn't fail" {
create_package username/package
mock_clone
Expand Down
12 changes: 12 additions & 0 deletions tests/basher-outdated.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ load test_helper
assert_success
assert_output username/outdated
}

@test "ignore packages checked out with a tag or ref" {
mock_clone
create_package username/tagged
basher-install username/tagged

create_command git 'if [ "$1" = "symbolic-ref" ]; then exit 128; fi'

run basher-outdated
assert_success
assert_output ""
}

0 comments on commit e683443

Please sign in to comment.