Skip to content

Commit 89abd39

Browse files
Merge pull request #5479 from smarterclayton/find_common_parent
In hack/cherry-pick find common parent for merged PRs
2 parents 24253c8 + 107dfed commit 89abd39

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

Diff for: hack/common.sh

+27-3
Original file line numberDiff line numberDiff line change
@@ -555,14 +555,38 @@ os::build::commit_range() {
555555
fi
556556

557557
local base
558-
base="$(git merge-base ${remote}/pr/$1 $2)"
558+
base="$(git merge-base ${target} $2)"
559559
if [[ $? -ne 0 ]]; then
560560
echo "Branch has no common commits with $2" 1>&2
561561
exit 1
562562
fi
563563
if [[ "${base}" == "${target}" ]]; then
564-
echo "Branch has already been merged to upstream master, use explicit range instead" 1>&2
565-
exit 1
564+
565+
# DO NOT TRUST THIS CODE
566+
merged="$(git rev-list --reverse ${target}..$2 --ancestry-path | head -1)"
567+
if [[ -z "${merged}" ]]; then
568+
echo "Unable to find the commit that merged ${remote}/pr/$1" 1>&2
569+
exit 1
570+
fi
571+
#if [[ $? -ne 0 ]]; then
572+
# echo "Unable to find the merge commit for $1: ${merged}" 1>&2
573+
# exit 1
574+
#fi
575+
echo "++ pr/$1 appears to have merged at ${merged}" 1>&2
576+
leftparent="$(git rev-list --parents -n 1 ${merged} | cut -f2 -d ' ')"
577+
if [[ $? -ne 0 ]]; then
578+
echo "Unable to find the left-parent for the merge of for $1" 1>&2
579+
exit 1
580+
fi
581+
base="$(git merge-base ${target} ${leftparent})"
582+
if [[ $? -ne 0 ]]; then
583+
echo "Unable to find the common commit between ${leftparent} and $1" 1>&2
584+
exit 1
585+
fi
586+
echo "${base}..${target}"
587+
exit 0
588+
#echo "Branch has already been merged to upstream master, use explicit range instead" 1>&2
589+
#exit 1
566590
fi
567591

568592
echo "${base}...${target}"

0 commit comments

Comments
 (0)