From 8c8c41bd501070c9bd0d27b24d2bd84fc22fa100 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Thu, 13 Sep 2018 20:11:44 +0300 Subject: [PATCH] Support opening current tag / commit Fixes #89. Fixes #129. --- git-open | 4 ++-- test/git-open.bats | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/git-open b/git-open index 2e10b2a..d93a63d 100755 --- a/git-open +++ b/git-open @@ -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" diff --git a/test/git-open.bats b/test/git-open.bats index c070606..49128d5 100755 --- a/test/git-open.bats +++ b/test/git-open.bats @@ -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"