Support opening current tag / commit

Fixes #89.
Fixes #129.
This commit is contained in:
Orestis Floros 2018-09-13 20:11:44 +03:00
parent 5fefffede3
commit 8c8c41bd50
No known key found for this signature in database
GPG key ID: E9AD9F32E401E38F
2 changed files with 24 additions and 2 deletions

View file

@ -153,8 +153,8 @@ function getConfig() {
domain=$(getConfig "domain")
protocol=$(getConfig "protocol")
# Get current branch
branch=${2:-$(git symbolic-ref -q --short HEAD)}
# Get current branch / tag / commit
branch=${2:-$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match 2>/dev/null || git rev-parse HEAD)}
# Split arguments on '/'
IFS='/' read -r -a pathargs <<<"$urlpath"

View file

@ -65,6 +65,17 @@ setup() {
assert_output "https://github.com/user/repo/tree/mybranch"
}
@test "gh: tag" {
git remote set-url origin "git@github.com:user/repo.git"
git tag mytag
echo a > a
git add a
git commit -m a
git checkout mytag
run ../git-open
assert_output "https://github.com/user/repo/tree/mytag"
}
@test "gh: non-origin remote" {
git remote set-url origin "git@github.com:user/repo.git"
git remote add upstream "git@github.com:upstreamorg/repo.git"
@ -292,6 +303,17 @@ setup() {
assert_output --partial "https://bitbucket.org/paulirish/crbug-extension"
}
@test "bitbucket: tag" {
git remote set-url origin "git@bitbucket.org:paulirish/crbug-extension.git"
git tag mytag
echo a > a
git add a
git commit -m a
git checkout mytag
run ../git-open
assert_output "https://bitbucket.org/paulirish/crbug-extension/src?at=mytag"
}
@test "bitbucket: non-origin remote" {
# https://github.com/paulirish/git-open/pull/4
git remote add bbclone "git@bitbucket.org:rwhitbeck/git-open.git"