Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Nowak <maciejt.nowak@gmail.com>2018-06-23 22:39:11 +0300
committerMaciej Nowak <maciejt.nowak@gmail.com>2018-06-28 10:19:50 +0300
commit591edb439c2608f7448d7c3d5d2fc35e0ad5e8c1 (patch)
tree9219fc5db67b8d8aa8a40de5f01e27318728dc2a
parent2bac2918b2d6f12d94f739f4b6865b9e9221c642 (diff)
Allow straight diff in Compare API
Repository compare API now allows choosing straight (from..to) or merge-base diff (from...to)
-rw-r--r--changelogs/unreleased/straight-comparision-mode.yml5
-rw-r--r--doc/api/repositories.md1
-rw-r--r--lib/api/repositories.rb3
-rw-r--r--spec/requests/api/repositories_spec.rb25
4 files changed, 33 insertions, 1 deletions
diff --git a/changelogs/unreleased/straight-comparision-mode.yml b/changelogs/unreleased/straight-comparision-mode.yml
new file mode 100644
index 00000000000..2f6a0c0b54d
--- /dev/null
+++ b/changelogs/unreleased/straight-comparision-mode.yml
@@ -0,0 +1,5 @@
+---
+title: Allow straight diff in Compare API
+merge_request: 20120
+author: Maciej Nowak
+type: added
diff --git a/doc/api/repositories.md b/doc/api/repositories.md
index 5aff255c20a..cb816bbd712 100644
--- a/doc/api/repositories.md
+++ b/doc/api/repositories.md
@@ -130,6 +130,7 @@ Parameters:
- `id` (required) - The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user
- `from` (required) - the commit SHA or branch name
- `to` (required) - the commit SHA or branch name
+- `straight` (optional) - comparison method, `true` for direct comparison between `from` and `to` (`from`..`to`), `false` to compare using merge base (`from`...`to`)'. Default is `false`.
```
GET /projects/:id/repository/compare?from=master&to=feature
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index bb3fa99af38..33a9646ac3b 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -100,9 +100,10 @@ module API
params do
requires :from, type: String, desc: 'The commit, branch name, or tag name to start comparison'
requires :to, type: String, desc: 'The commit, branch name, or tag name to stop comparison'
+ optional :straight, type: Boolean, desc: 'Comparison method, `true` for direct comparison between `from` and `to` (`from`..`to`), `false` to compare using merge base (`from`...`to`)', default: false
end
get ':id/repository/compare' do
- compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to])
+ compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to], straight: params[:straight])
present compare, with: Entities::Compare
end
diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb
index cd135dfc32a..28f8564ae92 100644
--- a/spec/requests/api/repositories_spec.rb
+++ b/spec/requests/api/repositories_spec.rb
@@ -288,6 +288,9 @@ describe API::Repositories do
shared_examples_for 'repository compare' do
it "compares branches" do
+ expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, {
+ straight: false
+ }).and_call_original
get api(route, current_user), from: 'master', to: 'feature'
expect(response).to have_gitlab_http_status(200)
@@ -295,6 +298,28 @@ describe API::Repositories do
expect(json_response['diffs']).to be_present
end
+ it "compares branches with explicit merge-base mode" do
+ expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, {
+ straight: false
+ }).and_call_original
+ get api(route, current_user), from: 'master', to: 'feature', straight: false
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(json_response['commits']).to be_present
+ expect(json_response['diffs']).to be_present
+ end
+
+ it "compares branches with explicit straight mode" do
+ expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, {
+ straight: true
+ }).and_call_original
+ get api(route, current_user), from: 'master', to: 'feature', straight: true
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(json_response['commits']).to be_present
+ expect(json_response['diffs']).to be_present
+ end
+
it "compares tags" do
get api(route, current_user), from: 'v1.0.0', to: 'v1.1.0'