Skip to content

Commit

Permalink
feat: add option to automatically resolve merge conflicts
Browse files Browse the repository at this point in the history
Add option to automatically resolve merge conflicts by either accepting the change from `target` (default) or `source`. This behaviour can be defined by specifying the input `resolve_conflicts`.

BREAKING CHANGE: default behaviour for merge conflict changes

Merge conflicts are now resolved using strategy option `ours` by default, forcing conflicts to be auto-resolved cleanly by favoring the `target` version. All non-conflicting changes are still reflected in the merge result.

Set input `resolve_conflicts` to `false` to restore the previous behaviour of failing if any merge conflicts occur.
  • Loading branch information
jojomatik committed Oct 11, 2022
1 parent 2e8fc2c commit d7daf16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ jobs:
# target branch contains changes that are not present in the
# source branch
strategy: "merge"
# The changes to accept, if strategy `merge` leads to merge conflicts
# Optional
# Default: `target`
# Possible values:
# - `target`: forces conflicts to be auto-resolved cleanly by favoring
# the target version. All non-conflicting changes are reflected
# in the merge result.
# - `source`: forces conflicts to be auto-resolved cleanly by favoring
# the source version. All non-conflicting changes are reflected
# in the merge result.
# - `false`: `merge` fails if any merge conflicts occur.
resolve_conflicts: "theirs"
# The name to create merge commits with
# Required, if strategy `merge` is used
git_committer_name: ${{ secrets.BOT_GIT_NAME }}
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
description: 'The strategy to use, if fast-forward is not possible (merge, force, fail)'
required: false
default: "merge"
resolve_conflicts:
description: 'The changes to accept, if strategy `merge` leads to merge conflicts (target, source, false)'
required: false
default: "theirs"
git_committer_name:
description: 'The name to create merge commits with'
required: false
Expand Down Expand Up @@ -45,7 +49,7 @@ runs:
shell: bash
- name: Merge ${{ inputs.source }} into ${{ inputs.target }}
if: inputs.strategy == 'merge'
run: git merge ${{ inputs.source }}
run: git merge ${{ inputs.source }} ${{ inputs.resolve_conflicts != 'false' && format('--strategy-option {0}', inputs.resolve_conflicts == 'target' && 'ours' || 'theirs') || '' }}
shell: bash
- name: Push ${{ inputs.target }}
if: inputs.strategy == 'merge'
Expand Down

0 comments on commit d7daf16

Please sign in to comment.