Detect the upstream branch name when base is not specified #139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the
lint-prepush
command assumesmaster
as a base branch in the project.While the configuration does allow this to be explicitly overridden we can potentially provide a default behavior that works even when a project doesn't use
master
as a base branch.Changes
When the
base
branch is not explicitly specified, instead of defaulting tomaster
,git rev-parse
can be used to determine the named git ref for the remote branch being pushed to.For example, I'm on a local branch named
fix/hard-coded-master
, and it is set to useorigin/fix/hard-coded-master
as the upstream branch.Using
git rev-parse
when can see what the current branch's upsream ref is:Using this information, when the
base
branch is not explicitly specified and the local branch has an upstream branch, we can now use these two refs withgit diff
to get the list of relevant files.Here's the command as
utils/fetchGitDiff.js
would run it:How To Test
Make sure the local branch has an upstream branch and the
base
is not specified inpackage.json
:Clear out the
.lint-prepush
cache:Reset the remote branch to remove the local branch's commits if they've already been pushed:
Run
git push
withDEBUG=*