]> git.ozlabs.org Git - next-scripts/blob - merge_msg
merge_msg: prompt for the HEAD side trees involved
[next-scripts] / merge_msg
1 #!/bin/bash
2
3 branch=()
4 if [ "X$1" = 'X-b' ]; then
5         branch=( -b "$2" )
6         shift 2
7 fi
8
9 gitk --merge -- "$@" &
10
11 tools_dir=$(dirname "$0")
12
13 hc=()
14 cc=()
15 cformat='%(trailers:only=no,valueonly,unfold,key=signed-off-by)%aN <%aE>%n%cN <%cE>'
16
17 read -r -a head_commits -p 'HEAD commit(s): '
18 for c in "${head_commits[@]}"; do
19         if ! git rev-parse --verify "$c" >/dev/null; then
20                 printf 'Unknown commit %s\n' "$c"
21                 exit 1
22         fi
23         hc+=( "$(git log -1 --format='%h ("%s")' "$c")" )
24         readarray -t -O "${#cc[@]}" cc < <(git log -1 --format="$cformat" "$c" | sort -u)
25 done
26 hcs=''
27 if [ "${#hc[@]}" -gt 1 ]; then
28         hcs='s'
29 fi
30
31 read -r -a head_branches -p 'HEAD branch(es): '
32
33 hb=( "${head_branches[@]/%/,}" )
34 hb[-1]=${hb[-1]%,}
35 if [ "${#hb[@]}" -gt 2 ]; then
36         hb[-2]=${hb[-2]/%,/ and}
37 fi
38 hbs=''
39 if [ "${#hb[@]}" -gt 1 ]; then
40         hbs='s'
41 fi
42
43 printf -v subject 'manual merge of the BRANCH tree with the %s tree%s' \
44         "${hb[*]}" "$hbs"
45
46 printf -v files '  %s\n' "$@"
47 conf='a conflict'
48 if [ "$#" -gt 1 ]; then
49         conf='conflicts'
50 fi
51
52 "$tools_dir/message_helper" "${branch[@]}" "$subject" "${cc[@]}" <<EOF
53 FIXME: Add owner of second tree to To:
54        Add author(s)/SOB of conflicting commits.
55
56 Today's linux-next merge of the BRANCH tree got $conf in:
57
58 $files
59 between commit$hcs:
60
61 $(printf '  %s\n' "${hc[@]}")
62
63 from the ${hb[*]} tree$hbs and commit:
64
65    ("")
66
67 from the BRANCH tree.
68
69 I fixed it up (see below) and can carry the fix as necessary. This
70 is now fixed as far as linux-next is concerned, but any non trivial
71 conflicts should be mentioned to your upstream maintainer when your tree
72 is submitted for merging.  You may also want to consider cooperating
73 with the maintainer of the conflicting tree to minimise any particularly
74 complex conflicts.
75 EOF
76
77 exit 0