]> git.ipfire.org Git - thirdparty/git.git/blame - RP
What's cooking (2024/01 #09)
[thirdparty/git.git] / RP
CommitLineData
5c031573
JH
1#!/bin/sh
2# Replace patch series
3
4usage="$0 branch [base-branch] <patchfile"
5
6if test -d .dotest
7then
8 echo >&2 "still in the middle of rebase/am"
9 exit 1
10fi
11
12case "$#,$1" in
131,--continue)
14 ;;
15*)
16 rm -f .rp-state
17 target_branch="$1"
18 case $# in
19 1)
20 base_branch=master
21 ;;
22 2)
c6d71b2d 23 base_branch=$(git rev-parse --verify "$2") || exit
5c031573
JH
24 ;;
25 *)
26 echo >&2 "$usage"
27 exit 1
28 ;;
29 esac
30
31 # find branch point
32 branch_point=$(git merge-base "$base_branch" "$target_branch") || {
33 echo >&2 "failed to compute the branch point"
34 exit 1
35 }
36
37 # safety -- never rewind/replace what's merged to next
38 in_branch=$(git rev-list $branch_point..$target_branch) &&
39 not_in_next=$(git rev-list $branch_point..$target_branch ^next) &&
40 test "z$in_branch" = "z$not_in_next" || {
41 echo >&2 "should not be rewinding part of $target_branch that is already in next"
42 exit 1
43 }
44
45 # detach the HEAD
46 git checkout "$branch_point" || {
47 echo >&2 "detaching the head at $branch_point"
48 exit 1
49 }
50
51 {
52 echo "target_branch=$target_branch"
53 echo "branch_point=$branch_point"
54 } >.rp-state
55 # apply patches
56 git am -3 -s -u || {
57 echo >&2 "finish the am and say $0 --continue"
58 exit 1
59 }
60 ;;
61esac
62
63branch_point=$(sed -ne 's/^branch_point=//p' .rp-state) &&
64target_branch=$(sed -ne 's/^target_branch=//p' .rp-state) || {
65 echo >&2 "no replace-patch session"
66 exit 1
67}
68rm -f .rp-state
69
70git branch -f "$target_branch" HEAD
71git checkout "$target_branch"
72git -p show-branch "$target_branch@{1}" "$target_branch"
73git diff --stat -p "$target_branch@{1}" "$target_branch"