Skip to content

Commit 4ca1990

Browse files
authored
Merge pull request #130 from orestisf1993/tags-commits
Support opening current tag / commit
2 parents 5fefffe + 8c8c41b commit 4ca1990

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

git-open

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ function getConfig() {
153153
domain=$(getConfig "domain")
154154
protocol=$(getConfig "protocol")
155155

156-
# Get current branch
157-
branch=${2:-$(git symbolic-ref -q --short HEAD)}
156+
# Get current branch / tag / commit
157+
branch=${2:-$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match 2>/dev/null || git rev-parse HEAD)}
158158

159159
# Split arguments on '/'
160160
IFS='/' read -r -a pathargs <<<"$urlpath"

test/git-open.bats

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ setup() {
6565
assert_output "https://github.com/user/repo/tree/mybranch"
6666
}
6767

68+
@test "gh: tag" {
69+
git remote set-url origin "[email protected]:user/repo.git"
70+
git tag mytag
71+
echo a > a
72+
git add a
73+
git commit -m a
74+
git checkout mytag
75+
run ../git-open
76+
assert_output "https://github.com/user/repo/tree/mytag"
77+
}
78+
6879
@test "gh: non-origin remote" {
6980
git remote set-url origin "[email protected]:user/repo.git"
7081
git remote add upstream "[email protected]:upstreamorg/repo.git"
@@ -292,6 +303,17 @@ setup() {
292303
assert_output --partial "https://bitbucket.org/paulirish/crbug-extension"
293304
}
294305

306+
@test "bitbucket: tag" {
307+
git remote set-url origin "[email protected]:paulirish/crbug-extension.git"
308+
git tag mytag
309+
echo a > a
310+
git add a
311+
git commit -m a
312+
git checkout mytag
313+
run ../git-open
314+
assert_output "https://bitbucket.org/paulirish/crbug-extension/src?at=mytag"
315+
}
316+
295317
@test "bitbucket: non-origin remote" {
296318
# https://github.com/paulirish/git-open/pull/4
297319
git remote add bbclone "[email protected]:rwhitbeck/git-open.git"

0 commit comments

Comments
 (0)