fork重名,提交
This commit is contained in:
parent
1c08c79e8e
commit
c1747ab217
|
@ -64,32 +64,53 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def forked
|
def forked
|
||||||
# 被forked的标识如果不满足单个用户唯一性,则不执行fork
|
# 如果当前用户已经fork过该项目,不会新fork项目,则跳至已fork的项
|
||||||
if is_sigle_identifier?(User.current, @repository.identifier)
|
unless has_forked?(@project, User.current)
|
||||||
# REDO: 那些人有权限forked项目
|
project = project_from_current_project(@project.id, User.current.id)
|
||||||
g = Gitlab.client
|
redirect_to project_path(project)
|
||||||
gproject = g.post ("/projects/fork/#{@project.gpid}?user_id=#{User.current.gid}")
|
|
||||||
if gproject
|
|
||||||
copy_project(@project, gproject)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
flash[:notice] = l(:project_gitlab_fork_double_message)
|
# 单个用户只能拥有一个名字一样的版本库,否则不能fork
|
||||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
# if is_sigle_identifier?(User.current, @repository.identifier)
|
||||||
|
# REDO: 那些人有权限forked项目
|
||||||
|
g = Gitlab.client
|
||||||
|
gproject = g.fork(@project.gpid, User.current.gid)
|
||||||
|
if gproject
|
||||||
|
copy_project(@project, gproject)
|
||||||
|
forked_count = @project.forked_count.to_i + 1
|
||||||
|
@project.update_attributes(:forked_count => forked_count)
|
||||||
|
end
|
||||||
|
# else
|
||||||
|
# flash[:notice] = l(:project_gitlab_fork_double_message)
|
||||||
|
# redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# 判断用户是否已经fork过该项目
|
||||||
|
def has_forked?(project, user)
|
||||||
|
projects = Project.where("user_id =?", user)
|
||||||
|
projects.map(&:forked_from_project_id).detect{|s| s == @project.id}.nil? ? true : false
|
||||||
|
end
|
||||||
|
|
||||||
|
# 获取当前用户fork过的项目
|
||||||
|
def project_from_current_project(project, user)
|
||||||
|
project = Project.where("user_id =? and forked_from_project_id =?",user, project).first
|
||||||
end
|
end
|
||||||
|
|
||||||
# copy a project for fork
|
# copy a project for fork
|
||||||
def copy_project(project, gproject)
|
def copy_project(tproject, gproject)
|
||||||
project = Project.new
|
project = Project.new
|
||||||
project.name = @project.name
|
project.name = tproject.name
|
||||||
project.is_public = @project.is_public
|
project.is_public = tproject.is_public
|
||||||
project.status = @project.status
|
project.status = tproject.status
|
||||||
project.description = @project.description
|
project.description = tproject.description
|
||||||
project.hidden_repo = @project.hidden_repo
|
project.hidden_repo = tproject.hidden_repo
|
||||||
project.user_id = User.current.id
|
project.user_id = User.current.id
|
||||||
project.project_type = 0
|
project.project_type = 0
|
||||||
project.project_new_type = @project.project_new_type
|
project.project_new_type = tproject.project_new_type
|
||||||
project.gpid = gproject.id
|
project.gpid = gproject.id
|
||||||
|
project.forked_from_project_id = tproject.id
|
||||||
if project.save
|
if project.save
|
||||||
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||||||
m = Member.new(:user => User.current, :roles => [r])
|
m = Member.new(:user => User.current, :roles => [r])
|
||||||
|
@ -124,16 +145,16 @@ class RepositoriesController < ApplicationController
|
||||||
|
|
||||||
def copy_repository(project, gproject)
|
def copy_repository(project, gproject)
|
||||||
# 避免
|
# 避免
|
||||||
if is_sigle_identifier?(project.user_id, gproject.name)
|
# if is_sigle_identifier?(project.user_id, gproject.name)
|
||||||
repository = Repository.factory('Git')
|
repository = Repository.factory('Git')
|
||||||
repository.project_id = project.id
|
repository.project_id = project.id
|
||||||
repository.type = 'Repository::Gitlab'
|
repository.type = 'Repository::Gitlab'
|
||||||
repository.url = gproject.name
|
repository.url = gproject.name
|
||||||
repository.identifier = gproject.name
|
repository.identifier = gproject.name
|
||||||
repository = repository.save
|
repository = repository.save
|
||||||
else
|
# else
|
||||||
flash[:notice] = l(:project_gitlab_create_double_message)
|
# flash[:notice] = l(:project_gitlab_create_double_message)
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
def newrepo
|
def newrepo
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
<textarea id="copy_rep_content" class="cloneUrl mt5 fl" type="input" placeholder="http://xianbo_trustie2@repository.trustie.net/xianbo/trustie2.git"><%=@repository.type.to_s=="Repository::Gitlab" ? @repos_url.to_s.lstrip : @repository.url %></textarea>
|
<textarea id="copy_rep_content" class="cloneUrl mt5 fl" type="input" placeholder="http://xianbo_trustie2@repository.trustie.net/xianbo/trustie2.git"><%=@repository.type.to_s=="Repository::Gitlab" ? @repos_url.to_s.lstrip : @repository.url %></textarea>
|
||||||
<a href="javascript:void(0);" class="clone_btn mt5" onclick="jsCopy()"><span class="vl_copy" title="点击复制版本库地址"></span></a>
|
<a href="javascript:void(0);" class="clone_btn mt5" onclick="jsCopy()"><span class="vl_copy" title="点击复制版本库地址"></span></a>
|
||||||
<div class="fl mt5 ml15"><a href="javascript:void(0);" class="vl_btn fb" onclick="zip()"><span class="vl_zip"></span>ZIP</a> </div>
|
<div class="fl mt5 ml15"><a href="javascript:void(0);" class="vl_btn fb" onclick="zip()"><span class="vl_zip"></span>ZIP</a> </div>
|
||||||
<div class="fr mt5"><a href="javascript:void(0);" class="vl_btn fb" onclick="zip()"><span class="vl_fork"></span>Fork</a> <span href="javascript:void(0);" class="vl_btn_2 fb">0</span> </div>
|
<!--<div class="fr mt5"><a href="javascript:void(0);" class="vl_btn fb" onclick="zip()"><span class="vl_fork"></span>Fork</a> <span href="javascript:void(0);" class="vl_btn_2 fb">0</span> </div>-->
|
||||||
<!--<div class="fr mt5"><a href="javascript:void(0);" class="vl_btn fb" onclick="zip()"><span class="vl_fork"></span><%= link_to "Fork", :controller => 'repositories', :action => 'forked' %></a> <span href="javascript:void(0);" class="vl_btn_2 fb">0</span> </div>-->
|
|
||||||
|
<div class="fr mt5"><span class="vl_fork"></span><%= link_to "Fork", :controller => 'repositories', :action => 'forked'%>
|
||||||
|
<span href="javascript:void(0);" class="vl_btn_2 fb"><%= @project.forked_count.to_i %></span> </div>
|
||||||
<div class="cl"></div>
|
<div class="cl"></div>
|
||||||
<div class="recordBanner mt10">
|
<div class="recordBanner mt10">
|
||||||
<% if @changesets && !@changesets.empty? %>
|
<% if @changesets && !@changesets.empty? %>
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddForkedCountToProjects < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :projects, :forked_count, :integer
|
||||||
|
end
|
||||||
|
end
|
14
db/schema.rb
14
db/schema.rb
|
@ -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 => 20151203072815) do
|
ActiveRecord::Schema.define(:version => 20151204062220) do
|
||||||
|
|
||||||
create_table "activities", :force => true do |t|
|
create_table "activities", :force => true do |t|
|
||||||
t.integer "act_id", :null => false
|
t.integer "act_id", :null => false
|
||||||
|
@ -738,17 +738,6 @@ ActiveRecord::Schema.define(:version => 20151203072815) do
|
||||||
|
|
||||||
add_index "homework_commons", ["course_id", "id"], :name => "index_homework_commons_on_course_id_and_id"
|
add_index "homework_commons", ["course_id", "id"], :name => "index_homework_commons_on_course_id_and_id"
|
||||||
|
|
||||||
create_table "homework_detail_groups", :force => true do |t|
|
|
||||||
t.integer "homework_common_id"
|
|
||||||
t.integer "min_num"
|
|
||||||
t.integer "max_num"
|
|
||||||
t.integer "base_on_project"
|
|
||||||
t.datetime "created_at", :null => false
|
|
||||||
t.datetime "updated_at", :null => false
|
|
||||||
end
|
|
||||||
|
|
||||||
add_index "homework_detail_groups", ["homework_common_id"], :name => "index_homework_detail_groups_on_homework_common_id"
|
|
||||||
|
|
||||||
create_table "homework_detail_manuals", :force => true do |t|
|
create_table "homework_detail_manuals", :force => true do |t|
|
||||||
t.float "ta_proportion"
|
t.float "ta_proportion"
|
||||||
t.integer "comment_status"
|
t.integer "comment_status"
|
||||||
|
@ -1330,6 +1319,7 @@ ActiveRecord::Schema.define(:version => 20151203072815) do
|
||||||
t.integer "project_new_type"
|
t.integer "project_new_type"
|
||||||
t.integer "gpid"
|
t.integer "gpid"
|
||||||
t.integer "forked_from_project_id"
|
t.integer "forked_from_project_id"
|
||||||
|
t.integer "forked_count"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "projects", ["lft"], :name => "index_projects_on_lft"
|
add_index "projects", ["lft"], :name => "index_projects_on_lft"
|
||||||
|
|
|
@ -241,8 +241,9 @@ class Gitlab::Client
|
||||||
|
|
||||||
# Forks a project into the user namespace of the authenticated user.
|
# Forks a project into the user namespace of the authenticated user.
|
||||||
# @param [Integer] - The ID of the project to be forked
|
# @param [Integer] - The ID of the project to be forked
|
||||||
def fork(id)
|
def fork(gpid, gid)
|
||||||
post("/projects/fork/#{id}")
|
post ("/projects/fork/#{gpid}?user_id=#{gid}")
|
||||||
|
# post("/projects/fork/#{id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Mark this project as forked from the other
|
# Mark this project as forked from the other
|
||||||
|
|
Loading…
Reference in New Issue