From 2ca8cf9f7e5bdeee12f919cf7da50814ef846048 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 9 Oct 2020 11:13:22 +0200 Subject: [PATCH] Add a './g review' script to trigger CI for a commit in an easy way Similar to gerrit's 'git review' which creates/updates a change without clicking anywhere in a browser. Also add a './g pull' to help those who are used to that. Change-Id: I240ff55c7480d0a2cd6de3f2ea3cd84ca0556af4 --- g | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 g diff --git a/g b/g new file mode 100755 index 000000000..fc35acacc --- /dev/null +++ b/g @@ -0,0 +1,38 @@ +#!/bin/bash -e +# +# './g pull -r' just forwards to 'git pull -r'. +# +# './g review' to submit a pull request, assuming: +# 1) You have 'gh' installed. +# 2) You are a committer, so you have the permission to push to a private/nick/name branch. +# 3) You delete this branch after the PR is merged. +# + +if [ "$1" == "review" ]; then + if [ -z "$(type -p gh)" ]; then + echo "'gh' not found, install it from ." + exit 1 + fi + + BRANCH=$(git symbolic-ref HEAD|sed 's|refs/heads/||') + REMOTE=$(git config branch.$BRANCH.remote) + if git rev-parse --quiet --verify $REMOTE/private/$USER/$BRANCH >/dev/null; then + # PR is open, just update it. + git push -f $REMOTE HEAD:private/$USER/$BRANCH + else + # Open a new PR. + git push $REMOTE HEAD:private/$USER/$BRANCH + git branch private/$USER/$BRANCH + gh pr create --base $BRANCH --head private/$USER/$BRANCH --fill + git branch -D private/$USER/$BRANCH + fi + exit 0 +fi + +if [ "$1" == "pull" ]; then + shift + git pull "$@" + exit 0 +fi + +# vim:set shiftwidth=4 softtabstop=4 expandtab: