experimental/documentation/gerrit.md: more tricks
authorHal Canary <halcanary@google.com>
Mon, 15 May 2017 20:16:42 +0000 (16:16 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 15 May 2017 20:21:36 +0000 (20:21 +0000)
NOTRY=true
Change-Id: I04d371b16f7805b4c972010a5bc1eebd979169a6
Reviewed-on: https://skia-review.googlesource.com/16915
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>

experimental/documentation/gerrit.md

index e3aa775..7767c8c 100644 (file)
@@ -122,4 +122,18 @@ These shell scripts can be turned into Git aliases with a little hack:
 
     git config alias.gerrit-push-message '!f(){ git push origin @:refs/for/master%m=$(echo $*|sed "s/[^A-Za-z0-9]/_/g");};f'
 
+If your branch's upstream branch (set with `git branch --set-upstream-to=...`)
+is set, you can use that to automatically push to that branch:
+
+    gerrit_push_upstream() {
+        local UPSTREAM="$(git rev-parse --abbrev-ref --symbolic-full-name @{u})"
+        local REMOTE="${UPSTREAM%%/*}"
+        local REMOTE_BRANCH="${UPSTREAM#*/}"
+        local MESSAGE="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')"
+        git push "$REMOTE" "@:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}"
+    }
+
+As a Git alias:
+
+    git config alias.gerrit-push-upstream '!f()(U="$(git rev-parse --abbrev-ref --symbolic-full-name @{u})";R="${U%%/*}";B="${U#*/}";M="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')";git push "$R" "@:refs/for/${B}%m=$M");f'