Skip to content

Commit b416dcc

Browse files
authored
Merge pull request #9 from linkyard/put-branch
Support push to branch for multibranch
2 parents 40f7e1f + 30489a0 commit b416dcc

3 files changed

Lines changed: 56 additions & 10 deletions

File tree

assets/out

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ if [ -z "$uri" ]; then
3838
exit 1
3939
fi
4040

41+
cd $source
42+
43+
if [ -z "$branch" ]; then
44+
branch=$(git -C $repository config --local concourse-ci.branch-name)
45+
fi
4146
if [ -z "$branch" ]; then
4247
echo "invalid payload (missing branch)"
4348
exit 1
@@ -48,8 +53,6 @@ if [ -z "$repository" ]; then
4853
exit 1
4954
fi
5055

51-
cd $source
52-
5356
if [ -n "$tag" ] && [ ! -f "$tag" ]; then
5457
echo "tag file '$tag' does not exist"
5558
exit 1
@@ -125,6 +128,6 @@ else
125128
fi
126129

127130
jq -n "{
128-
version: {ref: $(git rev-parse HEAD | jq -R .)},
131+
version: {ref: $(echo $(git rev-parse HEAD):$branch | jq -R .)},
129132
metadata: $(git_metadata)
130133
}" >&3

test/helpers.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,16 @@ put_uri_with_rebase_with_tag_and_prefix() {
446446
}
447447
}" | ${resource_dir}/out "$2" | tee /dev/stderr
448448
}
449+
450+
put_uri_with_multibranch() {
451+
jq -n "{
452+
source: {
453+
uri: $(echo $1 | jq -R .),
454+
branches: $(echo $4 | jq -R .)
455+
},
456+
params: {
457+
repository: $(echo $3 | jq -R .),
458+
multibranch: true
459+
}
460+
}" | ${resource_dir}/out "$2" | tee /dev/stderr
461+
}

test/put.sh

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ it_can_put_to_url() {
2020
git -C $repo1 checkout refs/heads/master
2121

2222
put_uri $repo1 $src repo | jq -e "
23-
.version == {ref: $(echo $ref | jq -R .)}
23+
.version == {ref: $(echo $ref:master | jq -R .)}
2424
"
2525

2626
# switch back to master
@@ -46,7 +46,7 @@ it_can_put_to_url_with_tag() {
4646
git -C $repo1 checkout refs/heads/master
4747

4848
put_uri_with_tag $repo1 $src some-tag-file repo | jq -e "
49-
.version == {ref: $(echo $ref | jq -R .)}
49+
.version == {ref: $(echo $ref:master | jq -R .)}
5050
"
5151

5252
# switch back to master
@@ -72,7 +72,7 @@ it_can_put_to_url_with_tag_and_prefix() {
7272
git -C $repo1 checkout refs/heads/master
7373

7474
put_uri_with_tag_and_prefix $repo1 $src some-tag-file v repo | jq -e "
75-
.version == {ref: $(echo $ref | jq -R .)}
75+
.version == {ref: $(echo $ref:master | jq -R .)}
7676
"
7777

7878
# switch back to master
@@ -105,7 +105,7 @@ it_can_put_to_url_with_rebase() {
105105
local rebased_ref=$(git -C $repo2 rev-parse HEAD)
106106

107107
jq -e "
108-
.version == {ref: $(echo $rebased_ref | jq -R .)}
108+
.version == {ref: $(echo $rebased_ref:master | jq -R .)}
109109
" < $response
110110

111111
# switch back to master
@@ -139,7 +139,7 @@ it_can_put_to_url_with_rebase_with_tag() {
139139
local rebased_ref=$(git -C $repo2 rev-parse HEAD)
140140

141141
jq -e "
142-
.version == {ref: $(echo $rebased_ref | jq -R .)}
142+
.version == {ref: $(echo $rebased_ref:master | jq -R .)}
143143
" < $response
144144

145145
# switch back to master
@@ -174,7 +174,7 @@ it_can_put_to_url_with_rebase_with_tag_and_prefix() {
174174
local rebased_ref=$(git -C $repo2 rev-parse HEAD)
175175

176176
jq -e "
177-
.version == {ref: $(echo $rebased_ref | jq -R .)}
177+
.version == {ref: $(echo $rebased_ref:master | jq -R .)}
178178
" < $response
179179

180180
# switch back to master
@@ -201,7 +201,7 @@ it_can_put_to_url_with_only_tag() {
201201
git -C $repo1 checkout refs/heads/master
202202

203203
put_uri_with_only_tag $repo1 $src repo | jq -e "
204-
.version == {ref: $(echo $ref | jq -R .)}
204+
.version == {ref: $(echo $ref:master | jq -R .)}
205205
"
206206

207207
# switch back to master
@@ -212,10 +212,40 @@ it_can_put_to_url_with_only_tag() {
212212
test "$(git -C $repo1 rev-parse some-only-tag)" = $ref
213213
}
214214

215+
it_can_put_to_url_when_multibranch() {
216+
local repo=$(init_repo)
217+
local ref1=$(make_commit $repo)
218+
local ref2=$(make_commit $repo)
219+
local ref3=$(make_commit_to_file_on_branch $repo some-other-file branch-a)
220+
local ref4=$(make_commit $repo)
221+
222+
git -C $repo checkout refs/heads/master
223+
224+
local dest=$TMPDIR/destination
225+
226+
test_get $dest uri $repo ref "$ref3:branch-a $ref2:master" | jq -e "
227+
.version == {ref: $(echo "$ref3:branch-a $ref2:master" | jq -R .)}
228+
"
229+
230+
test -e $dest/some-other-file
231+
test "$(git -C $dest rev-parse HEAD)" = $ref3
232+
test "$(git -C $dest rev-parse branch-a)" = $ref3
233+
234+
put_uri_with_multibranch $repo $repo $dest "(branch-a)" | jq -e "
235+
.version == {ref: $(echo $ref3:branch-a | jq -R .)}
236+
"
237+
238+
git -C $repo checkout branch-a
239+
test -e $repo/some-other-file
240+
test "$(git -C $repo rev-parse master)" = $ref4
241+
test "$(git -C $repo rev-parse branch-a)" = $ref3
242+
}
243+
215244
run it_can_put_to_url
216245
run it_can_put_to_url_with_tag
217246
run it_can_put_to_url_with_tag_and_prefix
218247
run it_can_put_to_url_with_rebase
219248
run it_can_put_to_url_with_rebase_with_tag
220249
run it_can_put_to_url_with_rebase_with_tag_and_prefix
221250
run it_can_put_to_url_with_only_tag
251+
run it_can_put_to_url_when_multibranch

0 commit comments

Comments
 (0)