diff --git a/README.md b/README.md index d7db6ae7..0bd698aa 100644 --- a/README.md +++ b/README.md @@ -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: ``` @@ -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 @@ -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 diff --git a/assets/check b/assets/check index fbeace8f..c69d314b 100755 --- a/assets/check +++ b/assets/check @@ -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! diff --git a/assets/in b/assets/in index 6f589b0c..f27e8e17 100755 --- a/assets/in +++ b/assets/in @@ -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 @@ -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 diff --git a/test/get.sh b/test/get.sh index 7c7ad4b2..aeeb5272 100755 --- a/test/get.sh +++ b/test/get.sh @@ -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 @@ -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 diff --git a/test/helpers.sh b/test/helpers.sh index 2bd86a61..70f00f25 100644 --- a/test/helpers.sh +++ b/test/helpers.sh @@ -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: {