diff options
author | Rémy Coutable <remy@rymai.me> | 2016-04-04 13:14:58 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-04-04 13:14:58 +0000 |
commit | 41c478cb8f680c57015ab8c2ae7bc0f371a03899 (patch) | |
tree | aaf10872287b1ac43aef3bd9939c552d8587495a | |
parent | 438e0ce848749944a3b006c0e3cf8249ed847df1 (diff) | |
parent | 787713895851a7260e2c46e2863b1bbb68b3a649 (diff) | |
download | gitlab-ce-41c478cb8f680c57015ab8c2ae7bc0f371a03899.tar.gz |
Merge branch 'fix-mr-for-orphaned-branches' into 'master'
Fix creation of merge requests for orphaned branches with images
When attempting to create a merge request from an orphaned branch (e.g. this happens for the first commit of any repo) that contained images, GitLab would fail with a Error 500. This MR fixes that problem.
Closes #14875
See merge request !3511
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/views/projects/diffs/_image.html.haml | 7 | ||||
-rw-r--r-- | spec/features/merge_requests/create_new_mr_spec.rb | 28 | ||||
-rw-r--r-- | spec/support/test_env.rb | 1 |
4 files changed, 35 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG index f8f21ed0dc9..26e81f3c303 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -16,6 +16,7 @@ v 8.7.0 (unreleased) - Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.) - Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.) - Gracefully handle notes on deleted commits in merge requests (Stan Hu) + - Fix creation of merge requests for orphaned branches (Stan Hu) - Fall back to `In-Reply-To` and `References` headers when sub-addressing is not available (David Padilla) - Remove "Congratulations!" tweet button on newly-created project. (Connor Shea) diff --git a/app/views/projects/diffs/_image.html.haml b/app/views/projects/diffs/_image.html.haml index 8367112a9cb..2731219ccad 100644 --- a/app/views/projects/diffs/_image.html.haml +++ b/app/views/projects/diffs/_image.html.haml @@ -1,7 +1,10 @@ - diff = diff_file.diff - file_raw_path = namespace_project_raw_path(@project.namespace, @project, tree_join(@commit.id, diff.new_path)) -- old_commit_id = diff_refs.first.id -- old_file_raw_path = namespace_project_raw_path(@project.namespace, @project, tree_join(old_commit_id, diff.old_path)) +// diff_refs will be nil for orphaned commits (e.g. first commit in repo) +- if diff_refs + - old_commit_id = diff_refs.first.id + - old_file_raw_path = namespace_project_raw_path(@project.namespace, @project, tree_join(old_commit_id, diff.old_path)) + - if diff.renamed_file || diff.new_file || diff.deleted_file .image %span.wrap diff --git a/spec/features/merge_requests/create_new_mr_spec.rb b/spec/features/merge_requests/create_new_mr_spec.rb new file mode 100644 index 00000000000..fd02d584848 --- /dev/null +++ b/spec/features/merge_requests/create_new_mr_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +feature 'Create New Merge Request', feature: true, js: false do + let(:user) { create(:user) } + let(:project) { create(:project, :public) } + + before do + project.team << [user, :master] + + login_as user + visit namespace_project_merge_requests_path(project.namespace, project) + end + + it 'generates a diff for an orphaned branch' do + click_link 'New Merge Request' + select "orphaned-branch", from: "merge_request_source_branch" + select "master", from: "merge_request_target_branch" + click_button "Compare branches" + + expect(page).to have_content "README.md" + expect(page).to have_content "wm.png" + + fill_in "merge_request_title", with: "Orphaned MR test" + click_button "Submit merge request" + + expect(page).to have_content 'git checkout -b orphaned-branch origin/orphaned-branch' + end +end diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 0d1bd030f3c..71664bb192e 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -15,6 +15,7 @@ module TestEnv 'lfs' => 'be93687', 'master' => '5937ac0', "'test'" => 'e56497b', + 'orphaned-branch' => '45127a9', } # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily |