Environment variable for fetch refspec?

I need to be able to obtain commits outside the pull request branch that is fetched by travis using git fetch during the cloning stage of a Travis build (for example here). This operation appears to be built using the fetch_ref function.

This additional work is needed to be able to perform static analysis on the changes in the branch and to exclude code already committed to master.

In order to obtain the necessary commits, I do a git fetch --shallow-exclude=master origin BRANCH. This works fine if the PR branch is in our repo, but does not work is it comes from a GitHub fork, since the repo is not origin in that case, and GitHub does not call the refspec BRANCH, but rather something like +refs/pull/1301/merge. This refspec is available to Travis in the data.ref variable as can be seen in the clone.rb file linked above, but I don’t see any env-var which makes this available to the build environment.

Is there a way to obtain this value?