Unverified Commit 9d14c513 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

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: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 31d4d6b30e4c
...@@ -3,6 +3,16 @@ class UpdateContext < BaseContext ...@@ -3,6 +3,16 @@ class UpdateContext < BaseContext
def execute(role = :default) def execute(role = :default)
params[:project].delete(:namespace_id) params[:project].delete(:namespace_id)
params[:project].delete(:public) unless can?(current_user, :change_public_mode, project) params[:project].delete(:public) unless can?(current_user, :change_public_mode, project)
new_branch = params[:project].delete(:default_branch)
if project.repository.exists? && new_branch != project.repository.root_ref
GitlabShellWorker.perform_async(
:update_repository_head,
project.path_with_namespace,
new_branch
)
end
project.update_attributes(params[:project], as: role) project.update_attributes(params[:project], as: role)
end end
end end
......
...@@ -28,7 +28,7 @@ class Project < ActiveRecord::Base ...@@ -28,7 +28,7 @@ class Project < ActiveRecord::Base
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
extend Enumerize extend Enumerize
attr_accessible :name, :path, :description, :default_branch, :issues_tracker, :label_list, attr_accessible :name, :path, :description, :issues_tracker, :label_list,
:issues_enabled, :wall_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id, :issues_enabled, :wall_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id,
:wiki_enabled, :public, :import_url, :last_activity_at, as: [:default, :admin] :wiki_enabled, :public, :import_url, :last_activity_at, as: [:default, :admin]
...@@ -36,6 +36,8 @@ class Project < ActiveRecord::Base ...@@ -36,6 +36,8 @@ class Project < ActiveRecord::Base
acts_as_taggable_on :labels, :issues_default_labels acts_as_taggable_on :labels, :issues_default_labels
attr_accessor :new_default_branch
# Relations # Relations
belongs_to :creator, foreign_key: "creator_id", class_name: "User" belongs_to :creator, foreign_key: "creator_id", class_name: "User"
belongs_to :group, foreign_key: "namespace_id", conditions: "type = 'Group'" belongs_to :group, foreign_key: "namespace_id", conditions: "type = 'Group'"
...@@ -143,7 +145,7 @@ def team ...@@ -143,7 +145,7 @@ def team
end end
def repository def repository
@repository ||= Repository.new(path_with_namespace, default_branch) @repository ||= Repository.new(path_with_namespace)
end end
def saved? def saved?
...@@ -451,4 +453,8 @@ def reset_events_cache ...@@ -451,4 +453,8 @@ def reset_events_cache
def project_member(user) def project_member(user)
users_projects.where(user_id: user).first users_projects.where(user_id: user).first
end end
def default_branch
@default_branch ||= repository.root_ref if repository.exists?
end
end end
...@@ -3,7 +3,7 @@ class Repository ...@@ -3,7 +3,7 @@ class Repository
attr_accessor :raw_repository, :path_with_namespace attr_accessor :raw_repository, :path_with_namespace
def initialize(path_with_namespace, default_branch) def initialize(path_with_namespace, default_branch = nil)
@path_with_namespace = path_with_namespace @path_with_namespace = path_with_namespace
@raw_repository = Gitlab::Git::Repository.new(path_to_repo) if path_with_namespace @raw_repository = Gitlab::Git::Repository.new(path_to_repo) if path_with_namespace
rescue Gitlab::Git::Repository::NoRepository rescue Gitlab::Git::Repository::NoRepository
......
...@@ -30,12 +30,6 @@ def after_create(project) ...@@ -30,12 +30,6 @@ def after_create(project)
def after_update(project) def after_update(project)
project.send_move_instructions if project.namespace_id_changed? project.send_move_instructions if project.namespace_id_changed?
project.rename_repo if project.path_changed? project.rename_repo if project.path_changed?
GitlabShellWorker.perform_async(
:update_repository_head,
project.path_with_namespace,
project.default_branch
) if project.default_branch_changed?
end end
def before_destroy(project) def before_destroy(project)
......
class RemoveDefaultBranch < ActiveRecord::Migration
def up
remove_column :projects, :default_branch
end
def down
add_column :projects, :default_branch, :string
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20131009115346) do ActiveRecord::Schema.define(:version => 20131106151520) do
create_table "deploy_keys_projects", :force => true do |t| create_table "deploy_keys_projects", :force => true do |t|
t.integer "deploy_key_id", :null => false t.integer "deploy_key_id", :null => false
...@@ -171,7 +171,6 @@ ...@@ -171,7 +171,6 @@
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.integer "creator_id" t.integer "creator_id"
t.string "default_branch"
t.boolean "issues_enabled", :default => true, :null => false t.boolean "issues_enabled", :default => true, :null => false
t.boolean "wall_enabled", :default => true, :null => false t.boolean "wall_enabled", :default => true, :null => false
t.boolean "merge_requests_enabled", :default => true, :null => false t.boolean "merge_requests_enabled", :default => true, :null => false
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment