add fetch-gerrit-patch.sh, tweak READMEs

Change-Id: I6df4f3226af9087ef346de72cbcaa86a4d4d5e13
This commit is contained in:
Neels Hofmeyr 2017-09-04 04:32:21 +02:00
parent d3707d086c
commit f6402d8921
3 changed files with 87 additions and 0 deletions

5
README
View File

@ -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.

View File

@ -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

41
src/fetch-gerrit-patch.sh Executable file
View File

@ -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