Projects STRLCPY git-open Commits 0564817a
🤬
  • Adding a --commit option.

    I've only tested this with gitlab seeing as I needed it there. If this could be useful I can integrate any feedback you might have to get this proposal merged.
  • Loading...
  • Domenico Gemoli committed 5 years ago
    0564817a
    1 parent 44382bf5
  • ■ ■ ■ ■ ■
    git-open
    skipped 15 lines
    16 16   https://github.com/paulirish/git-open/
    17 17   
    18 18   Available options are
     19 +c,commit! open current commit
    19 20  i,issue! open issues page
    20 21  p,print! just print the url
    21 22  "
    skipped 3 lines
    25 26  SUBDIRECTORY_OK='Yes' . "$(git --exec-path)/git-sh-setup"
    26 27   
    27 28  # Defaults
     29 +is_commit=0
    28 30  is_issue=0
    29 31  protocol="https"
    30 32  print_only=0
    31 33   
    32 34  while test $# != 0; do
    33 35   case "$1" in
     36 + --commit) is_commit=1;;
    34 37   --issue) is_issue=1;;
    35 38   --print) print_only=1;;
    36 39   --) shift; break ;;
    skipped 190 lines
    227 230   
    228 231  openurl="$protocol://$domain/$urlpath"
    229 232   
    230  -# simplify URL for master
    231  -if [[ $remote_ref != "master" ]]; then
     233 +if (( is_commit )); then
     234 + sha=$(git rev-parse HEAD)
     235 + openurl="$openurl/commit/$sha"
     236 +elif [[ $remote_ref != "master" ]]; then
     237 + # simplify URL for master
    232 238   openurl="$openurl$providerBranchRef"
    233 239  fi
    234 240   
    skipped 26 lines
  • ■ ■ ■ ■ ■ ■
    git-open.1.md
    skipped 2 lines
    3 3   
    4 4  ## SYNOPSIS
    5 5   
    6  -`git open` [--issue] [remote-name] [branch-name]
     6 +`git open` [--issue] [--commit] [remote-name] [branch-name]
    7 7   
    8 8   
    9 9  ## DESCRIPTION
    skipped 3 lines
    13 13   
    14 14   
    15 15  ## OPTIONS
     16 + 
     17 +`-c`, `--commit`
     18 + Open the current commit. See `EXAMPLES` for more information.
     19 + Only tested with GitHub & GitLab.
    16 20   
    17 21  `-i`, `--issue`
    18 22   Open the current issue. When the name of the current branch matches the right pattern,
    skipped 38 lines
    57 61  ```
    58 62   
    59 63  It prints the URL https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/
     64 + 
     65 +```sh
     66 +git open --commit
     67 +```
     68 + 
     69 +Supposing that the current sha is `2ddc8d4548d0cee3d714dcf0068dbec5b168a9b2`, it opens
     70 +https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/commit/2ddc8d4548d0cee3d714dcf0068dbec5b168a9b2
     71 + 
    60 72   
    61 73  ## SUPPORTED GIT HOSTING SERVICES
    62 74   
    skipped 82 lines
  • ■ ■ ■ ■ ■ ■
    test/git-open.bats
    skipped 159 lines
    160 160   assert_output "https://github.com/paulirish/git-open/issues/38"
    161 161  }
    162 162   
     163 +@test "gh: git open --commit" {
     164 + git remote set-url origin "github.com:paulirish/git-open.git"
     165 + sha=$(git rev-parse HEAD)
     166 + run ../git-open "--commit"
     167 + assert_output "https://github.com/paulirish/git-open/commit/${sha}"
     168 +}
     169 + 
    163 170  @test "gh: gist" {
    164 171   git remote set-url origin "[email protected]:2d84a6db1b41b4020685.git"
    165 172   run ../git-open
    skipped 522 lines
Please wait...
Page is in error, reload to recover