Skip to content

Commit 702bf5a

Browse files
authored
Merge pull request #391 from britto/add-git-branch-file
Populate additional `.git/branch` file
2 parents abb0629 + 7095560 commit 702bf5a

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ the case.
311311
the commit SHA-1 ref, but also the detected tag name when using `tag_filter` or
312312
`tag_regex`.
313313

314+
* `.git/branch`: Name of the original branch that was cloned.
315+
314316
* `.git/short_ref`: Short (first seven characters) of the `.git/ref`. Can be templated with `short_ref_format` parameter.
315317

316318
* `.git/commit_message`: For publishing the Git commit message on successful builds.

assets/in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ git --no-pager log -1 --pretty=format:"%an" > .git/committer_name
234234
# pulled ref in following tasks and resources.
235235
echo "${return_ref}" > .git/ref
236236

237+
# Store original cloned branch in .git/branch
238+
git name-rev --name-only HEAD > .git/branch
239+
237240
# Store short ref with templating. Useful to build Docker images with
238241
# a custom tag
239242
echo "${return_ref}" | cut -c1-7 | awk "{ printf \"${short_ref_format}\", \$1 }" > .git/short_ref

test/get.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,28 @@ it_can_get_returned_ref() {
729729
( echo ".git/describe_ref does not match. Expected '${expected_describe_ref}', got '$(cat $dest/.git/describe_ref)'"; return 1 )
730730
}
731731

732+
it_can_get_commit_branch() {
733+
local repo=$(init_repo)
734+
local ref1=$(make_commit_to_branch $repo branch-a)
735+
local ref2=$(make_commit $repo)
736+
737+
local dest=$TMPDIR/destination
738+
739+
get_uri $repo $dest
740+
741+
test -e $dest/.git/branch || ( echo ".git/branch does not exist."; return 1 )
742+
test "$(cat $dest/.git/branch)" = "master" || \
743+
( echo ".git/branch does not match. Expected 'master', got '$(cat $dest/.git/branch)'"; return 1 )
744+
745+
rm -rf $dest
746+
747+
get_uri_at_branch $repo branch-a $dest
748+
749+
test -e $dest/.git/branch || ( echo ".git/branch does not exist."; return 1 )
750+
test "$(cat $dest/.git/branch)" = "branch-a" || \
751+
( echo ".git/branch does not match. Expected 'branch-a', got '$(cat $dest/.git/branch)'"; return 1 )
752+
}
753+
732754
it_can_get_commit_message() {
733755
local repo=$(init_repo)
734756
local commit_message='Awesome-commit-message'
@@ -916,6 +938,7 @@ run it_can_get_signed_commit_via_tag
916938
run it_can_get_signed_commit_via_tag_regex
917939
run it_can_get_committer_email
918940
run it_can_get_returned_ref
941+
run it_can_get_commit_branch
919942
run it_can_get_commit_message
920943
run it_can_get_commit_timestamps
921944
run it_decrypts_git_crypted_files

0 commit comments

Comments
 (0)