-
Notifications
You must be signed in to change notification settings - Fork 0
/
RP
executable file
·73 lines (64 loc) · 1.5 KB
/
RP
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
#!/bin/sh
# Replace patch series
usage="$0 branch [base-branch] <patchfile"
if test -d .dotest
then
echo >&2 "still in the middle of rebase/am"
exit 1
fi
case "$#,$1" in
1,--continue)
;;
*)
rm -f .rp-state
target_branch="$1"
case $# in
1)
base_branch=master
;;
2)
base_branch=$(git rev-parse --verify "$2") || exit
;;
*)
echo >&2 "$usage"
exit 1
;;
esac
# find branch point
branch_point=$(git merge-base "$base_branch" "$target_branch") || {
echo >&2 "failed to compute the branch point"
exit 1
}
# safety -- never rewind/replace what's merged to next
in_branch=$(git rev-list $branch_point..$target_branch) &&
not_in_next=$(git rev-list $branch_point..$target_branch ^next) &&
test "z$in_branch" = "z$not_in_next" || {
echo >&2 "should not be rewinding part of $target_branch that is already in next"
exit 1
}
# detach the HEAD
git checkout "$branch_point" || {
echo >&2 "detaching the head at $branch_point"
exit 1
}
{
echo "target_branch=$target_branch"
echo "branch_point=$branch_point"
} >.rp-state
# apply patches
git am -3 -s -u || {
echo >&2 "finish the am and say $0 --continue"
exit 1
}
;;
esac
branch_point=$(sed -ne 's/^branch_point=//p' .rp-state) &&
target_branch=$(sed -ne 's/^target_branch=//p' .rp-state) || {
echo >&2 "no replace-patch session"
exit 1
}
rm -f .rp-state
git branch -f "$target_branch" HEAD
git checkout "$target_branch"
git -p show-branch "$target_branch@{1}" "$target_branch"
git diff --stat -p "$target_branch@{1}" "$target_branch"