aboutsummaryrefslogtreecommitdiffstats
path: root/git-req.sh
blob: 5c86116359f0dc3627309e5b521dabb1ad789dde (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
#!/bin/bash
set -eux

[ "$#" -lt 1 ] && exit 1

req_no="$1"

if ! git rev-parse --git-dir >/dev/null 2>&1 ; then
    echo "Must be run from git repo checkout."
    exit 2
fi

repo_url="$(git config --get remote.origin.url)"
if [[ "${repo_url}" =~ gitlab ]] ; then
    rem_ref_name="merge-requests"
    loc_ref_name="mr"
else
    rem_ref_name="pull"
    loc_ref_name="pr"
fi

git fetch origin refs/"$rem_ref_name"/"$req_no"/head:"$loc_ref_name"/"$req_no"
git checkout "$loc_ref_name/$req_no"