Branch name Push Rule prevents you from deleting existing branches that don't match the regex

Zendesk: https://gitlab.zendesk.com/agent/tickets/85188 (GitLab internal link only)

Summary

With a Push Rule set to reject a branch name you cannot delete existing branch names that match the Push Rule's regex.

Steps to reproduce

  • Create a branch containing a -, e.g. hello-world
  • Create a Push Rule to reject branch names containing any non-word characters, e.g. ^(\w*)$
  • Try to delete the hello-world branch via the UI
  • The branch is not deleted and no errors are shown in the UI
  • Remove the Push Rule added above
  • Try to delete the hello-world branch again
  • Branch is successfully deleted

Example Project

https://gitlab.com/dummy-projects/branch-name-push-rule/branches

What is the current bug behavior?

  • With a Push Rule set, you can't delete branches matching that Push Rule
  • No error or message is shown in the UI

What is the expected correct behavior?

  • The branch should be deleted

Relevant logs and/or screenshots

Tested on 10.1.4 and customer who reported this is running 10.1.1

==> /var/log/gitlab/gitlab-rails/production.log <==
Started DELETE "/group-one/rails-template-one/branches/hello-world" for 192.168.10.1 at 2017-11-17 08:27:22 +0000
Processing by Projects::BranchesController#destroy as JS
  Parameters: {"namespace_id"=>"group-one", "project_id"=>"rails-template-one", "id"=>"hello-world"}
Started POST "/api/v4/internal/allowed" for 127.0.0.1 at 2017-11-17 08:27:22 +0000

==> /var/log/gitlab/gitlab-rails/api_json.log <==
{"time":"2017-11-17T08:27:22.867Z","severity":"INFO","duration":12.17,"db":1.81,"view":10.36,"status":200,"method":"POST","path":"/api/v4/internal/allowed","params":{"action":"git-receive-pack","changes":"12a50b434f533cfc8f9708babef09f46aaef9fb4 0000000000000000000000000000000000000000 refs/heads/hello-world\n","gl_repository":"project-1","project":"/var/opt/gitlab/git-data/repositories/group-one/rails-template-one.git","protocol":"web","env":"{\"GIT_ALTERNATE_OBJECT_DIRECTORIES\":null,\"GIT_OBJECT_DIRECTORY\":null}","user_id":"2","secret_token":"[FILTERED]"},"host":"127.0.0.1","ip":"127.0.0.1","ua":"Ruby"}

==> /var/log/gitlab/gitlab-shell/gitlab-shell.log <==
I, [2017-11-17T08:27:22.868373 #30772]  INFO -- : POST http://127.0.0.1:8080/api/v4/internal/allowed 0.01664

==> /var/log/gitlab/gitlab-rails/production.log <==
Completed 400 Bad Request in 139ms (Views: 0.3ms | ActiveRecord: 1.1ms | Elasticsearch: 0.0ms)

==> /var/log/gitlab/gitlab-rails/production_json.log <==
{"method":"DELETE","path":"/group-one/rails-template-one/branches/hello-world","format":"js","controller":"Projects::BranchesController","action":"destroy","status":400,"duration":140.18,"view":0.31,"db":1.15,"time":"2017-11-17T08:27:22.733Z","params":{"namespace_id":"group-one","project_id":"rails-template-one","id":"hello-world"},"remote_ip":"192.168.10.1","user_id":2,"username":"user1","gitaly_calls":3}

==> /var/log/gitlab/gitlab-workhorse/current <==
2017-11-17_08:27:22.87504 gitlab-ee-latest @ - - [2017-11-17 08:27:22.719549275 +0000 UTC] "DELETE /group-one/rails-template-one/branches/hello-world HTTP/1.1" 400 0 "http://gitlab-ee-latest/group-one/rails-template-one/branches" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36" 0.155374

==> /var/log/gitlab/nginx/gitlab_access.log <==
192.168.10.1 - - [17/Nov/2017:08:27:22 +0000] "DELETE /group-one/rails-template-one/branches/hello-world HTTP/1.1" 400 0 "http://gitlab-ee-latest/group-one/rails-template-one/branches" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"

Reproducing this from the Rails console throws an error pointing at the Push Rule regex:

irb(main):017:0> p = Project.find_by_full_path('group-one/rails-template-one')
=> #<Project id:1 group-one/rails-template-one>
irb(main):018:0> u = User.find_by_username('root')
=> #<User id:1 @root>
irb(main):019:0> DeleteBranchService.new(p, u).execute('hello-world')
=> {:message=>"GitLab: Branch name does not follow the pattern '^(\\w*)$'<br>", :status=>:error, :return_code=>400}
Edited Nov 20, 2017 by Collen
Assignee Loading
Time tracking Loading