diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 932cdeacd..7409a0b99 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -85,15 +85,10 @@ class PullRequestsController < ApplicationController description = params[:description] source_branch = params[:source_branch] target_branch = params[:target_branch] + target_project_id = params[:target_project_id] begin - # 如果分支没有改动 - if compare_pull_request(source_branch, target_project, target_branch).blank? - @no_updates = 1 - respond_to do |format| - format.html{new_project_pull_request_path()} - end - else - @no_updates = 0 + # 如果分支有改动 + if compare_pull_request(source_branch, target_project_id, target_branch) # 如果传送了目标项目ID即向fork源项目发送请求 if params[:forked_project_id] && params[:source_project] == "forked_project_name" target_project_id = params[:forked_project_id].to_i @@ -106,6 +101,11 @@ class PullRequestsController < ApplicationController format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)} end end + else + @tip = 1 + respond_to do |format| + format.js{redirect_to new_project_pull_request_path} + end end rescue Exception => e @message = e.message @@ -114,20 +114,31 @@ class PullRequestsController < ApplicationController # Compare branch for MR # 判断源分支和目标分支是否有改动 + # status 为true 表示有改动; false:便是没有改动 def compare_pull_request source_branch, target_project, target_branch - user_source_name = @project.owner.try(:login) + user_name_source = @project.owner.try(:login) identifier = @repository.identifier.downcase - git_source_tree = '--git-dir=/home/git/repositories/' + user_name + '/' + identifier + '.git' + git_source_tree = '--git-dir=/home/git/repositories/' + user_name_source + '/' + identifier + '.git' if target_project - git_target_tree = '--git-dir=/home/git/repositories/' + user_name + '/' + identifier + '.git' - else + user_name_target = Project.find(target_project).owner.try(:login) + git_target_tree = '--git-dir=/home/git/repositories/' + user_name_target + '/' + identifier + '.git' + # git_target_tree = '--git-dir=/home/git/repositories/' + user_name_target + '/' + identifier + '.git' + # remote git_target_tree = '--git-dir=/home/git/repositories/' + user_name_target + '/' + identifier + '.git' + ########### + git_sourse_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, source_branch) + git_target_commit_id = @g.get_branch_commit_id(user_name_source.gpid, git_target_tree, target_branch) + ############## + # git_sourse_commit_id = `git #{git_source_tree} log #{source_branch} --pretty=oneline -1` + # git_target_commit_id = `git #{git_target_tree} log #{target_branch} --pretty=oneline -1` + # git_target_commit_id = `--git rev-parse #{target_branch}` + # 员项目的源分支和目标项目的目标分支的commit_id如果相同则没有改动 + status = git_sourse_commit_id == git_target_commit_id ? false : true + else + reuslt = `git #{git_source_tree} log --pretty=oneline #{source_branch} ^#{target_branch}` + status = result.blank? ? false : true end - # def compare_pull_request - user_name = @project.owner.try(:login) - identifier = @repository.identifier.downcase - git_tree = '--git-dir=/home/git/repositories/' + user_name + '/' + identifier + '.git' - status = `git #{git_tree} log --pretty=oneline #{source_branch} ^#{target_branch}` + status end # @project_menu_type 为了控制base顶部导航 diff --git a/app/views/pull_requests/_form.html.erb b/app/views/pull_requests/_form.html.erb index a79f8c374..3d7c3661f 100644 --- a/app/views/pull_requests/_form.html.erb +++ b/app/views/pull_requests/_form.html.erb @@ -12,7 +12,7 @@ <% if @forked_project.nil? %> <%= select_tag :branch, options_for_select(@source_rev), :id => "pull_request_branch", :name => "target_branch", :value => "target_branch",:class => "fl PullReques_minselect ml5" %> <% else %> - @@ -21,11 +21,13 @@ <% end %> - <%= hidden_field_tag 'target_project_id', '' %> <% end %> +
+ <%= render :partial => "tip" %> +
@@ -69,7 +71,7 @@ { var source_branch = $.trim($("#source_branch").val()); var target_branch = $.trim($("#pull_request_branch").val()); - var target_project = $.trim($("#pull_request_project").children().attr("name")); + var target_project = $.trim($("#target_project_id").children().attr("name")); var target_forked_project = $.trim($("#pull_request_project_hidden").text()); if(target_project == target_forked_project && source_branch == target_branch) { diff --git a/app/views/pull_requests/_tip.html.erb b/app/views/pull_requests/_tip.html.erb new file mode 100644 index 000000000..f511f1588 --- /dev/null +++ b/app/views/pull_requests/_tip.html.erb @@ -0,0 +1,5 @@ +<% if @tip %> +
+ 您选择的源分支和目标分支为似乎没有差异,请将新改动提交至源分支或者切换到其它目标分支 +
+<% end %> diff --git a/app/views/pull_requests/new.js.erb b/app/views/pull_requests/new.js.erb new file mode 100644 index 000000000..2c943e6c2 --- /dev/null +++ b/app/views/pull_requests/new.js.erb @@ -0,0 +1 @@ +$("#pull_request_branch_tip").html('<%= escape_javascript(render :partial => "pull_requests/tip") %>'); diff --git a/lib/gitlab-cli/lib/gitlab/client/repositories.rb b/lib/gitlab-cli/lib/gitlab/client/repositories.rb index 3630f40dd..e016ab6a8 100644 --- a/lib/gitlab-cli/lib/gitlab/client/repositories.rb +++ b/lib/gitlab-cli/lib/gitlab/client/repositories.rb @@ -86,6 +86,11 @@ class Gitlab::Client get("/projects/#{project}/repository/user_static", :query => options) end + def get_branch_commit_id(project, git_tree, ref_name) + post("/projects/#{project}/repository/get_branch_commit_id?git_tree=#{git_tree}&ref_name=#{ref_name}") + end + + # Gets a specific commit identified by the commit hash or name of a branch or tag. # # @example