Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 23 additions & 32 deletions buildkite/scripts/merges-cleanly.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/bin/bash

BRANCH=$1
echo "Checking conflicts: ${BUILDKITE_PULL_REQUEST_BASE_BRANCH} <--> ${BRANCH}"
PR_BRANCH=${BUILDKITE_BRANCH}
BASE_BRANCH=${BUILDKITE_PULL_REQUEST_BASE_BRANCH}
SYNC_BRANCH=$1
echo "Checking conflicts: (${PR_BRANCH} -> ${BASE_BRANCH}) -> ${SYNC_BRANCH}"


# Adapted from this stackoverflow answer: https://stackoverflow.com/a/10856937
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not telling what's being done at all.

# The git merge-tree command shows the content of a 3-way merge without
# touching the index, which we can then search for conflict markers.

# Only execute in the CI. If the script is run locally, it messes us the user
# Only execute in the CI. If the script is run locally, it'll mess up user's git
# config
if [ "${BUILDKITE:-false}" == true ]
then
Expand All @@ -18,31 +15,25 @@ then
git config --global user.name "It's me, CI"
fi

# Fetch a fresh copy of the target branch
source buildkite/scripts/refresh_code.sh

git fetch origin "${BRANCH}"
git fetch origin
git checkout ${BASE_BRANCH}
git reset --hard origin/${BASE_BRANCH}

# Check mergeability. We use flags so that
# * `--no-commit` stops us from updating the index with a merge commit,
# * `--no-ff` stops us from updating the index to the HEAD, if the merge is a
# straightforward fast-forward
git merge --no-commit --no-ff origin/"${BRANCH}"

RET=$?
if ! git merge origin/${PR_BRANCH}; then
ret=$?
echo "Merging from ${PR_BRANCH} -> ${BASE_BRANCH} failed (exit $ret)"
exit $ret
fi

if [ $RET -eq 0 ]; then
echo "No conflicts found against upstream branch ${BRANCH}"
exit 0
else
# exclude branches for which merging cleanly is not a hard requirement
if [ "${BUILDKITE_PULL_REQUEST_BASE_BRANCH}" == "o1js-main" ]; then
echo "Conflicts were found, but the current branch ($CURRENT) does not have to merge cleanly. Exiting with code 0."
exit 0
fi
git checkout ${SYNC_BRANCH}
git reset --hard origin/${SYNC_BRANCH}

# Found a conflict
echo "[ERROR] This pull request conflicts with $BRANCH, please open a new pull request against $BRANCH at this link:"
echo "https://github.com/MinaProtocol/mina/compare/${BRANCH}...${BUILDKITE_BRANCH}"
exit 1
if ! git merge --no-ff --no-commit ${BASE_BRANCH}; then
ret=$?
echo "[ERROR] This pull request has merge conflicts, please open a new pull request against $SYNC_BRANCH at this link:"
echo "https://github.com/MinaProtocol/mina/compare/${SYNC_BRANCH}...${PR_BRANCH}"
exit $ret
fi

echo "No conflicts found"
exit 0