Commit 253680bbffe2423a11d4fa8626c2b35c289ea8cc
Exists in
master
and in
4 other branches
Merge branch 'improve/default_branch' of /home/git/repositories/gitlab/gitlabhq
Showing
12 changed files
with
34 additions
and
22 deletions
Show diff stats
CHANGELOG
... | ... | @@ -9,6 +9,8 @@ v 6.3.0 |
9 | 9 | - Fixed issue with 500 error when group did not exist |
10 | 10 | - Ability to leave project |
11 | 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 | 15 | v 6.2.0 |
14 | 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 | 3 | def execute(role = :default) |
4 | 4 | params[:project].delete(:namespace_id) |
5 | 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 | 16 | project.update_attributes(params[:project], as: role) |
7 | 17 | end |
8 | 18 | end | ... | ... |
app/models/project.rb
... | ... | @@ -28,7 +28,7 @@ class Project < ActiveRecord::Base |
28 | 28 | include Gitlab::ShellAdapter |
29 | 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 | 32 | :issues_enabled, :wall_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id, |
33 | 33 | :wiki_enabled, :public, :import_url, :last_activity_at, as: [:default, :admin] |
34 | 34 | |
... | ... | @@ -36,6 +36,8 @@ class Project < ActiveRecord::Base |
36 | 36 | |
37 | 37 | acts_as_taggable_on :labels, :issues_default_labels |
38 | 38 | |
39 | + attr_accessor :new_default_branch | |
40 | + | |
39 | 41 | # Relations |
40 | 42 | belongs_to :creator, foreign_key: "creator_id", class_name: "User" |
41 | 43 | belongs_to :group, foreign_key: "namespace_id", conditions: "type = 'Group'" |
... | ... | @@ -143,7 +145,7 @@ class Project < ActiveRecord::Base |
143 | 145 | end |
144 | 146 | |
145 | 147 | def repository |
146 | - @repository ||= Repository.new(path_with_namespace, default_branch) | |
148 | + @repository ||= Repository.new(path_with_namespace) | |
147 | 149 | end |
148 | 150 | |
149 | 151 | def saved? |
... | ... | @@ -451,4 +453,8 @@ class Project < ActiveRecord::Base |
451 | 453 | def project_member(user) |
452 | 454 | users_projects.where(user_id: user).first |
453 | 455 | end |
456 | + | |
457 | + def default_branch | |
458 | + @default_branch ||= repository.root_ref if repository.exists? | |
459 | + end | |
454 | 460 | end | ... | ... |
app/models/repository.rb
... | ... | @@ -3,7 +3,7 @@ class Repository |
3 | 3 | |
4 | 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 | 7 | @path_with_namespace = path_with_namespace |
8 | 8 | @raw_repository = Gitlab::Git::Repository.new(path_to_repo) if path_with_namespace |
9 | 9 | rescue Gitlab::Git::Repository::NoRepository | ... | ... |
app/observers/project_observer.rb
... | ... | @@ -30,12 +30,6 @@ class ProjectObserver < BaseObserver |
30 | 30 | def after_update(project) |
31 | 31 | project.send_move_instructions if project.namespace_id_changed? |
32 | 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 | 33 | end |
40 | 34 | |
41 | 35 | def before_destroy(project) | ... | ... |
db/schema.rb
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | # |
12 | 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 | 16 | create_table "deploy_keys_projects", :force => true do |t| |
17 | 17 | t.integer "deploy_key_id", :null => false |
... | ... | @@ -171,7 +171,6 @@ ActiveRecord::Schema.define(:version => 20131009115346) do |
171 | 171 | t.datetime "created_at", :null => false |
172 | 172 | t.datetime "updated_at", :null => false |
173 | 173 | t.integer "creator_id" |
174 | - t.string "default_branch" | |
175 | 174 | t.boolean "issues_enabled", :default => true, :null => false |
176 | 175 | t.boolean "wall_enabled", :default => true, :null => false |
177 | 176 | t.boolean "merge_requests_enabled", :default => true, :null => false | ... | ... |
doc/api/projects.md
... | ... | @@ -213,7 +213,6 @@ Parameters: |
213 | 213 | |
214 | 214 | + `name` (required) - new project name |
215 | 215 | + `description` (optional) - short project description |
216 | -+ `default_branch` (optional) - 'master' by default | |
217 | 216 | + `issues_enabled` (optional) |
218 | 217 | + `wall_enabled` (optional) |
219 | 218 | + `merge_requests_enabled` (optional) | ... | ... |
features/steps/public/projects_feature.rb
... | ... | @@ -23,7 +23,7 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps |
23 | 23 | end |
24 | 24 | |
25 | 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 | 27 | end |
28 | 28 | |
29 | 29 | step 'public empty project "Empty Public Project"' do | ... | ... |
lib/api/projects.rb
... | ... | @@ -60,7 +60,6 @@ module API |
60 | 60 | # Parameters: |
61 | 61 | # name (required) - name for new project |
62 | 62 | # description (optional) - short project description |
63 | - # default_branch (optional) - 'master' by default | |
64 | 63 | # issues_enabled (optional) |
65 | 64 | # wall_enabled (optional) |
66 | 65 | # merge_requests_enabled (optional) |
... | ... | @@ -75,7 +74,6 @@ module API |
75 | 74 | attrs = attributes_for_keys [:name, |
76 | 75 | :path, |
77 | 76 | :description, |
78 | - :default_branch, | |
79 | 77 | :issues_enabled, |
80 | 78 | :wall_enabled, |
81 | 79 | :merge_requests_enabled, | ... | ... |
spec/models/merge_request_spec.rb
... | ... | @@ -116,13 +116,13 @@ describe MergeRequest do |
116 | 116 | end |
117 | 117 | |
118 | 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 | 121 | subject.closes_issues.should == [issue0, issue1].sort_by(&:id) |
122 | 122 | end |
123 | 123 | |
124 | 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 | 126 | subject.target_branch = 'something-else' |
127 | 127 | |
128 | 128 | subject.closes_issues.should be_empty | ... | ... |
spec/requests/api/projects_spec.rb
... | ... | @@ -91,7 +91,6 @@ describe API::API do |
91 | 91 | it "should assign attributes to project" do |
92 | 92 | project = attributes_for(:project, { |
93 | 93 | description: Faker::Lorem.sentence, |
94 | - default_branch: 'stable', | |
95 | 94 | issues_enabled: false, |
96 | 95 | wall_enabled: false, |
97 | 96 | merge_requests_enabled: false, |
... | ... | @@ -110,16 +109,13 @@ describe API::API do |
110 | 109 | project = attributes_for(:project, { public: true }) |
111 | 110 | post api("/projects", user), project |
112 | 111 | json_response['public'].should be_true |
113 | - | |
114 | 112 | end |
115 | 113 | |
116 | 114 | it "should set a project as private" do |
117 | 115 | project = attributes_for(:project, { public: false }) |
118 | 116 | post api("/projects", user), project |
119 | 117 | json_response['public'].should be_false |
120 | - | |
121 | 118 | end |
122 | - | |
123 | 119 | end |
124 | 120 | |
125 | 121 | describe "POST /projects/user/:id" do |
... | ... | @@ -146,7 +142,6 @@ describe API::API do |
146 | 142 | it "should assign attributes to project" do |
147 | 143 | project = attributes_for(:project, { |
148 | 144 | description: Faker::Lorem.sentence, |
149 | - default_branch: 'stable', | |
150 | 145 | issues_enabled: false, |
151 | 146 | wall_enabled: false, |
152 | 147 | merge_requests_enabled: false, | ... | ... |