Skip to content

Use original commit version as output version after a merge #253

Description

@rliebz

Currently, if the merge parameter is set for out, the version ref used will be the result of the merge commit. I believe the version ref should instead be the original commit.

Consider my poorly drawn diagram of a commit history:

*  m - Merge commit of x and o
|\
* |  x - Commit we're racing against
| *  o - Good commit that we want
|/
* p - Parent commit

And my poorly drawn pipeline:

git-repo --> [ run-tests ] --> git-repo --> [ bump-version-and-tag ] --> git-repo-bumped --> [ deploy ]

In this case, I've made some changes in commit o as part of my pipeline, and I'd like to tag and push commit o. To prevent pipeline failures if some commit x ends up in my target branch before the pipeline is finished, I've set merge: true, which merges the latest target branch here, combining x and o into merge commit m:

git-resource/assets/out

Lines 177 to 192 in 9129dd9

while true; do
echo "rebasing..."
git fetch push-target "refs/notes/*:refs/notes/*"
git pull --rebase=preserve push-target $branch
result="0"
push_with_result_check result
if [ "$result" = "0" ]; then
break
elif [ "$result" = "1" ]; then
exit 1
fi
echo "rebasing and trying again..."
done

And then ultimately uses the current commit, which would be commit m. This means the rest of my pipeline will now include commit x, despite it not being part of the relevant changeset:

git-resource/assets/out

Lines 199 to 202 in 9129dd9

jq -n "{
version: {ref: $(git rev-parse HEAD | jq -R .)},
metadata: $(git_metadata)
}" >&3

Because merging creates a non-linear history where commit o will still be intact, I think commit o should be used as the version ref. This would mean future parts of the pipeline can operate on the original change set without picking up racing commits in the target branch, while still being able to output the change into the target branch without races.

Edit: If this is something you're interested in, I'd be happy to contribute the change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions