Debian Codegraph @

admin/pr_as_branch

raw
1 #!/bin/sh
2
3 set -e
4 set -u
5
6
7 # Usage
8
9 usage() {
10 program=$(basename "$0");
11
12 if [ $# != 0 ]; then echo "$@"; echo ""; fi;
13
14 echo "${program}: usage:";
15 echo " ${program} pull_request_number trac_ticket_number branch_name";
16 echo "";
17 echo "Note: branch_name should not include the ticket number prefix; that ";
18 echo "will be added automatically.";
19 echo "";
20 echo "${program} creates a branch in the Twisted GitHub repository from a";
21 echo "forked pull request. This is necessary in order to create a branch";
22 echo "that is visible to the Buildbot-based builder infrastructure.";
23 }
24
25
26 # Options
27
28 while [ $# != 0 ]; do
29 case "$1" in
30 --help)
31 usage;
32 exit 0;
33 ;;
34 --|*) break; ;;
35 esac;
36 done;
37
38 if [ $# != 3 ]; then
39 usage "Invalid arguments: $*";
40 exit 1;
41 fi;
42
43 PR_NUMBER="$1"; shift;
44 TICKET_NUMBER="$1"; shift;
45 BRANCH_NAME="$1"; shift;
46
47
48 # Do The Right Thing
49
50 #repo="https://github.com/twisted/twisted.git";
51 repo="[email protected]:twisted/twisted.git";
52
53 wc="$(dirname "$(dirname "$0")")/.git";
54
55 if [ ! -d "${wc}" ]; then
56 wc="$(mktemp -d -t twisted.XXXX)";
57
58 git clone --depth 1 --progress "${repo}" "${wc}";
59
60 cloned=true;
61 else
62 cloned=false;
63 fi;
64
65 cd "${wc}";
66
67 git fetch origin "refs/pull/${PR_NUMBER}/head";
68 git push origin "FETCH_HEAD:refs/heads/${TICKET_NUMBER}-${BRANCH_NAME}";
69
70 if ${cloned}; then
71 rm -fr "${wc}";
72 fi;