From f6402d8921f05f0417dbdebc4e89cf8d8e5e7c98 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Mon, 4 Sep 2017 04:32:21 +0200 Subject: [PATCH] add fetch-gerrit-patch.sh, tweak READMEs Change-Id: I6df4f3226af9087ef346de72cbcaa86a4d4d5e13 --- README | 5 +++++ src/README | 41 +++++++++++++++++++++++++++++++++++++++ src/fetch-gerrit-patch.sh | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100755 src/fetch-gerrit-patch.sh diff --git a/README b/README index a3ab68f..65dbf2e 100644 --- a/README +++ b/README @@ -52,3 +52,8 @@ configurations, see the command line options of ./gen_makefile.py. Remove osmocom built binaries and headers from given prefix, default is /usr/local. + + +=== src/* + +Find other useful scripts in src/, see src/README. diff --git a/src/README b/src/README index 4444824..a2fbe81 100644 --- a/src/README +++ b/src/README @@ -2,6 +2,15 @@ This dir is intended to keep all the git clones. There are some handy scripts I use for my daily Osmocom development: + osmo-add-gerrit-hooks.sh + Look for git repositories in and below the current dir and install the + gerrit commit-msg hook in each one. This requires an ~/.ssh/config + entry, see top comment in the script. + + fetch-gerrit-patch.sh + Pass a patch number seen on gerrit to fetch the latest patch set into + your git clone. See top comment in the script. + ./g run a git command in each source tree ./e run an arbitrary shell command in each source tree ./st show a brief branch and local mods status for each source tree @@ -11,6 +20,38 @@ There are some handy scripts I use for my daily Osmocom development: Examples: + +----------------------------------------------------------------------------- + +git clone ssh://go/osmo-msc + +./osmo-add-gerrit-hooks.sh ++ cd /n/s/osmo/src/./osmo-msc/.git ++ [ ! -f hooks/commit-msg ] ++ scp go:hooks/commit-msg hooks/ +commit-msg 100% 4688 4.6KB/s 00:00 + + +----------------------------------------------------------------------------- + + +cd osmo-msc +../fetch-gerrit-patch.sh 3787 ++ git fetch origin refs/changes/87/3787/2 +From ssh://go/osmo-msc + * branch refs/changes/87/3787/2 -> FETCH_HEAD ++ git checkout -b 3787_2 FETCH_HEAD +Switched to a new branch '3787_2' + + +# or if you want an earlier patch set +../fetch-gerrit-patch.sh 3787/1 +From ssh://go/osmo-msc + * branch refs/changes/87/3787/1 -> FETCH_HEAD ++ git checkout -b 3787_1 FETCH_HEAD +Switched to a new branch '3787_1' + + ----------------------------------------------------------------------------- ./g fetch # run 'git fetch' in each clone = fetch all from upstream diff --git a/src/fetch-gerrit-patch.sh b/src/fetch-gerrit-patch.sh new file mode 100755 index 0000000..0353461 --- /dev/null +++ b/src/fetch-gerrit-patch.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# fetch gerrit patch into new branch named like the patch number. +# +# Usage: go to a git clone and pass a patch number: +# +# cd osmo-msc +# P 973 +# or +# P 973/2 +# +# Will create new local branches '973_4' (if 4 is the latest patch set) +# or '973_2', respectively. + +patch="$1" + +if [ -z "$patch" ]; then + echo "Usage: $0 1234[/5]" + exit 1 +fi + +if [ -z "$(echo "$patch" | grep '/')" ]; then + patch="/$patch/" +fi + +if [ -z "$(echo "$patch" | grep '^/')" ]; then + patch="/$patch" +fi + +last_set="$(git ls-remote origin "changes/*" | grep "$patch" | sed 's#.*/\([^/]*\)$#\1 &#' | sort -n | tail -n 1)" +if [ -z "$last_set" ]; then + echo "Not found: $patch" + exit 1 +fi + +change_name="$(echo "$last_set" | sed 's/.*\(refs.*\)/\1/')" +branch_name="$(echo "$change_name" | sed 's#refs/changes/../\([0-9]*\)/\([0-9]*\)#\1_\2#')" + +set -x +git fetch origin "$change_name" +git checkout -b "$branch_name" FETCH_HEAD +