Skip to content
Snippets Groups Projects
Commit f93a5ffb authored by Vivien Didelot's avatar Vivien Didelot Committed by Gerrit Code Review
Browse files

tools: add Gerrit/Redmine utilities for Git

This commit adds two dev scripts, intended to be used with Git. They
allow easy interaction with Gerrit (using the commit change ID) and
Redmine (using the issue reference).

Usage examples:

    # Copy Gerrit change URL of HEAD, for later pasting
    git gerrit url | xclip

    # Open Gerrit in a web browser for the parent commit
    git gerrit open HEAD^

    # Fetch the last version corresponding to a commit
    git gerrit fetch 2460d160

    # Open Redmine issue related to the current commit
    git redmine open

These scripts may be used directly:

    ./tools/git-gerrit

or installed as a Git subcommand (recommended):

    git config alias.gerrit '!tools/git-gerrit'
    git config alias.redmine '!tools/git-redmine'

The configuration is managed through git config. Running these scripts
with missing configuration (e.g. host, port) will prompt the setup.

Note on global usage: optionally, you can specify the global path of
these scripts, or add them to your $PATH, in order to use them in any
repo, and eventually have global settings, like:

    git config --global redmine.url https://...

Change-Id: Ie8530fd03e00452075ab045b278923d03d0ead20
parent 15ff9184
No related branches found
No related tags found
No related merge requests found
#!/bin/sh
#
# Copyright 2014 Savoir-Faire Linux Inc.
# Author: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
# Licensed under the terms of the GNU GPL v3, or at your option, any later version.
#
# You can install this script as a Git subcommand with one of the 2 methods below:
#
# 1) git config alias.gerrit '!tools/git-gerrit'
# 2) or put this script in your $PATH
usage () {
echo "Usage:"
echo " $0 <url|open|fetch> [<git-rev>]"
echo " $0 help"
echo
echo "Examples:"
echo " git gerrit open"
echo " git gerrit url HEAD~2"
echo " git gerrit fetch ; git diff FETCH_HEAD"
}
test $# -ge 1 -a $# -le 2 || {
echo "Invalid syntax."
usage
exit 1
}
test "$1" = "help" && {
usage
exit
}
GERRIT_USER=`git config gerrit.user`
GERRIT_HOST=`git config gerrit.host`
GERRIT_PORT=`git config gerrit.port`
test -n "$GERRIT_USER" -a -n "$GERRIT_HOST" -a -n "$GERRIT_PORT" || {
echo "You must configure your Gerrit host, e.g.:"
echo
echo " git config gerrit.user vivien"
echo " git config gerrit.host gerrit-sflphone.savoirfairelinux.com"
echo " git config gerrit.port 29420"
echo
exit 1
}
alias _gerrit="ssh -p $GERRIT_PORT $GERRIT_HOST gerrit query"
CHANGE_ID=`git show --summary --format=%b $2 | perl -n -e '/^Change-Id: (I[0-9a-f]+)$/ && print $1'`
test -n "$CHANGE_ID" || {
echo "no Change ID!"
exit 1
}
test "$1" = "fetch" && {
GERRIT_REMOTE=`git config gerrit.remote`
test -n "$GERRIT_REMOTE" || {
echo "You must specify the Git remote pointing to Gerrit, e.g.:"
echo
echo " git config gerrit.remote origin"
echo
exit 1
}
_gerrit --current-patch-set $CHANGE_ID | awk '/ref:/ { print $2 }' | while read ref ; do
git fetch $GERRIT_REMOTE $ref:$ref
done
exit
}
URL=`_gerrit $CHANGE_ID | awk '/url:/ { print $2 }'`
case $1 in
url) echo $URL ;;
open) xdg-open $URL ;;
*) echo "Oops, bad command" ; usage ; exit 1 ;;
esac
exit
#!/bin/sh
#
# Copyright 2014 Savoir-Faire Linux Inc.
# Author: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
# Licensed under the terms of the GNU GPL v3, or at your option, any later version.
#
# You can install this script as a Git subcommand with one of the 2 methods below:
#
# 1) git config alias.redmine '!tools/git-redmine'
# 2) or put this script in your $PATH
usage () {
echo "Usage:"
echo " $0 <url|open> [<git-rev>]"
echo " $0 help"
echo
echo "Examples:"
echo " git redmine open # open the Redmine ticket related to the current commit"
echo " git redmine url HEAD~2"
}
test $# -ge 1 -a $# -le 2 || {
echo "Invalid syntax."
usage
exit 1
}
test "$1" = "help" && {
usage
exit
}
REDMINE_URL=`git config redmine.url`
test -n "$REDMINE_URL" || {
echo "You must configure your Redmine URL, e.g.:"
echo
echo " git config redmine.url https://projects.savoirfairelinux.com"
echo
exit 1
}
ISSUE=`git show --summary --format=%b $2 | perl -n -e '/^(Refs|Issue:) #(\d+)$/ && print $2'`
test -n "$ISSUE" || {
echo "no issue ID!"
exit 1
}
URL=$REDMINE_URL/issues/$ISSUE
case $1 in
url) echo $URL ;;
open) xdg-open $URL ;;
*) echo "Oops, bad command" ; usage ; exit 1 ;;
esac
exit
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment