Skip to content

Commit f15c1af

Browse files
authored
Merge pull request #464 from concourse/all_branches_flag
add all_branches as get.param to fetch all branches during cloning
2 parents 57d4ac7 + cd27a79 commit f15c1af

5 files changed

Lines changed: 43 additions & 2 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,14 @@ correct key is provided set in `git_crypt_key`.
504504
describe</code></a>. Defaults to <code>--always --dirty --broken</code>.
505505
</td>
506506
</tr>
507+
<tr>
508+
<td><code>all_branches</code><br/><i>Optional</i></td>
509+
<td>
510+
If <code>true</code> the flag <code>--single-branch</code> will be
511+
excluded and all branches will be fetched from the repository. If
512+
<code>false</code> or not specified, only a single branch (either
513+
<code>source.branch</code> or the default branch) will be fetched. </td>
514+
</tr>
507515
</table>
508516

509517
#### GPG signature verification

assets/in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ short_ref_format=$(jq -r '(.params.short_ref_format // "%s")' <<< "$payload")
6262
timestamp_format=$(jq -r '(.params.timestamp_format // "iso8601")' <<< "$payload")
6363
describe_ref_options=$(jq -r '(.params.describe_ref_options // "--always --dirty --broken")' <<< "$payload")
6464
search_remote_refs_flag=$(jq -r '(.source.search_remote_refs // false)' <<< "$payload")
65+
all_branches=$(jq -r '(.params.all_branches // false)' <<< "$payload")
6566

6667
# If params not defined, get it from source
6768
if [ -z "$fetch_tags" ] || [ "$fetch_tags" == "null" ] ; then
@@ -108,7 +109,12 @@ if [ "$disable_git_lfs" == "true" ]; then
108109
export GIT_LFS_SKIP_SMUDGE=1
109110
fi
110111

111-
git clone --progress --single-branch $depthflag $uri $branchflag $destination $tagflag $nocheckoutflag
112+
singlebranchflag="--single-branch"
113+
if [ "${all_branches,,}" == "true" ]; then
114+
singlebranchflag=""
115+
fi
116+
117+
git clone --progress $singlebranchflag $depthflag $uri $branchflag $destination $tagflag $nocheckoutflag
112118

113119
cd $destination
114120

assets/in_schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"clean_tags": "",
1010
"short_ref_format": "",
1111
"timestamp_format": "",
12-
"describe_ref_options": ""
12+
"describe_ref_options": "",
13+
"all_branches": ""
1314
}

test/get.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ it_can_get_from_url_at_override_branch() {
102102
test "$(git -C $dest rev-parse HEAD)" = $ref
103103
}
104104

105+
it_can_get_from_url_with_all_branches() {
106+
local repo=$(init_repo)
107+
local ref=$(make_commit $repo)
108+
local dest=$TMPDIR/destination
109+
110+
get_uri_with_all_branches $repo "master" $dest | jq -e "
111+
.version == {ref: $(echo $ref | jq -R .)}
112+
"
113+
114+
git -C $dest show-ref --verify refs/remotes/origin/master
115+
git -C $dest show-ref --verify refs/remotes/origin/bogus
116+
}
117+
105118
it_preserves_git_config_in_local_repository() {
106119
local repo=$(init_repo)
107120
local ref=$(make_commit $repo)
@@ -1130,6 +1143,7 @@ run it_can_get_from_url_at_ref
11301143
run it_can_get_from_url_at_branch
11311144
run it_can_get_from_url_only_single_branch
11321145
run it_can_get_from_url_at_override_branch
1146+
run it_can_get_from_url_with_all_branches
11331147
run it_preserves_git_config_in_local_repository
11341148
run it_can_get_from_url_with_sparse_paths
11351149
run it_omits_empty_branch_in_metadata

test/helpers.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,18 @@ get_uri_with_fetch_branches() {
11071107
}" | ${resource_dir}/in "$dest" | tee /dev/stderr
11081108
}
11091109

1110+
get_uri_with_all_branches() {
1111+
jq -n "{
1112+
source: {
1113+
uri: $(echo $1 | jq -R .),
1114+
branch: $(echo $2 | jq -R .),
1115+
},
1116+
params: {
1117+
all_branches: \"true\"
1118+
}
1119+
}" | ${resource_dir}/in "$3" | tee /dev/stderr
1120+
}
1121+
11101122
put_uri() {
11111123
jq -n "{
11121124
source: {

0 commit comments

Comments
 (0)