Skip to content

Docs: issues inferring branch (e.g. in Travis build) #136

@OliverJAsh

Description

@OliverJAsh

I just noticed that all of my builds are uploading with their branch set to HEAD. IIUC, this is because of the way Travis builds work—they clone the repository then checkout a specific commit (e.g. abc) rather than a branch name (e.g. master):

$ git clone  --branch=master https://github.com/unsplash/unsplash-web.git unsplash/unsplash-web
Cloning into 'unsplash/unsplash-web'...
$ cd unsplash/unsplash-web
$ git checkout -qf 67babfc8143aab900f9660c2c933388e0b9e7125

This means that when the build tracker CLI tries to infer the branch name via git rev-parse --abbrev-ref HEAD, we will get HEAD instead of the actual branch name.

You can see this for yourself by running these commands locally:

$ git checkout master
$ git rev-parse --abbrev-ref HEAD
master
$ git checkout `git rev-parse master`
$ git rev-parse --abbrev-ref HEAD
HEAD

I understand this is why the --branch flag is useful. Perhaps we could have some docs on the site to outline the problem and the recommended solution, as otherwise it might not be obvious why this happens nor how to fix it?

For future reference, I managed to specify the branch name using the environment variables provided by Travis: TRAVIS_PULL_REQUEST_BRANCH and TRAVIS_BRANCH (https://docs.travis-ci.com/user/environment-variables/#default-environment-variables).

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Low priority

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions