blob: 2ba5ec4c7d8f20d82f9b5d7458d8e77d6c8ddec6 (
plain) (
blame)
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
|
#!/bin/bash
set -eu
if [ $# -lt 1 ] ; then
STR="$(cat)"
else
echo "No options yet!"
exit 1
fi
# 1. Collect URL of the incoming repo
URL="$(echo "$STR" | sed -n -e '/^are available in the Git repository at:/,+2 {
s/[[:space:]]\+//
s/\(=[[:digit:]]\{2\}\)\+$//
/^\(http\|git\)/p
}')"
# mapfile -t -c 1 -C 'cb() { [[ "$2" =~ (git|http|ssh):// ]] && printf "%s\n" "$2"; }; cb' URLS <<<"$STR"
# echo "$URLS[@]"
# 2. Check it is in our remotes
mapfile REMOTES < <(git remote -v|awk '{print $1,$2;}')
REMOTE=''
for rem in "${REMOTES[@]}" ; do
if [[ ${rem} =~ $URL ]] ; then
REMOTE="$(echo "${rem}" | awk -F ' ' '{print $1;}' )"
break
fi
done
# 4. Create new branch
BEG="$(echo "$STR" | awk '/^The following changes since commit / { print $NF }' | sed -e 's/[=:]*$//')"
END="$(echo "$STR" | awk '/^for you to fetch changes up to / { print $NF }' | sed -e 's/[=:]*$//')"
# 5. Fetch the remote
if [[ -n "$REMOTE" ]] ; then
git fetch $REMOTE $END
else
git fetch $URL $END
fi
git checkout -b _4review FETCH_HEAD
|