Skip to content

Instantly share code, notes, and snippets.

@jbalogh
Forked from davedash/gist:382311
Created April 28, 2010 19:28
Show Gist options
  • Save jbalogh/382581 to your computer and use it in GitHub Desktop.
Save jbalogh/382581 to your computer and use it in GitHub Desktop.
git-url: helps you close bugs good
#!/bin/sh
# Usage: `git url` or `git url <commitish>`
#
# * copies the commit's github url to your clipboard
# * prints out the log message
# * opens the bugzilla page if it found a bug number
#
# Set up the github url with `git config github.url <url>`.
# Only for the Mac.
if [[ $1 ]]; then
REV=$1
else
REV='HEAD'
fi
if [ $(git config github.url) ]; then
ROOT=$(git config github.url)
else
ROOT=$(git config remote.origin.url | perl -pi -e 's%^.*:(.*).git%https://github.com/\1/commit%')
fi
BUGZILLA='https://bugzilla.mozilla.org/show_bug.cgi?id='
HASH=$(git rev-parse --short $REV)
MSG=$(git log --pretty=oneline --format=%s -1 $HASH)
BUG=$(echo $MSG | ack -i 'bug (\d+)' --output='$1')
echo $ROOT/$HASH '\c' | pbcopy
echo $MSG
# Open the browser if we found a bug number.
if [[ $BUG ]]; then
open $BUGZILLA$BUG
fi
@fwenzel
Copy link

fwenzel commented Jun 16, 2010

With a commit msg like this: fixed something (bug 571385 and bug 570776), There's an error message in the open call: The file .../570776 does not exist.

@jbalogh
Copy link
Author

jbalogh commented Jun 16, 2010

Patches welcome! You could do | head -1 on the $BUG, but that's kind of lame. Opening both bugs would be cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment