Commit 253680bbffe2423a11d4fa8626c2b35c289ea8cc

Authored by Dmitriy Zaporozhets
2 parents d618a5fe 7ab3bf96

Merge branch 'improve/default_branch' of /home/git/repositories/gitlab/gitlabhq

@@ -9,6 +9,8 @@ v 6.3.0 @@ -9,6 +9,8 @@ v 6.3.0
9 - Fixed issue with 500 error when group did not exist 9 - Fixed issue with 500 error when group did not exist
10 - Ability to leave project 10 - Ability to leave project
11 - You can create file in repo using UI 11 - You can create file in repo using UI
  12 + - API: dropped default_branch attribute from project during creation
  13 + - Project default_branch is not stored in db any more. It takes from repo now.
12 14
13 v 6.2.0 15 v 6.2.0
14 - Public project pages are now visible to everyone (files, issues, wik, etc.) 16 - Public project pages are now visible to everyone (files, issues, wik, etc.)
app/contexts/projects/update_context.rb
@@ -3,6 +3,16 @@ module Projects @@ -3,6 +3,16 @@ module Projects
3 def execute(role = :default) 3 def execute(role = :default)
4 params[:project].delete(:namespace_id) 4 params[:project].delete(:namespace_id)
5 params[:project].delete(:public) unless can?(current_user, :change_public_mode, project) 5 params[:project].delete(:public) unless can?(current_user, :change_public_mode, project)
  6 + new_branch = params[:project].delete(:default_branch)
  7 +
  8 + if project.repository.exists? && new_branch != project.repository.root_ref
  9 + GitlabShellWorker.perform_async(
  10 + :update_repository_head,
  11 + project.path_with_namespace,
  12 + new_branch
  13 + )
  14 + end
  15 +
6 project.update_attributes(params[:project], as: role) 16 project.update_attributes(params[:project], as: role)
7 end 17 end
8 end 18 end
app/models/project.rb
@@ -28,7 +28,7 @@ class Project < ActiveRecord::Base @@ -28,7 +28,7 @@ class Project < ActiveRecord::Base
28 include Gitlab::ShellAdapter 28 include Gitlab::ShellAdapter
29 extend Enumerize 29 extend Enumerize
30 30
31 - attr_accessible :name, :path, :description, :default_branch, :issues_tracker, :label_list, 31 + attr_accessible :name, :path, :description, :issues_tracker, :label_list,
32 :issues_enabled, :wall_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id, 32 :issues_enabled, :wall_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id,
33 :wiki_enabled, :public, :import_url, :last_activity_at, as: [:default, :admin] 33 :wiki_enabled, :public, :import_url, :last_activity_at, as: [:default, :admin]
34 34
@@ -36,6 +36,8 @@ class Project < ActiveRecord::Base @@ -36,6 +36,8 @@ class Project < ActiveRecord::Base
36 36
37 acts_as_taggable_on :labels, :issues_default_labels 37 acts_as_taggable_on :labels, :issues_default_labels
38 38
  39 + attr_accessor :new_default_branch
  40 +
39 # Relations 41 # Relations
40 belongs_to :creator, foreign_key: "creator_id", class_name: "User" 42 belongs_to :creator, foreign_key: "creator_id", class_name: "User"
41 belongs_to :group, foreign_key: "namespace_id", conditions: "type = 'Group'" 43 belongs_to :group, foreign_key: "namespace_id", conditions: "type = 'Group'"
@@ -143,7 +145,7 @@ class Project < ActiveRecord::Base @@ -143,7 +145,7 @@ class Project < ActiveRecord::Base
143 end 145 end
144 146
145 def repository 147 def repository
146 - @repository ||= Repository.new(path_with_namespace, default_branch) 148 + @repository ||= Repository.new(path_with_namespace)
147 end 149 end
148 150
149 def saved? 151 def saved?
@@ -451,4 +453,8 @@ class Project < ActiveRecord::Base @@ -451,4 +453,8 @@ class Project < ActiveRecord::Base
451 def project_member(user) 453 def project_member(user)
452 users_projects.where(user_id: user).first 454 users_projects.where(user_id: user).first
453 end 455 end
  456 +
  457 + def default_branch
  458 + @default_branch ||= repository.root_ref if repository.exists?
  459 + end
454 end 460 end
app/models/repository.rb
@@ -3,7 +3,7 @@ class Repository @@ -3,7 +3,7 @@ class Repository
3 3
4 attr_accessor :raw_repository, :path_with_namespace 4 attr_accessor :raw_repository, :path_with_namespace
5 5
6 - def initialize(path_with_namespace, default_branch) 6 + def initialize(path_with_namespace, default_branch = nil)
7 @path_with_namespace = path_with_namespace 7 @path_with_namespace = path_with_namespace
8 @raw_repository = Gitlab::Git::Repository.new(path_to_repo) if path_with_namespace 8 @raw_repository = Gitlab::Git::Repository.new(path_to_repo) if path_with_namespace
9 rescue Gitlab::Git::Repository::NoRepository 9 rescue Gitlab::Git::Repository::NoRepository
app/observers/project_observer.rb
@@ -30,12 +30,6 @@ class ProjectObserver < BaseObserver @@ -30,12 +30,6 @@ class ProjectObserver < BaseObserver
30 def after_update(project) 30 def after_update(project)
31 project.send_move_instructions if project.namespace_id_changed? 31 project.send_move_instructions if project.namespace_id_changed?
32 project.rename_repo if project.path_changed? 32 project.rename_repo if project.path_changed?
33 -  
34 - GitlabShellWorker.perform_async(  
35 - :update_repository_head,  
36 - project.path_with_namespace,  
37 - project.default_branch  
38 - ) if project.default_branch_changed?  
39 end 33 end
40 34
41 def before_destroy(project) 35 def before_destroy(project)
db/migrate/20131106151520_remove_default_branch.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class RemoveDefaultBranch < ActiveRecord::Migration
  2 + def up
  3 + remove_column :projects, :default_branch
  4 + end
  5 +
  6 + def down
  7 + add_column :projects, :default_branch, :string
  8 + end
  9 +end
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 # 11 #
12 # It's strongly recommended to check this file into your version control system. 12 # It's strongly recommended to check this file into your version control system.
13 13
14 -ActiveRecord::Schema.define(:version => 20131009115346) do 14 +ActiveRecord::Schema.define(:version => 20131106151520) do
15 15
16 create_table "deploy_keys_projects", :force => true do |t| 16 create_table "deploy_keys_projects", :force => true do |t|
17 t.integer "deploy_key_id", :null => false 17 t.integer "deploy_key_id", :null => false
@@ -171,7 +171,6 @@ ActiveRecord::Schema.define(:version =&gt; 20131009115346) do @@ -171,7 +171,6 @@ ActiveRecord::Schema.define(:version =&gt; 20131009115346) do
171 t.datetime "created_at", :null => false 171 t.datetime "created_at", :null => false
172 t.datetime "updated_at", :null => false 172 t.datetime "updated_at", :null => false
173 t.integer "creator_id" 173 t.integer "creator_id"
174 - t.string "default_branch"  
175 t.boolean "issues_enabled", :default => true, :null => false 174 t.boolean "issues_enabled", :default => true, :null => false
176 t.boolean "wall_enabled", :default => true, :null => false 175 t.boolean "wall_enabled", :default => true, :null => false
177 t.boolean "merge_requests_enabled", :default => true, :null => false 176 t.boolean "merge_requests_enabled", :default => true, :null => false
doc/api/projects.md
@@ -213,7 +213,6 @@ Parameters: @@ -213,7 +213,6 @@ Parameters:
213 213
214 + `name` (required) - new project name 214 + `name` (required) - new project name
215 + `description` (optional) - short project description 215 + `description` (optional) - short project description
216 -+ `default_branch` (optional) - 'master' by default  
217 + `issues_enabled` (optional) 216 + `issues_enabled` (optional)
218 + `wall_enabled` (optional) 217 + `wall_enabled` (optional)
219 + `merge_requests_enabled` (optional) 218 + `merge_requests_enabled` (optional)
features/steps/public/projects_feature.rb
@@ -23,7 +23,7 @@ class Spinach::Features::PublicProjectsFeature &lt; Spinach::FeatureSteps @@ -23,7 +23,7 @@ class Spinach::Features::PublicProjectsFeature &lt; Spinach::FeatureSteps
23 end 23 end
24 24
25 step 'public project "Community"' do 25 step 'public project "Community"' do
26 - create :project_with_code, name: 'Community', public: true, default_branch: 'master' 26 + create :project_with_code, name: 'Community', public: true
27 end 27 end
28 28
29 step 'public empty project "Empty Public Project"' do 29 step 'public empty project "Empty Public Project"' do
lib/api/projects.rb
@@ -60,7 +60,6 @@ module API @@ -60,7 +60,6 @@ module API
60 # Parameters: 60 # Parameters:
61 # name (required) - name for new project 61 # name (required) - name for new project
62 # description (optional) - short project description 62 # description (optional) - short project description
63 - # default_branch (optional) - 'master' by default  
64 # issues_enabled (optional) 63 # issues_enabled (optional)
65 # wall_enabled (optional) 64 # wall_enabled (optional)
66 # merge_requests_enabled (optional) 65 # merge_requests_enabled (optional)
@@ -75,7 +74,6 @@ module API @@ -75,7 +74,6 @@ module API
75 attrs = attributes_for_keys [:name, 74 attrs = attributes_for_keys [:name,
76 :path, 75 :path,
77 :description, 76 :description,
78 - :default_branch,  
79 :issues_enabled, 77 :issues_enabled,
80 :wall_enabled, 78 :wall_enabled,
81 :merge_requests_enabled, 79 :merge_requests_enabled,
spec/models/merge_request_spec.rb
@@ -116,13 +116,13 @@ describe MergeRequest do @@ -116,13 +116,13 @@ describe MergeRequest do
116 end 116 end
117 117
118 it 'accesses the set of issues that will be closed on acceptance' do 118 it 'accesses the set of issues that will be closed on acceptance' do
119 - subject.project.default_branch = subject.target_branch 119 + subject.project.stub(default_branch: subject.target_branch)
120 120
121 subject.closes_issues.should == [issue0, issue1].sort_by(&:id) 121 subject.closes_issues.should == [issue0, issue1].sort_by(&:id)
122 end 122 end
123 123
124 it 'only lists issues as to be closed if it targets the default branch' do 124 it 'only lists issues as to be closed if it targets the default branch' do
125 - subject.project.default_branch = 'master' 125 + subject.project.stub(default_branch: 'master')
126 subject.target_branch = 'something-else' 126 subject.target_branch = 'something-else'
127 127
128 subject.closes_issues.should be_empty 128 subject.closes_issues.should be_empty
spec/requests/api/projects_spec.rb
@@ -91,7 +91,6 @@ describe API::API do @@ -91,7 +91,6 @@ describe API::API do
91 it "should assign attributes to project" do 91 it "should assign attributes to project" do
92 project = attributes_for(:project, { 92 project = attributes_for(:project, {
93 description: Faker::Lorem.sentence, 93 description: Faker::Lorem.sentence,
94 - default_branch: 'stable',  
95 issues_enabled: false, 94 issues_enabled: false,
96 wall_enabled: false, 95 wall_enabled: false,
97 merge_requests_enabled: false, 96 merge_requests_enabled: false,
@@ -110,16 +109,13 @@ describe API::API do @@ -110,16 +109,13 @@ describe API::API do
110 project = attributes_for(:project, { public: true }) 109 project = attributes_for(:project, { public: true })
111 post api("/projects", user), project 110 post api("/projects", user), project
112 json_response['public'].should be_true 111 json_response['public'].should be_true
113 -  
114 end 112 end
115 113
116 it "should set a project as private" do 114 it "should set a project as private" do
117 project = attributes_for(:project, { public: false }) 115 project = attributes_for(:project, { public: false })
118 post api("/projects", user), project 116 post api("/projects", user), project
119 json_response['public'].should be_false 117 json_response['public'].should be_false
120 -  
121 end 118 end
122 -  
123 end 119 end
124 120
125 describe "POST /projects/user/:id" do 121 describe "POST /projects/user/:id" do
@@ -146,7 +142,6 @@ describe API::API do @@ -146,7 +142,6 @@ describe API::API do
146 it "should assign attributes to project" do 142 it "should assign attributes to project" do
147 project = attributes_for(:project, { 143 project = attributes_for(:project, {
148 description: Faker::Lorem.sentence, 144 description: Faker::Lorem.sentence,
149 - default_branch: 'stable',  
150 issues_enabled: false, 145 issues_enabled: false,
151 wall_enabled: false, 146 wall_enabled: false,
152 merge_requests_enabled: false, 147 merge_requests_enabled: false,