forked from nod/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpullr.sh
More file actions
81 lines (77 loc) · 2.34 KB
/
pullr.sh
File metadata and controls
81 lines (77 loc) · 2.34 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Nixon's pull request acceptance process
#
# once a pull request has been reviewed and the changes look good, bring
# the pull request branch into your local repo and run "fab test" to
# make sure that the pull request doesn't conflict with other changes on
# the master branch.
#
# Usage:
#
# Create a local branch and run testcases:
#
# pullr <pull-request-#> [ -d | -s]
#
# If all the testcases pass, run "delp" to remove the pull request
# branch.
#
# Side effects:
#
# pullr will pull in all upstream changes into your master branch
#
# Requirements:
#
# git://github.com/nixon/github-gem.git
# git://github.com/nixon/git-pulls.git
#
# Bugs:
#
# If "-d" is used with pullr and there are conflicts when merging in
# the pull request branch, the pull request branch will be deleted
# instead of recognizing the conflict as an error condition.
#
function delp {
# delete git pull request branch
br=$(git branch | awk '$1=="*" {print $2; exit}')
if ! echo "$br" | egrep -q '^pull-[0-9]+$'; then
echo "\"$br\" is not a pull request branch" >&2
return 1
fi
git reset --hard # clean up branch in case of merge conflicts, etc
git checkout master
git branch -D "$br"
}
function gitdir_top {
w=$(git rev-parse --git-dir)
if [[ -n $w ]] ; then
echo "$w/.."
fi
}
function git_upstream {
# which remote name represents the current repo's upstream
# if there's one named "upstream" pick that one, otherwise, default
# to "origin".
git remote | fgrep upstream || echo origin
}
function pullr {
# pullr : run tests against a pull request
# given a pull request number, merge the pull request with master,
# and run testcases. when finished, if all tests pass, optionally
# remove the pull request branch.
pullreq=${1?}
command=$2 # -s to skip tests, -d to delete branch after tests.
(cd $(gitdir_top) && # git pulls has to be done at the top
git co master && # make sure we're on master
git pull $(git_upstream) master && # make sure we're up-to-date
git pulls update &&
out=$(gh fetch-pull $pullreq merge)
echo "$out"
if [[ $command != "-s" ]] ; then
echo $out | fgrep -q CONFLICT || fab test
fi)
rc=$?
if [[ $rc -eq 0 ]] && [[ "$command" == "-d" ]] ; then
delp
rc=$?
fi
return $rc
}