Skip to content

Is there a way to pass --no-verify when creating a PR? #684

Description

@CExWHamdan

Sometimes I would like to be able to create a PR without running the pre-commit and commit-msg pre-push hooks when pushing the changes. Is that possible?

Edit: Replaced pre-commit and commit-msg with pre-push.

Activity

  1. mislav commented on Mar 20, 2020

    @mislav
    Contributor

    Hi, thanks for the suggestion!

    During pr create, the only git command that we shell out to is git push. Therefore the only git hook that I can imagine running is the pre-push hook. We don't create commits, so I'm confused as to how pre-commit and commit-msg are running for you. Could you check whether some of your git hooks invoke other hooks?

    We did not have a plan to support --no-verify, but we do have a plan to respect an already-pushed branch. That way, if you do something like this, gh wouldn't shell out to git at all:

    git push --no-verify <remote> HEAD
    gh pr create

    Would this be sufficient?

  2. CExWHamdan commented on Mar 20, 2020

    @CExWHamdan
    Author

    Sorry, I meant pre-push hooks.

    I was just hoping I can do it all through gh instead of having to push the branch via git with the --no-verify flag and then creating the PR through gh as you suggested.

    Hope you consider that in the future. Thank you!

  3. mislav commented on Mar 26, 2020

    @mislav
    Contributor

    I was just hoping I can do it all through gh instead of having to push the branch via git with the --no-verify flag

    That makes sense. We will consider supporting a flag such as --no-verify. But it's likelier that before that we already ship a fix that respects if a branch has been manually push, which at least gives you a temporary workaround.

  4. mislav commented on Mar 30, 2020

    @mislav
    Contributor

    We did not have a plan to support --no-verify, but we do have a plan to respect an already-pushed branch. That way, if you do something like this, gh wouldn't shell out to git at all:

    git push --no-verify <remote> HEAD
    gh pr create

    Just a note that the feature described here just landed in master and is slated for release this week. No plan yet for adding --no-verify to gh pr create yet, but we will keep this and related requests in mind!

  5. nl-ria commented on Aug 17, 2020

    @nl-ria

    Hi ! Unfortunately, the fix #704 doesnt seem to be working as expected.

    I am doing the following to create a PR using gh and making my commits and push using git, since there is no way to pass --no-verify in gh pr create.

    $ git push --no-verify -u origin $BRANCH_NAME
    $ gh pr create

    But in the output, I can still see the pre-push hooks running for gh pr create

    ...
    Creating pull request for $BRANCH_NAME into master in $REPO_NAME
    husky > pre-push (node v12.16.2)
    ...
    

    The branch is successfully created on Github, since I am passing --no-verify flag with git push. However, creating a PR is failing because I cannot pass the --no-verify flag with gh pr create

    I am using the latest version of gh cli

    $ gh --version
    gh version 0.11.1 (2020-07-28)
    https://github.com/cli/cli/releases/tag/v0.11.1
    
  6. mislav commented on Aug 17, 2020

    @mislav
    Contributor

    @nl-ria Thank you for reporting!

    I just tried to reproduce this using the commands you provided, and I couldn't, but it's still possible that there is a bug here. If you use the DEBUG=1 environment variable when running gh, you will get verbose output that should include all underlying invocations of git. Can you share with us the output? (You may anonymize branch names.)

  7. nl-ria commented on Aug 17, 2020

    @nl-ria

    @mislav - thanks for getting back so quickly, here is output in debug mode

    Running command
    $ gh pr create --title "$title" --body "$body"

    Output

    [git remote -v]
    * Request at 2020-08-17 13:12:38.706138 +0100 BST m=+0.037714513
    * Request to https://api.github.com/graphql
    * Request took 811.334796ms
    [git symbolic-ref --quiet --short HEAD]
    [git config --get-regexp ^branch\.$BRANCH_NAME\.(remote|merge)$]
    [git show-ref --verify -- HEAD refs/remotes/origin/$BRANCH_NAME refs/remotes/origin/$BRANCH_NAME]
    * Request at 2020-08-17 13:12:39.546963 +0100 BST m=+0.878513929
    * Request to https://api.github.com/graphql
    * Request took 380.311856ms
    [git status --porcelain]
    [git -c log.ShowSignature=false log --pretty=format:%H,%s --cherry origin/master...$BRANCH_NAME]
    [git -c log.ShowSignature=false show -s --pretty=format:%b e66d5583a31bc87298d4b8a62daa9922531226fa]
    * Request at 2020-08-17 13:12:40.014256 +0100 BST m=+1.345793091
    * Request to https://api.github.com/graphql
    * Request took 300.451734ms
    
    Creating pull request for $BRANCH_NAME into master in $REPO_NAME
    
    [git push --set-upstream origin HEAD:$BRANCH_NAME]
    husky > pre-push (node v12.16.2)
    .... 
    runs the pre-push github hooks and fails as expected
    ....
    husky > pre-push hook failed (add --no-verify to bypass)
    error: failed to push some refs to '$REPO_NAME'
    exit status 1
    
  8. mislav commented on Aug 17, 2020

    @mislav
    Contributor

    @nl-ria Thank you for the debug output!

    Nothing stands out to me as potentially wrong in the log. 😕 Could you check the output of git show-ref --verify -- HEAD refs/remotes/origin/$BRANCH_NAME refs/remotes/origin/$BRANCH_NAME after you put in your actual branch name? It should be something like this, where you can see that the commit SHAs are identical:

    $ git show-ref --verify -- HEAD refs/remotes/origin/"$(git branch --show-current)"
    27b0c83f1c1f2d6e705426cf1d3926f0c5b1fa47 HEAD
    27b0c83f1c1f2d6e705426cf1d3926f0c5b1fa47 refs/remotes/origin/gh-pre-push-test
    

    And also please your git version 🙇

  9. nl-ria commented on Aug 17, 2020

    @nl-ria

    oh, interesting, not sure why, but getting an error when trying to get the output of the above command

    $ git show-ref --verify -- HEAD refs/remotes/origin/$BRANCH_NAME refs/remotes/origin/$BRANCH_NAME
    

    Output

    e66d5583a31bc87298d4b8a62daa9922531226fa HEAD
    fatal: 'refs/remotes/origin/$BRANCH_NAME' - not a valid ref
    

    Could you explain what this command means? I can see the same commit SHA on Github on $BRANCH_NAME, so not quite sure why its erring on my local machine.

    My Git version :

    $ git --version
    git version 2.28.0
    
  10. mislav commented on Aug 17, 2020

    @mislav
    Contributor

    @nl-ria What usually happens when you do something like git push origin mybranch is that git performs the push, but also creates what it calls a "remote-tracking branch". In this case, the remote-tracking branch is called origin/mybranch for short, but the fully qualified ref name for it would be refs/remotes/origin/mybranch.

    Your git push obviously succeeded, but the remote-tracking branch was not created and thus gh could not detect that the branch was already pushed. I'm not sure why is that, but it could be due to unconventional git config --get-all remote.origin.fetch configuration, or some other factors.

    In any case, it's clear to me from your and other people's reported cases that we need an explicit option to disallow the auto-fork/auto-push behavior so that we don't rely on brittle detection mechanisms. Thank you for your input! Unfortunately, I do not have a suitable workaround to suggest right now.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions