File tree Expand file tree Collapse file tree 4 files changed +42
-1
lines changed
Expand file tree Collapse file tree 4 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -330,6 +330,8 @@ pushed regardless of the upstream state.
330330 even if the `branch` differs from the `branch` specified in the source.
331331 To avoid this, you should use two resources of read-only and write-only.
332332
333+ * `refs_prefix`: *Optional.* Allows pushing to refs other than heads. Defaults to `refs/heads`.
334+
333335# # Development
334336
335337# ## Prerequisites
Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ only_tag=$(jq -r '.params.only_tag // false' <<< "$payload")
3939annotation_file=$( jq -r ' .params.annotate // ""' <<< " $payload" )
4040notes_file=$( jq -r ' .params.notes // ""' <<< " $payload" )
4141override_branch=$( jq -r ' .params.branch // ""' <<< " $payload" )
42+ # useful for pushing to special ref types like refs/for in gerrit.
43+ refs_prefix=$( jq -r ' .params.refs_prefix // "refs/heads"' <<< " $payload" )
4244
4345configure_git_global " ${git_config_payload} "
4446
@@ -103,7 +105,7 @@ tag() {
103105}
104106
105107push_src_and_tags () {
106- git push --tags push-target HEAD:refs/heads /$branch $forceflag
108+ git push --tags push-target HEAD:$refs_prefix /$branch $forceflag
107109}
108110
109111push_tags () {
Original file line number Diff line number Diff line change @@ -1238,3 +1238,16 @@ put_uri_with_config() {
12381238 }
12391239 }" | ${resource_dir} /out " $2 " | tee /dev/stderr
12401240}
1241+
1242+ put_uri_with_refs_prefix () {
1243+ jq -n " {
1244+ source: {
1245+ uri: $( echo $1 | jq -R .) ,
1246+ branch: \" master\"
1247+ },
1248+ params: {
1249+ repository: $( echo $3 | jq -R .) ,
1250+ refs_prefix: $( echo $4 | jq -R .) ,
1251+ }
1252+ }" | ${resource_dir} /out " $2 " | tee /dev/stderr
1253+ }
Original file line number Diff line number Diff line change @@ -585,6 +585,29 @@ it_will_fail_put_with_conflicting_tag_and_not_force_push() {
585585 test " $( git -C $repo1 rev-parse some-only-tag) " = $expected_ref
586586}
587587
588+ it_can_put_with_refs_prefix () {
589+ local repo1=$( init_repo)
590+
591+ local src=$( mktemp -d $TMPDIR /put-src.XXXXXX)
592+ local repo2=$src /repo
593+ git clone $repo1 $repo2
594+
595+ local ref=$( make_commit $repo2 )
596+
597+ # cannot push to repo while it's checked out to a branch
598+ git -C $repo1 checkout refs/heads/master
599+ set -x
600+ put_uri_with_refs_prefix $repo1 $src repo refs/for | jq -e "
601+ .version == {ref: $( echo $ref | jq -R .) }
602+ "
603+
604+ # switch back to master
605+ git -C $repo1 checkout refs/for/master
606+
607+ test -e $repo1 /some-file
608+ test " $( git -C $repo1 rev-parse HEAD) " = $ref
609+ }
610+
588611run it_can_put_to_url
589612run it_can_put_to_url_with_branch
590613run it_returns_branch_in_metadata
@@ -605,3 +628,4 @@ run it_will_fail_put_if_conflicts_and_not_force_push
605628run it_can_put_and_force_the_push
606629run it_can_put_to_url_with_only_tag_and_force_the_push
607630run it_will_fail_put_with_conflicting_tag_and_not_force_push
631+ run it_can_put_with_refs_prefix
You can’t perform that action at this time.
0 commit comments