Skip to content

Commit

Permalink
Merge pull request #314 from talset/fetchtags
Browse files Browse the repository at this point in the history
Add fetch_tags param fix #249 and #312
  • Loading branch information
aoldershaw authored Apr 22, 2020
2 parents bfc02ed + c647abf commit 1bf435a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 3 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ Tracks the commits in a [git](http://git-scm.com/) repository.
the `branch`. Patterns are [glob(7)](http://man7.org/linux/man-pages/man7/glob.7.html)
compatible (as in, bash compatible).
* `fetch_tags`: *Optional.* If `true` the flag `--tags` will be used to fetch
all tags in the repository. If `false` no tags will be fetched.
* `submodule_credentials`: *Optional.* List of credentials for HTTP(s) auth when pulling/pushing private git submodules which are not stored in the same git server as the container repository.
Example:
```
Expand Down Expand Up @@ -98,7 +101,7 @@ Tracks the commits in a [git](http://git-scm.com/) repository.
* `proxy_user`: *Optional.* If the proxy requires authentication, use this username
* `proxy_password`: *Optional.* If the proxy requires authenticate,
use this password
* `commit_filter`: *Optional.* Object containing commit message filters
* `commit_filter.exclude`: *Optional.* Array containing strings that should
cause a commit to be skipped
Expand Down Expand Up @@ -211,6 +214,11 @@ correct key is provided set in `git_crypt_key`.
`version.ref`, this resource will automatically deepen the clone until
`version.ref` is found again.

* `fetch_tags`: *Optional.* If `true` the flag `--tags` will be used to fetch
all tags in the repository. If `false` no tags will be fetched.

Will override `fetch_tags` source configuration if defined.

* `submodules`: *Optional.* If `none`, submodules will not be
fetched. If specified as a list of paths, only the given paths will be
fetched. If not specified, or if `all` is explicitly specified, all
Expand Down
4 changes: 3 additions & 1 deletion assets/check
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ configure_git_global "${git_config_payload}"
destination=$TMPDIR/git-resource-repo-cache

tagflag=""
if [ -n "$tag_filter" ]; then
if [ -n "$tag_filter" ] ; then
tagflag="--tags"
else
tagflag="--no-tags"
fi

# We're just checking for commits; we don't ever need to fetch LFS files here!
Expand Down
10 changes: 9 additions & 1 deletion assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ submodule_remote=$(jq -r '(.params.submodule_remote // false)' < $payload)
commit_verification_key_ids=$(jq -r '(.source.commit_verification_key_ids // [])[]' < $payload)
commit_verification_keys=$(jq -r '(.source.commit_verification_keys // [])[]' < $payload)
tag_filter=$(jq -r '.source.tag_filter // ""' < $payload)
fetch_tags=$(jq -r '.params.fetch_tags' < $payload)
gpg_keyserver=$(jq -r '.source.gpg_keyserver // "hkp://ipv4.pool.sks-keyservers.net/"' < $payload)
disable_git_lfs=$(jq -r '(.params.disable_git_lfs // false)' < $payload)
clean_tags=$(jq -r '(.params.clean_tags // false)' < $payload)
short_ref_format=$(jq -r '(.params.short_ref_format // "%s")' < $payload)

# If params not defined, get it from source
if [ -z "$fetch_tags" ] || [ "$fetch_tags" == "null" ] ; then
fetch_tags=$(jq -r '.source.fetch_tags' < $payload)
fi

configure_git_global "${git_config_payload}"

if [ -z "$uri" ]; then
Expand All @@ -69,7 +75,9 @@ if test "$depth" -gt 0 2> /dev/null; then
fi

tagflag=""
if [ -n "$tag_filter" ]; then
if [ "$fetch_tags" == "false" ] ; then
tagflag="--no-tags"
elif [ -n "$tag_filter" ] || [ "$fetch_tags" == "true" ] ; then
tagflag="--tags"
fi

Expand Down
34 changes: 34 additions & 0 deletions test/get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,38 @@ it_retains_tags_with_clean_tags_param() {
test "$(git -C $dest tag)" == $tag
}

it_returns_list_without_tags_in_metadata() {
local repo=$(init_repo)
local ref1=$(make_commit_to_branch $repo branch-a)

local ref2=$(make_annotated_tag $repo "v1.1-pre" "tag 1")
local ref3=$(make_annotated_tag $repo "v1.1-final" "tag 2")

local dest=$TMPDIR/destination
get_uri_at_branch_without_fetch_tags $repo branch-a $dest | jq -e "
.version == {ref: $(echo $ref1 | jq -R .)}
and
(.metadata | .[] | select(.name != \"tags\"))
"
}

it_returns_list_of_all_tags_in_metadata() {

local repo=$(init_repo)
local ref1=$(make_commit_to_branch $repo branch-a)
local ref2=$(make_annotated_tag $repo "v1.1-pre" "tag 1")
local ref3=$(make_annotated_tag $repo "v1.1-final" "tag 2")
local ref4=$(make_commit_to_branch $repo branch-b)
local ref5=$(make_annotated_tag $repo "v1.1-branch-b" "tag 3")

local dest=$TMPDIR/destination
get_uri_at_branch_with_fetch_tags $repo branch-a $dest | jq -e "
.version == {ref: $(echo $ref4 | jq -R .)}
and
(.metadata | .[] | select(.name == \"tags\") | .value == \"v1.1-branch-b,v1.1-final,v1.1-pre\")
"
}

run it_can_use_submodules_with_missing_paths
run it_can_use_submodules_with_names_that_arent_paths
run it_can_use_submodules_without_perl_warning
Expand Down Expand Up @@ -753,3 +785,5 @@ run it_decrypts_git_crypted_files
run it_clears_tags_with_clean_tags_param
run it_retains_tags_by_default
run it_retains_tags_with_clean_tags_param
run it_returns_list_without_tags_in_metadata
run it_returns_list_of_all_tags_in_metadata
24 changes: 24 additions & 0 deletions test/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,30 @@ get_uri_at_branch() {
}" | ${resource_dir}/in "$3" | tee /dev/stderr
}

get_uri_at_branch_without_fetch_tags() {
jq -n "{
source: {
uri: $(echo $1 | jq -R .),
branch: $(echo $2 | jq -R .)
},
params: {
fetch_tags: \"false\"
}
}" | ${resource_dir}/in "$3" | tee /dev/stderr
}

get_uri_at_branch_with_fetch_tags() {
jq -n "{
source: {
uri: $(echo $1 | jq -R .),
branch: $(echo $2 | jq -R .)
},
params: {
fetch_tags: \"true\"
}
}" | ${resource_dir}/in "$3" | tee /dev/stderr
}

get_uri_with_config() {
jq -n "{
source: {
Expand Down

0 comments on commit 1bf435a

Please sign in to comment.