diff --git a/README.md b/README.md index 73fe324..4d47461 100644 --- a/README.md +++ b/README.md @@ -330,6 +330,8 @@ pushed regardless of the upstream state. even if the `branch` differs from the `branch` specified in the source. To avoid this, you should use two resources of read-only and write-only. +* `refs_prefix`: *Optional.* Allows pushing to refs other than heads. Defaults to `refs/heads`. + ## Development ### Prerequisites diff --git a/assets/out b/assets/out index 93b3363..54a882a 100755 --- a/assets/out +++ b/assets/out @@ -39,6 +39,8 @@ only_tag=$(jq -r '.params.only_tag // false' <<< "$payload") annotation_file=$(jq -r '.params.annotate // ""' <<< "$payload") notes_file=$(jq -r '.params.notes // ""' <<< "$payload") override_branch=$(jq -r '.params.branch // ""' <<< "$payload") +# useful for pushing to special ref types like refs/for in gerrit. +refs_prefix=$(jq -r '.params.refs_prefix // "refs/heads"' <<< "$payload") configure_git_global "${git_config_payload}" @@ -103,7 +105,7 @@ tag() { } push_src_and_tags() { - git push --tags push-target HEAD:refs/heads/$branch $forceflag + git push --tags push-target HEAD:$refs_prefix/$branch $forceflag } push_tags() { diff --git a/test/helpers.sh b/test/helpers.sh index 65466cc..fe5d1db 100644 --- a/test/helpers.sh +++ b/test/helpers.sh @@ -1238,3 +1238,16 @@ put_uri_with_config() { } }" | ${resource_dir}/out "$2" | tee /dev/stderr } + +put_uri_with_refs_prefix() { + jq -n "{ + source: { + uri: $(echo $1 | jq -R .), + branch: \"master\" + }, + params: { + repository: $(echo $3 | jq -R .), + refs_prefix: $(echo $4 | jq -R .), + } + }" | ${resource_dir}/out "$2" | tee /dev/stderr +} \ No newline at end of file diff --git a/test/put.sh b/test/put.sh index 8e13ecb..850be6a 100755 --- a/test/put.sh +++ b/test/put.sh @@ -585,6 +585,29 @@ it_will_fail_put_with_conflicting_tag_and_not_force_push() { test "$(git -C $repo1 rev-parse some-only-tag)" = $expected_ref } +it_can_put_with_refs_prefix() { + local repo1=$(init_repo) + + local src=$(mktemp -d $TMPDIR/put-src.XXXXXX) + local repo2=$src/repo + git clone $repo1 $repo2 + + local ref=$(make_commit $repo2) + + # cannot push to repo while it's checked out to a branch + git -C $repo1 checkout refs/heads/master + set -x + put_uri_with_refs_prefix $repo1 $src repo refs/for | jq -e " + .version == {ref: $(echo $ref | jq -R .)} + " + + # switch back to master + git -C $repo1 checkout refs/for/master + + test -e $repo1/some-file + test "$(git -C $repo1 rev-parse HEAD)" = $ref +} + run it_can_put_to_url run it_can_put_to_url_with_branch run it_returns_branch_in_metadata @@ -605,3 +628,4 @@ run it_will_fail_put_if_conflicts_and_not_force_push run it_can_put_and_force_the_push run it_can_put_to_url_with_only_tag_and_force_the_push run it_will_fail_put_with_conflicting_tag_and_not_force_push +run it_can_put_with_refs_prefix