OSDN Git Service

default_branch for project & fixed project destroy
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Wed, 7 Dec 2011 21:56:57 +0000 (23:56 +0200)
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Wed, 7 Dec 2011 21:56:57 +0000 (23:56 +0200)
app/controllers/application_controller.rb
app/models/project.rb
app/views/layouts/project.html.haml
app/views/projects/_form.html.haml
db/migrate/20111207211728_add_default_branch_to_project.rb [new file with mode: 0644]
db/schema.rb
lib/gitlabhq/gitolite.rb

index dd0c3c3..6f7ed9a 100644 (file)
@@ -61,7 +61,7 @@ class ApplicationController < ActionController::Base
     else
       @branch = params[:branch].blank? ? nil : params[:branch]
       @tag = params[:tag].blank? ? nil : params[:tag]
-      @ref = @branch || @tag || Repository.default_ref
+      @ref = @branch || @tag || @project.try(:default_branch) || Repository.default_ref
     end
   end
 
index d881b4d..a536131 100644 (file)
@@ -158,7 +158,7 @@ class Project < ActiveRecord::Base
   end
 
   def root_ref 
-    "master"
+    default_branch || "master"
   end
 
   def public?
index 90d8a54..8a39dec 100644 (file)
@@ -49,7 +49,7 @@
                   %span{ :class => "number" }= @project.snippets.non_expired.count
 
               - if can? current_user, :admin_project, @project
-                = link_to "Project", edit_project_path(@project), :class => (current_page?(edit_project_path(@project))) ? "current" : nil
+                = link_to "Admin", edit_project_path(@project), :class => (current_page?(edit_project_path(@project))) ? "current" : nil
 
             .medium-tags{:style => 'padding: 10px 0 0 10px; width: 210px;'}= tag_list @project
 
index ce2fd06..5901801 100644 (file)
           %cite.right= "http://#{GIT_HOST["host"]}/"
         %td= f.text_field :code, :placeholder => "example"
 
+      - unless @project.heads.empty?  
+        %tr
+          %td= f.label :default_branch, "Default Branch"
+          %td= f.select(:default_branch, @project.heads.map(&:name), {}, :style => "width:300px;")
+
       %tr
         %td= f.label :tag_list
         %td= f.text_area :tag_list, :placeholder => "project tags", :style => "height:50px", :id => :tag_field
@@ -57,4 +62,5 @@
 :javascript
   $(function(){
     taggifyForm();
+    $('form #project_default_branch').chosen();
   })
diff --git a/db/migrate/20111207211728_add_default_branch_to_project.rb b/db/migrate/20111207211728_add_default_branch_to_project.rb
new file mode 100644 (file)
index 0000000..5c2107f
--- /dev/null
@@ -0,0 +1,5 @@
+class AddDefaultBranchToProject < ActiveRecord::Migration
+  def change
+    add_column :projects, :default_branch, :string, :null => false, :default => "master"
+  end
+end
index fd50bf3..17246a6 100644 (file)
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20111206222316) do
+ActiveRecord::Schema.define(:version => 20111207211728) do
 
   create_table "features", :force => true do |t|
     t.string   "name"
@@ -76,9 +76,10 @@ ActiveRecord::Schema.define(:version => 20111206222316) do
     t.text     "description"
     t.datetime "created_at"
     t.datetime "updated_at"
-    t.boolean  "private_flag", :default => true, :null => false
+    t.boolean  "private_flag",   :default => true,     :null => false
     t.string   "code"
     t.integer  "owner_id"
+    t.string   "default_branch", :default => "master", :null => false
   end
 
   create_table "snippets", :force => true do |t|
index 10ab87b..e79afb5 100644 (file)
@@ -42,7 +42,7 @@ module Gitlabhq
     end
 
     def destroy_project(project)
-      `sudo -u git rm -rf #{project.path_to_repo}`
+      FileUtils.rm_rf(project.path_to_repo)
       
       ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite'))
       conf = ga_repo.config