Commit 9d14c5137a5a82ed8edd353ac7e6ed701fc6f49d
1 parent
d618a5fe
Exists in
master
and in
4 other branches
Project#default_branch use repo HEAD instead of DB value now
Drop default_branch field from projects table Use repository.root_ref as value for defautl_branch method Fixes issue with default_branch and HEAD getting out of sync Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
6 changed files
with
29 additions
and
11 deletions
Show diff stats
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 | ... | ... |