]> git.ipfire.org Git - thirdparty/git.git/commitdiff
onemerge: make sure each merge in master..seen brings in only one topic
authorJunio C Hamano <gitster@pobox.com>
Mon, 29 Jun 2026 16:25:16 +0000 (09:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Jun 2026 16:25:16 +0000 (09:25 -0700)
If a topic B is built on top of a merge of topic A into master, then
we should merge topic A first before topic B when preparing the
integration branches.  Merging topic B first would bring topic A
along with it, which is generally not a good idea if we consider A
and B as two separate topics.

onemerge.sh [new file with mode: 0755]

diff --git a/onemerge.sh b/onemerge.sh
new file mode 100755 (executable)
index 0000000..d0bed02
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+# between master..seen, are there merges that bring in 
+# more than one topic at a time?
+
+endpoint=${1-seen}
+
+tmp=/var/tmp/e.$$
+rm -f "$tmp.1" "$tmp.2" &&
+prev= &&
+trap 'rm -f "$tmp.*"' 0 || exit
+
+git rev-list --merges --first-parent master..$endpoint |
+while read commit
+do
+       # $tmp.1 has remaining topics after the merge we are looking at.
+       # $tmp.2 has remaining topics after the previous merge that is
+       # a descendant of the current merge.
+
+       git branch --list --no-merged "$commit" '??/*' >"$tmp.1"
+       if test -f "$tmp.2" && test -n "$prev"
+       then
+               cnt=$(comm -23 "$tmp.1" "$tmp.2" | wc -l)
+               if test $cnt != 1
+               then
+                       echo Merges multiple topics
+                       git show -s --format="* %s" "$prev"
+                       comm -23 "$tmp.1" "$tmp.2"
+                       exit
+
+               fi
+       fi
+       mv -f "$tmp.1" "$tmp.2"
+       prev=$commit
+done