Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [`git archive-file`](#git-archive-file)
- [`git authors`](#git-authors)
- [`git browse`](#git-browse)
- [`git browse-ci`](#git-browse-ci)
- [`git bulk`](#git-bulk)
- [`git brv`](#git-brv)
- [`git changelog`](#git-changelog)
Expand Down Expand Up @@ -1502,6 +1503,19 @@ Opens the current git repository website in your default web browser.

```bash
$ git browse

$ git browse upstream
```

## git browse-ci

Opens the current git repository CI website (e.g. GitHub Actions, GitLab CI,
Bitbucket Pipelines) in your default web browser.

```bash
$ git browse-ci

$ git browse-ci upstream
```

## git utimes
Expand Down
65 changes: 65 additions & 0 deletions bin/git-browse-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

set -e -o pipefail
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get 128 exit code when no upstream is given after this modification...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be the combination of set -e and git rev-parse --abbrev-ref HEAD 2&> /dev/null (specifically the 2&> /dev/null).

Changing it to the shorthand version &> /dev/null or the longhand version >/dev/null 2>&1 fixes it for me.

if [[ $1 == "" ]]
then
branch=$(git rev-parse --abbrev-ref HEAD &> /dev/null)
remote=$(git config branch."${branch}".remote || echo "origin")
else
remote=$1
fi

if [[ $remote == "" ]]
then
echo "Remote not found"
exit 1
fi

remote_url=$(git remote get-url "${remote}")

if [[ $? -ne 0 ]]
then
exit $?
fi

if [[ $remote_url = git@* ]]
then
url=$(echo "${remote_url}" | sed -E -e 's/:/\//' -e 's/\.git$//' -e 's/.*@(.*)/http:\/\/\1/')
elif [[ $remote_url = http* ]]
then
url=${remote_url%.git}
fi

if [[ $url =~ github ]]
then
ci_url=${url}/actions
elif [[ $url =~ gitlab ]]
then
ci_url=${url}/-/pipelines
elif [[ $url =~ bitbucket ]]
then
ci_url=${url}/addon/pipelines/home
fi
case "$OSTYPE" in
darwin*)
# MacOS
open "${ci_url}"
;;
msys)
# Git-Bash on Windows
start "${ci_url}"
;;
linux*)
# Handle WSL on Windows
if uname -a | grep -i -q Microsoft
then
powershell.exe -NoProfile start "${ci_url}"
else
xdg-open "${ci_url}"
fi
;;
*)
# fall back to xdg-open for BSDs, etc.
xdg-open "${ci_url}"
;;
esac
4 changes: 4 additions & 0 deletions etc/bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,7 @@ _git_info(){
_git_browse(){
__git_complete_remote_or_refspec
}

_git_browse_ci(){
__git_complete_remote_or_refspec
}
1 change: 1 addition & 0 deletions etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
archive-file:'export the current head of the git repository to an archive' \
authors:'generate authors report' \
browse:'open repo website in browser' \
browse-ci:'open repo CI page in browser' \
bug:'create bug branch' \
bulk:'run bulk commands' \
brv:'list branches sorted by their last commit date'\
Expand Down
1 change: 1 addition & 0 deletions etc/git-extras.fish
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set __fish_git_extras_commands \
"archive-file:Export the current HEAD of the git repository to an archive" \
"authors:Generate authors report" \
"browse:View the web page for the current repository" \
"browse-ci:View the CI page for the current repository" \
"brv:List branches sorted by their last commit date" \
"bulk:Run git commands on multiple repositories" \
"changelog:Generate a changelog report" \
Expand Down
34 changes: 34 additions & 0 deletions man/git-browse-ci.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-BROWSE\-CI" "1" "March 2022" "" "Git Extras"
.
.SH "NAME"
\fBgit\-browse\-ci\fR \-
.
.SH "SYNOPSIS"
\fBgit\-browse\-ci\fR [remote_name]
.
.SH "DESCRIPTION"
Opens the current git repository CI page in your default web browser\.
.
.SH "OPTIONS"
<remote_name>
.
.P
The name of the remote you wish to browse to\. Defaults to the first remote if not specified\.
.
.SH "EXAMPLES"
$ git browse\-ci
.
.P
$ git browse\-ci upstream
.
.SH "AUTHOR"
Written by Peter Benjamin <\fIhttps://github\.com/pbnj\fR>
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>
119 changes: 119 additions & 0 deletions man/git-browse-ci.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions man/git-browse-ci.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
git-browse-ci(1) -- <View the web page for the current repository>
================================

## SYNOPSIS

`git-browse-ci` [remote_name]

## DESCRIPTION

Opens the current git repository CI page in your default web browser.

## OPTIONS

&lt;remote_name&gt;

The name of the remote you wish to browse to. Defaults to
the first remote if not specified.

## EXAMPLES

$ git browse-ci

$ git browse-ci upstream

## AUTHOR

Written by Peter Benjamin &lt;<https://github.com/pbnj>&gt;

## REPORTING BUGS

&lt;<https://github.com/tj/git-extras/issues>&gt;

## SEE ALSO

&lt;<https://github.com/tj/git-extras>&gt;
1 change: 1 addition & 0 deletions man/git-extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ git-extras(1) -- Awesome GIT utilities
- **git-alias(1)** Define, search and show aliases
- **git-archive-file(1)** Export the current HEAD of the git repository to an archive
- **git-authors(1)** Generate authors report
- **git-browse-ci(1)** <View the web page for the current repository>
- **git-browse(1)** <View the web page for the current repository>
- **git-brv(1)** List branches sorted by their last commit date
- **git-bulk(1)** Run git commands on multiple repositories
Expand Down
1 change: 1 addition & 0 deletions man/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ git-abort(1) git-abort
git-alias(1) git-alias
git-archive-file(1) git-archive-file
git-authors(1) git-authors
git-browse-ci(1) git-browse-ci
git-browse(1) git-browse
git-brv(1) git-brv
git-bulk(1) git-bulk
Expand Down