Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'all_branches' flag to params in 'in' #393

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ correct key is provided set in `git_crypt_key`.

* `describe_ref_options`: *Optional.* When populating `.git/describe_ref` use this options to call [`git describe`](https://git-scm.com/docs/git-describe). Defaults to `--always --dirty --broken`.

* `all_branches`: *Optional.* If `true` the flag `--single-branch` will be excluded
and all branches will be fetched from the repository. If `false` or not specified,
only a single branch (either `source.branch` or the default branch) will be fetched.

#### GPG signature verification

If `commit_verification_keys` or `commit_verification_key_ids` is specified in
Expand Down
8 changes: 7 additions & 1 deletion assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ submodule_recursive=$(jq -r '(.params.submodule_recursive // true)' <<< "$payloa
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")
all_branches=$(jq -r '(.params.all_branches // false)' <<< "$payload")
tag_filter=$(jq -r '.source.tag_filter // ""' <<< "$payload")
tag_regex=$(jq -r '.source.tag_regex // ""' <<< "$payload")
fetch_tags=$(jq -r '.params.fetch_tags' <<< "$payload")
Expand Down Expand Up @@ -94,7 +95,12 @@ if [ "$disable_git_lfs" == "true" ]; then
export GIT_LFS_SKIP_SMUDGE=1
fi

git clone --single-branch $depthflag $uri $branchflag $destination $tagflag
singlebranchflag="--single-branch"
if [ "$all_branches" == "true" ]; then
singlebranchflag=""
fi

git clone $singlebranchflag $depthflag $uri $branchflag $destination $tagflag

cd $destination

Expand Down
6 changes: 3 additions & 3 deletions assets/out
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ elif [ "$merge" = "true" ]; then
while true; do
echo "merging..."

git reset --hard $commit_to_push
git fetch push-target "refs/notes/*:refs/notes/*" $branch

git fetch push-target "refs/notes/*:refs/notes/*"
git pull --no-edit push-target $branch
git checkout push-target/$branch
git merge $commit_to_push

result="0"
push_with_result_check result
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG base_image=ubuntu:bionic
ARG base_image=ubuntu:jammy

FROM ${base_image} AS resource

Expand Down
14 changes: 14 additions & 0 deletions test/get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ it_can_get_from_url_at_override_branch() {
test "$(git -C $dest rev-parse HEAD)" = $ref
}

it_can_get_from_url_with_all_branches() {
local repo=$(init_repo)
local ref=$(make_commit $repo)
local dest=$TMPDIR/destination

get_uri_with_all_branches $repo "master" $dest | jq -e "
.version == {ref: $(echo $ref | jq -R .)}
"

git -C $dest show-ref --verify refs/remotes/origin/master
git -C $dest show-ref --verify refs/remotes/origin/bogus
}

it_omits_empty_branch_in_metadata() {
local repo=$(init_repo)
local ref1=$(make_commit_to_branch $repo branch-a)
Expand Down Expand Up @@ -894,6 +907,7 @@ run it_can_get_from_url_at_ref
run it_can_get_from_url_at_branch
run it_can_get_from_url_only_single_branch
run it_can_get_from_url_at_override_branch
run it_can_get_from_url_with_all_branches
run it_omits_empty_branch_in_metadata
run it_returns_branch_in_metadata
run it_omits_empty_tags_in_metadata
Expand Down
12 changes: 12 additions & 0 deletions test/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,18 @@ get_uri_with_override_branch() {
}" | ${resource_dir}/in "$4" | tee /dev/stderr
}

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

get_uri_with_git_crypt_key() {
local git_crypt_key_path=$(git_crypt_fixture_key_path)
local git_crypt_key_base64_encoded=$(cat $git_crypt_key_path | base64)
Expand Down
7 changes: 6 additions & 1 deletion test/put.sh
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ it_can_put_to_url_with_merge_commit() {
local repo2=$src/repo
git clone $repo1 $repo2

# make a commit that will require rebasing
# make a commit that will require merging
local baseref=$(make_commit_to_file $repo1 some-other-file)

local ref=$(make_commit $repo2)
Expand Down Expand Up @@ -296,6 +296,11 @@ it_can_put_to_url_with_merge_commit() {
local latest_merge_ref=$(git -C $repo1 log -n 1 --merges --pretty=format:"%H")

test $latest_merge_ref = $merged_ref

# confirm first parent correctly matches commit prior to merge
local first_parent_ref=$(git -C $repo1 log -n 1 HEAD^1 --pretty=format:"%H")

test $first_parent_ref = $baseref
}

it_chooses_the_unmerged_commit_ref() {
Expand Down