From 70955606b19d3154dae21bc9419019566236cad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Britto?= Date: Tue, 27 Sep 2022 22:27:04 -0300 Subject: [PATCH] Populate additional .git/branch file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit containing the name of the original cloned branch. Signed-off-by: João Britto --- README.md | 2 ++ assets/in | 3 +++ test/get.sh | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/README.md b/README.md index 09ab0d8..cba3f84 100644 --- a/README.md +++ b/README.md @@ -311,6 +311,8 @@ the case. the commit SHA-1 ref, but also the detected tag name when using `tag_filter` or `tag_regex`. +* `.git/branch`: Name of the original branch that was cloned. + * `.git/short_ref`: Short (first seven characters) of the `.git/ref`. Can be templated with `short_ref_format` parameter. * `.git/commit_message`: For publishing the Git commit message on successful builds. diff --git a/assets/in b/assets/in index 8dd81af..483f56a 100755 --- a/assets/in +++ b/assets/in @@ -234,6 +234,9 @@ git --no-pager log -1 --pretty=format:"%an" > .git/committer_name # pulled ref in following tasks and resources. echo "${return_ref}" > .git/ref +# Store original cloned branch in .git/branch +git name-rev --name-only HEAD > .git/branch + # Store short ref with templating. Useful to build Docker images with # a custom tag echo "${return_ref}" | cut -c1-7 | awk "{ printf \"${short_ref_format}\", \$1 }" > .git/short_ref diff --git a/test/get.sh b/test/get.sh index dce6bca..369908a 100755 --- a/test/get.sh +++ b/test/get.sh @@ -729,6 +729,28 @@ it_can_get_returned_ref() { ( echo ".git/describe_ref does not match. Expected '${expected_describe_ref}', got '$(cat $dest/.git/describe_ref)'"; return 1 ) } +it_can_get_commit_branch() { + local repo=$(init_repo) + local ref1=$(make_commit_to_branch $repo branch-a) + local ref2=$(make_commit $repo) + + local dest=$TMPDIR/destination + + get_uri $repo $dest + + test -e $dest/.git/branch || ( echo ".git/branch does not exist."; return 1 ) + test "$(cat $dest/.git/branch)" = "master" || \ + ( echo ".git/branch does not match. Expected 'master', got '$(cat $dest/.git/branch)'"; return 1 ) + + rm -rf $dest + + get_uri_at_branch $repo branch-a $dest + + test -e $dest/.git/branch || ( echo ".git/branch does not exist."; return 1 ) + test "$(cat $dest/.git/branch)" = "branch-a" || \ + ( echo ".git/branch does not match. Expected 'branch-a', got '$(cat $dest/.git/branch)'"; return 1 ) +} + it_can_get_commit_message() { local repo=$(init_repo) local commit_message='Awesome-commit-message' @@ -916,6 +938,7 @@ run it_can_get_signed_commit_via_tag run it_can_get_signed_commit_via_tag_regex run it_can_get_committer_email run it_can_get_returned_ref +run it_can_get_commit_branch run it_can_get_commit_message run it_can_get_commit_timestamps run it_decrypts_git_crypted_files