-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpurq
More file actions
executable file
·120 lines (98 loc) · 2.85 KB
/
purq
File metadata and controls
executable file
·120 lines (98 loc) · 2.85 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
# Examine a pull request or branch, comparing it to your master branch.
# Will stash your current work and restore when you're done.
#
# Usage: $0 <pull request #> <remote = upstream>
#
MASTER=master
# People using overly complicated branching models
# often use "develop" or "dev" as their master
for b in {develop,dev}; do
git branch | grep -q " $b$"
if [ $? -eq 0 ]; then
MASTER=$b
fi
done
# Here's where you set your diff'ing tool:
#
# If you don't have a tool ready, use this; it will display a list of files
# that differ and then just drop you into a child shell so you can examine
# changes manually; when you exit the shell your state will be restored.
DIFF_CMD="git diff --name-status %s; bash"
#
# This is my vim branch diffing tool; change it if you like.
my_diff () {
mtron >/tmp/mtron.log 2>&1 &
vim "+call Gbdiff(\"$1\")"
}
my_cleanup () {
ALREADY_RUNNING="$(ps u | grep tagphp | grep -v grep)"
if [ -z "$ALREADY_RUNNING" ]; then
tagphp >/dev/null 2>&1
fi
}
DIFF_CMD="my_diff %s"
CLEANUP_CMD="my_cleanup &"
if [ -z "$1" ]; then
echo "Please provide the pull request number as the first argument."
exit
fi
if [ -n "$2" ]; then
REMOTE="$2"
else
REMOTE=upstream
fi
# Check remote name, grab info
REPO="$(git remote -v | grep "^$REMOTE " | head -n 1 | sed 's/.*\t//' | sed 's/ (.*)//')"
if [ -z "$REPO" ]; then
echo "Unknown remote \"$REMOTE\"!"
exit 1
fi
# Save whatever you're working on
GIT_STASH=$(git status --porcelain)
if [ -n "$GIT_STASH" ]; then
echo -n "Stashing current state..."
git stash save --include-untracked > /dev/null
echo " Stashed."
fi
ON_BRANCH=$(git branch | grep '^* ' | sed 's/^* //')
# This will restore it when finished here
on_exit () {
echo "Switching back to $ON_BRANCH..."
git checkout "$ON_BRANCH"
if [ -n "$GIT_STASH" ]; then
echo "Restoring stash..."
git stash pop > /dev/null
fi
if [ -n "$TEMP_BRANCH" ]; then
git branch -D "$TEMP_BRANCH"
fi
eval "$CLEANUP_CMD"
}
trap on_exit EXIT
TEMP_BRANCH="PR-$1"
echo -n "Fetching remote revisions..."
git fetch "$REPO" refs/pull/$1/head:$TEMP_BRANCH >/dev/null 2>&1
echo " Fetched."
if [ $? -ne 0 ]; then
echo "git fetch "$REPO" refs/pull/$1/head:$TEMP_BRANCH failed."
exit 1
fi
git checkout $TEMP_BRANCH
if [ $? -ne 0 ]; then
echo "git checkout $TEMP_BRANCH failed."
exit 1
fi
MERGE_BASE="$(git merge-base HEAD $MASTER)"
PR_MERGES="$(git log --pretty=oneline $MERGE_BASE..HEAD | grep "[a-f0-9]\{40\} Merge pull request #")"
if [ -n "$PR_MERGES" ]; then
echo "Looks like you need to rebase... this PR's merge base is not in your $MASTER branch."
exit 1
fi
# TODO: We can add support for diffing merged PRs here if we use this command:
# git show :/^Merge
# to set the base to the last merge instead of the merge-base with $MASTER
# (which is effectively HEAD)
echo "Launching diff'er..."
eval $(printf "$DIFF_CMD" "$(git merge-base HEAD $MASTER)")
exit 0