From fbc6f95a02913a76cafc43a1886ef339f3b7ebde Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 29 Sep 2014 15:12:07 +0200 Subject: Protect default branch by default. --- CHANGELOG | 1 + app/services/git_push_service.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 3006ff4049d..78602c15e2c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ v 7.4.0 - Fix creating new files with web editor - Improve error reporting on users API (Julien Bianchi) - Refactor test coverage tools usage. Use SIMPLECOV=true to generate it locally + - Default branch is protected by default - Increase unicorn timeout to 60 seconds - Sort search autocomplete projects by stars count so most popular go first diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index fddfddb92ee..17c84c78d2d 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -29,6 +29,8 @@ class GitPushService if is_default_branch?(ref) # Initial push to the default branch. Take the full history of that branch as "newly pushed". @push_commits = project.repository.commits(newrev) + # Default branch is protected by default + project.protected_branches.create({ name: project.default_branch }) else # Use the pushed commits that aren't reachable by the default branch # as a heuristic. This may include more commits than are actually pushed, but -- cgit v1.2.1 From ab6459ad488e51a1477d48535c2cae6ce2d14a23 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 29 Sep 2014 16:07:53 +0200 Subject: Add a simple spec test. --- spec/services/git_push_service_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb index 9afa4953d61..4ef053a767f 100644 --- a/spec/services/git_push_service_spec.rb +++ b/spec/services/git_push_service_spec.rb @@ -105,6 +105,8 @@ describe GitPushService do context "execute web hooks" do it "when pushing a branch for the first time" do project.should_receive(:execute_hooks) + project.default_branch.should == "master" + project.protected_branches.should_receive(:create).with({ name: "master" }) service.execute(project, user, @blankrev, 'newrev', 'refs/heads/master') end -- cgit v1.2.1