Skip to content

Avoid auto-forking/pushing an already pushed branch in pr create#704

Merged
mislav merged 3 commits intomasterfrom
branch-push-detection
Mar 30, 2020
Merged

Avoid auto-forking/pushing an already pushed branch in pr create#704
mislav merged 3 commits intomasterfrom
branch-push-detection

Conversation

@mislav
Copy link
Copy Markdown
Contributor

@mislav mislav commented Mar 26, 2020

A branch is considered already pushed if its HEAD commit hash matches the commit hash of one of the remote tracking branches: refs/remotes/<remote>/<branch>

This mechanism allows the user to:

  • Choose a remote as push target for their branch different than the one that would automatically get chosen for them by pr create;
  • Avoid a git push operation (and its associated git hooks) if a push was not necessary in the first place.

Drawbacks:

  • If an older version of the branch is pushed to a remote, but later some new commits were added to the local branch, the existing remote tracking branch will intentionally not be considered a push target. This conservative approach is to avoid false positives due to:
    • One of the remotes having an unrelated branch that just so happens to share the same name as the local branch;
    • The local branch being created with a remote tracking branch as a starting point, e.g. git switch -c my-feature origin/master. With git default settings, this will auto-setup merge configuration (see branch.autoSetupMerge in git config), which gh could potentially falsely interpret as a push configuration as well, be it not for the strict commit hash matching.

Fixes #681
Ref. #684 #350 #684

TODO:

mislav added 3 commits March 26, 2020 19:21
This is so we can pass a list of full qualified refs and have them
resolved for both existence and their commit hashes.
A valid remote specificication read from `branch.<name>.remote` git
config can be a URL, a `.`, a filesystem path, and a remote name. When
detecting the remote name, be sure not to take filesystem paths instead.
A branch is considered already pushed if its HEAD commit hash matches
the commit hash of one of the remote tracking branches:
`refs/remotes/<remote>/<branch>`

This mechanism allows the user to:

- Choose a remote as push target for their branch different than the one
  that would automatically get chosen for them by `pr create`;

- Avoid a `git push` operation (and its associated git hooks) if a push
  was not necessary in the first place.
@mislav mislav requested a review from vilmibm March 26, 2020 19:41
Copy link
Copy Markdown
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Respect an already pushed branch in pr create

2 participants