blob: 035346159dc59ca390009224658eb617442745a4 [file] [log] [blame]
Neels Hofmeyrf6402d82017-09-04 04:32:21 +02001#!/bin/sh
2# fetch gerrit patch into new branch named like the patch number.
3#
4# Usage: go to a git clone and pass a patch number:
5#
6# cd osmo-msc
7# P 973
8# or
9# P 973/2
10#
11# Will create new local branches '973_4' (if 4 is the latest patch set)
12# or '973_2', respectively.
13
14patch="$1"
15
16if [ -z "$patch" ]; then
17 echo "Usage: $0 1234[/5]"
18 exit 1
19fi
20
21if [ -z "$(echo "$patch" | grep '/')" ]; then
22 patch="/$patch/"
23fi
24
25if [ -z "$(echo "$patch" | grep '^/')" ]; then
26 patch="/$patch"
27fi
28
29last_set="$(git ls-remote origin "changes/*" | grep "$patch" | sed 's#.*/\([^/]*\)$#\1 &#' | sort -n | tail -n 1)"
30if [ -z "$last_set" ]; then
31 echo "Not found: $patch"
32 exit 1
33fi
34
35change_name="$(echo "$last_set" | sed 's/.*\(refs.*\)/\1/')"
36branch_name="$(echo "$change_name" | sed 's#refs/changes/../\([0-9]*\)/\([0-9]*\)#\1_\2#')"
37
38set -x
39git fetch origin "$change_name"
40git checkout -b "$branch_name" FETCH_HEAD
41