-
Notifications
You must be signed in to change notification settings - Fork 7
/
git-fetchpr
executable file
·46 lines (38 loc) · 911 Bytes
/
git-fetchpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e
usage() {
echo "
Usage: $(basename $0) [OPTIONS] <PR>
Fetch a pull-request from github
OPTIONS
-b <branch> Branch on which to checkout this pr
-r <remote> Use <remote>, otherwise uses fetchpr.remote from config
" 1>&$1;
exit $(($1 - 1));
}
OPT_BRANCH=
OPT_REMOTE=
args=0
while getopts "b:r:h" o; do
case "${o}" in
b) OPT_BRANCH=${OPTARG}; args=$[$args + 2] ;;
r) OPT_REMOTE=${OPTARG}; args=$[$args + 2] ;;
h) usage 1;;
\?) usage 2;;
esac
done
shift $args
find_remote() {
if [[ -n "$OPT_REMOTE" ]]; then
return
fi
OPT_REMOTE="$(git config --get fetchpr.remote)"
}
find_remote
pr=$1
if [[ -n "$OPT_BRANCH" ]] && git rev-parse --verify -q "$OPT_BRANCH"; then
echo "Branch $OPT_BRANCH already exists" >&2
exit 1
fi
git fetch $OPT_REMOTE refs/pull/$pr/head:$OPT_BRANCH