Skip to content

Commit

Permalink
Merge pull request #262 from rliebz/merge-ref
Browse files Browse the repository at this point in the history
Add "returning" option for merge output ref
  • Loading branch information
vito authored May 29, 2019
2 parents c7ce452 + 3d45cf9 commit 4788c43
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ and the `rebase` parameter is not provided, the push will fail.
attempt to merge remote to local before pushing. Only one of `merge` or
`rebase` can be provided, but not both.

* `returning`: *Optional.* When passing the `merge` flag, specify whether the
merge commit or the original, unmerged commit should be passed as the output
ref. Options are `merged` and `unmerged`. Defaults to `merged`.

* `tag`: *Optional.* If this is set then HEAD will be tagged. The value should be
a path to a file containing the name of the tag.

Expand Down
9 changes: 8 additions & 1 deletion assets/out
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ tag=$(jq -r '.params.tag // ""' < $payload)
tag_prefix=$(jq -r '.params.tag_prefix // ""' < $payload)
rebase=$(jq -r '.params.rebase // false' < $payload)
merge=$(jq -r '.params.merge // false' < $payload)
returning=$(jq -r '.params.returning // "merged"' < $payload)
force=$(jq -r '.params.force // false' < $payload)
only_tag=$(jq -r '.params.only_tag // false' < $payload)
annotation_file=$(jq -r '.params.annotate // ""' < $payload)
Expand Down Expand Up @@ -196,7 +197,13 @@ else
add_and_push_notes
fi

if [ "$merge" = "true" ] && [ "$returning" = "unmerged" ]; then
version_ref="$(echo "$commit_to_push" | jq -R .)"
else
version_ref="$(git rev-parse HEAD | jq -R .)"
fi

jq -n "{
version: {ref: $(git rev-parse HEAD | jq -R .)},
version: {ref: $version_ref},
metadata: $(git_metadata)
}" >&3
14 changes: 14 additions & 0 deletions test/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,20 @@ put_uri_with_merge() {
}" | ${resource_dir}/out "$2" | tee /dev/stderr
}

put_uri_with_merge_returning_unmerged() {
jq -n "{
source: {
uri: $(echo $1 | jq -R .),
branch: \"master\"
},
params: {
repository: $(echo $3 | jq -R .),
merge: true,
returning: \"unmerged\"
}
}" | ${resource_dir}/out "$2" | tee /dev/stderr
}

put_uri_with_merge_and_rebase() {
jq -n "{
source: {
Expand Down
38 changes: 38 additions & 0 deletions test/put.sh
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,43 @@ it_can_put_to_url_with_merge_commit() {
test $latest_merge_ref = $merged_ref
}

it_chooses_the_unmerged_commit_ref() {
local repo1=$(init_repo)

local src=$(mktemp -d $TMPDIR/put-src.XXXXXX)
local repo2=$src/repo
git clone $repo1 $repo2

# make a commit that will require rebasing
local baseref=$(make_commit_to_file $repo1 some-other-file)

local unmerged_ref=$(make_commit $repo2)

# cannot push to repo while it's checked out to a branch
git -C $repo1 checkout refs/heads/master

local response=$(mktemp $TMPDIR/rebased-response.XXXXXX)

put_uri_with_merge_returning_unmerged $repo1 $src repo > $response

local merged_ref=$(git -C $repo2 rev-parse HEAD)

jq -e "
.version == {ref: $(echo $unmerged_ref | jq -R .)}
" < $response

# switch back to master
git -C $repo1 checkout master

test -e $repo1/some-file

test "$(git -C $repo1 rev-parse HEAD)" = $merged_ref

local latest_merge_ref=$(git -C $repo1 log -n 1 --merges --pretty=format:"%H")

test $latest_merge_ref = $merged_ref
}

it_will_fail_put_if_merge_and_rebase_are_set() {
local repo1=$(init_repo)

Expand Down Expand Up @@ -536,6 +573,7 @@ run it_can_put_to_url_with_rebase_with_tag
run it_can_put_to_url_with_rebase_with_tag_and_prefix
run it_will_fail_put_if_merge_and_rebase_are_set
run it_can_put_to_url_with_merge_commit
run it_chooses_the_unmerged_commit_ref
run it_can_put_to_url_with_only_tag
run it_can_put_and_set_git_config
run it_will_fail_put_if_conflicts_and_not_force_push
Expand Down

0 comments on commit 4788c43

Please sign in to comment.