Neels Hofmeyr | f6402d8 | 2017-09-04 04:32:21 +0200 | [diff] [blame] | 1 | #!/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 | |
| 14 | patch="$1" |
| 15 | |
| 16 | if [ -z "$patch" ]; then |
| 17 | echo "Usage: $0 1234[/5]" |
| 18 | exit 1 |
| 19 | fi |
| 20 | |
| 21 | if [ -z "$(echo "$patch" | grep '/')" ]; then |
| 22 | patch="/$patch/" |
| 23 | fi |
| 24 | |
| 25 | if [ -z "$(echo "$patch" | grep '^/')" ]; then |
| 26 | patch="/$patch" |
| 27 | fi |
| 28 | |
| 29 | last_set="$(git ls-remote origin "changes/*" | grep "$patch" | sed 's#.*/\([^/]*\)$#\1 &#' | sort -n | tail -n 1)" |
| 30 | if [ -z "$last_set" ]; then |
| 31 | echo "Not found: $patch" |
| 32 | exit 1 |
| 33 | fi |
| 34 | |
| 35 | change_name="$(echo "$last_set" | sed 's/.*\(refs.*\)/\1/')" |
| 36 | branch_name="$(echo "$change_name" | sed 's#refs/changes/../\([0-9]*\)/\([0-9]*\)#\1_\2#')" |
| 37 | |
| 38 | set -x |
| 39 | git fetch origin "$change_name" |
| 40 | git checkout -b "$branch_name" FETCH_HEAD |
| 41 | |