Cannot create master branch in repo with existing project-level branch permission for default branch

XMLWordPrintable

    • 4
    • Severity 2 - Major
    • 4

      Issue Summary

      This is reproducible on Data Center: (yes)

      We encounter a problem in Bitbucket.

      • We have a project-level branch permission for default branch ("master") where deletion and rewriting history is prevented.
      • One of our repo does not have any branch defined (especially not master),
      • In this repo we have existing commits with tags.

      -> when we click on "Branch permissions" in the repo we get a page displaying "500 Internal server error"
      -> when we try to create a branch called "master" via bitbucket on one of the tags we get an info stating

      "Branch creation cancelled. Repository hook com.atlassian.bitbucket.server.bitbucket-ref-restriction:restrictionEnforcerHook failed No default branch is defined"
      

      When we remove the branch permission from the project, we are able to create the branch.

      In our point of view

      • it should be possible to create a branch
      • there should be no error-500 page in this case

      ------------------------------------

      BR Michael

      Steps to Reproduce

      We need to simulate the case with GIT repositories without branches that were imported into the previous Bitbucket version, 7.16. The steps below contain copying .git of some existing repo to get to the point right after the upgrade from 7.16 to 8.16 with existing repos without branches.

      1. Tested with Bitbucket 8.16.0 and 8.17.0, it behaves the same.
      2. In Bitbucket web UI, create a new GIT repository ("branchless"), and let Bitbucket select the default branch name.
      3. Clone that empty repository to workstation, for example
        git clone ssh://git@BITBUCKET_HOST/dcnw1/branchless.git
        
      4. On the workstation, copy the .git directory from some existing small repository to the newly cloned one.
        Execute the next steps in the newly cloned repo.
      5. Edit the file .git/config and remove references to old branches and remotes.
      6. Add remote, point to new repository:
        git remote add origin ssh://git@BITBUCKET_HOST/dcnw1/branchless.git
      7. Add tag:
        git tag -a tag1 -m "tag 1"
        
      8. Checkout to tag - detached HEAD state
        git checkout tag1
        
      9. Remove "master" branch
        git branch -d master
        
      10. Push tag
        git push origin tag1
        
      11. We now have some files in Bitbucket's Git repository, without any branch but with one tag.
        This is the situation right after the upgrade from Bitbucket 7.16 to 8.16.
      12. In Bitbucket web UI, go to "Repository settings / Branch permissions" and confirm you see the message The default branch is set to "refs/heads/master" but does not exist. Configure the default branch in the repository settings. - there is no error shown.
      13. Now, go to Bitbucket web UI and define branch permission on a project level: "Add permission", select "Branching model" and select "Development - Default branch", select/check any restriction (for example, "Prevent deletion"). Click "Save".
      14. Now, again go to the "branchless" Git repository in Bitbucket Web UI, then "Repository settings / Branch permissions". There is "500. Internal server error"
      15. From now on, it is not possible to push tags to this repository anymore:
        git tag -a tag2 -m "tag 2"
        git push origin tag2
        Enumerating objects: 1, done.
        Counting objects: 100% (1/1), done.
        Writing objects: 100% (1/1), 160 bytes | 160.00 KiB/s, done.
        Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
        remote: Repository hook com.atlassian.bitbucket.server.bitbucket-ref-restriction:restrictionEnforcerHook failed
        remote: No default branch is defined
        To ssh:/BITBUCKET_HOST/dcnw1/branchless-2.git
         ! [remote rejected] tag2 -> tag2 (pre-receive hook declined)
        error: failed to push some refs to 'ssh://BITBUCKET_HOST/dcnw1/branchless-2.git'
        

      Expected Results

      • No error shown in repo's "Branch permissions".
      • Able to push tags, branches.

      Actual Results

      • Repo's "Branch permissions" shows Error 500
      • It is not possible to push to the repo:
        remote: Repository hook com.atlassian.bitbucket.server.bitbucket-ref-restriction:restrictionEnforcerHook failed
        remote: No default branch is defined
        To ssh:/BITBUCKET_HOST/dcnw1/branchless-2.git
         ! [remote rejected] tag2 -> tag2 (pre-receive hook declined)
        error: failed to push some refs to 'ssh://BITBUCKET_HOST/dcnw1/branchless-2.git'
        

      Workaround

      Workaround is to remove branch permissions that are set on project level.

            Assignee:
            Unassigned
            Reporter:
            Nenad Opsenica (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: