From d3b1cd68a3fc9351b2064ec4f5c94cd64f84675e Mon Sep 17 00:00:00 2001 From: David Symons Date: Fri, 2 Dec 2022 21:16:52 +1000 Subject: [PATCH 1/3] add 'all_branches' flag to params in 'in' Adds a flag to disable the use of the '--single-branch' flag when cloning the repository, allowing all branches to be fetched from the remote Signed-off-by: David Symons --- README.md | 4 ++++ assets/in | 8 +++++++- test/get.sh | 14 ++++++++++++++ test/helpers.sh | 12 ++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 46a825bd..35e3475a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/assets/in b/assets/in index 96bea2b1..6cc01aee 100755 --- a/assets/in +++ b/assets/in @@ -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") @@ -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 diff --git a/test/get.sh b/test/get.sh index dce6bca2..15968ee1 100755 --- a/test/get.sh +++ b/test/get.sh @@ -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) @@ -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 diff --git a/test/helpers.sh b/test/helpers.sh index 1ecb42c8..79b1d198 100644 --- a/test/helpers.sh +++ b/test/helpers.sh @@ -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) From a7fffb62e6a21662dbf45522be640e464970b90c Mon Sep 17 00:00:00 2001 From: David Symons Date: Mon, 5 Dec 2022 13:16:42 +1000 Subject: [PATCH 2/3] Upgrade ubuntu/Dockerfile to jammy --- dockerfiles/ubuntu/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/ubuntu/Dockerfile b/dockerfiles/ubuntu/Dockerfile index fee0c82f..ff91d267 100644 --- a/dockerfiles/ubuntu/Dockerfile +++ b/dockerfiles/ubuntu/Dockerfile @@ -1,4 +1,4 @@ -ARG base_image=ubuntu:bionic +ARG base_image=ubuntu:jammy FROM ${base_image} AS resource From 6474776307cca739d71fed0c935a99cb75f7f6fd Mon Sep 17 00:00:00 2001 From: David Symons Date: Mon, 31 Jul 2023 14:42:34 +1000 Subject: [PATCH 3/3] update merge logic to preserve correct first parent commit Updates the merge logic used when "merge: true" is configured so that it ensures that the first parent of the merge commit is the commit of the target branch. Prior behaviour lead to the source branch being the "first parent" in the merge commit Signed-off-by: David Symons --- assets/out | 6 +++--- test/put.sh | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/assets/out b/assets/out index 54a882a6..1ae415fa 100755 --- a/assets/out +++ b/assets/out @@ -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 diff --git a/test/put.sh b/test/put.sh index 850be6ad..970cd9f9 100755 --- a/test/put.sh +++ b/test/put.sh @@ -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) @@ -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() {