Skip to content

Commit

Permalink
fast-forward: Add --no-ff merge support
Browse files Browse the repository at this point in the history
This change allows to choose the merge strategy to use for merging
the pull-request.

A merge-strategy parameter is added, allowing to choose the no-ff way
(i.e. introducing a merge commit). The default strategy remains
fast-forwarding the branch.

Fixes sequoia-pgp#36
  • Loading branch information
smartin-vossloh committed Dec 18, 2024
1 parent 042cd23 commit 931f723
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
16 changes: 15 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ inputs:
indicating whether it is possible to fast forward the target
branch.
default: false
merge-strategy:
description: >
When merging, whether fast forwarding the branch or creating a
merge commit.
If merge-commit, a merge commit is created. Otherwise (the default),
the branch is fast forwarded.
default: fast-forward
comment:
description: >
Whether to post a comment.
Expand Down Expand Up @@ -61,7 +69,13 @@ runs:
# github.action_path is set to $REPO.
if test "x${{ inputs.merge }}" = xtrue
then
${{ github.action_path }}/src/fast-forward.sh --merge
if test "x${{ inputs.merge-strategy }}" = xmerge-commit
then
MERGE_STRATEGY=merge-commit
else
MERGE_STRATEGY=fast-forward
fi
${{ github.action_path }}/src/fast-forward.sh --merge "${MERGE_STRATEGY}"
else
${{ github.action_path }}/src/fast-forward.sh
fi
Expand Down
41 changes: 31 additions & 10 deletions src/fast-forward.sh
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,38 @@ LOG=$(mktemp)

if test "x$(jq -r .user.permissions.push < $PERM)" = xtrue
then
echo -n "Fast forwarding \`$BASE_REF\` ($BASE_SHA) to"
echo " \`$PR_REF\` ($PR_SHA)."
if test "x$2" = "xmerge-commit"
then
echo -n "Merging \`$PR_REF\` ($PR_SHA) into \`$BASE_REF\` ($BASE_SHA)."

echo '```shell'
(
PS4='$ '
set -x
git checkout "${BASE_REF}"
git -c user.name='Santa CLAUS' \
-c user.email='[email protected]' \
merge --no-ff --into-name "${BASE_REF}" \
-m "Merge pull request $(github_pull_request .number) from ${PR_REF} into ${BASE_REF}" \
"${PR_SHA}"
git push origin "${BASE_REF}"
)
echo '```'
echo 0 >$EXIT_CODE

echo '```shell'
(
PS4='$ '
set -x
git push origin "$PR_SHA:$BASE_REF"
)
echo '```'
echo 0 >$EXIT_CODE
else
echo -n "Fast forwarding \`$BASE_REF\` ($BASE_SHA) to"
echo " \`$PR_REF\` ($PR_SHA)."

echo '```shell'
(
PS4='$ '
set -x
git push origin "$PR_SHA:$BASE_REF"
)
echo '```'
echo 0 >$EXIT_CODE
fi
else
echo -n "Sorry @$(github_event .sender.login),"
echo -n " it is possible to fast forward \`$BASE_REF\` ($BASE_SHA)"
Expand Down

0 comments on commit 931f723

Please sign in to comment.