Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
b72cbd8d
Commit
b72cbd8d
authored
Nov 13, 2015
by
Stan Hu
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9757 from yms9654/diff-option
Add ignore white space option in merge request diff
parents
8146509c
3d0efa8e
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
80 additions
and
8 deletions
+80
-8
CHANGELOG
CHANGELOG
+1
-0
app/controllers/projects/compare_controller.rb
app/controllers/projects/compare_controller.rb
+2
-1
app/models/merge_request.rb
app/models/merge_request.rb
+1
-1
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+15
-1
app/services/compare_service.rb
app/services/compare_service.rb
+2
-2
app/views/projects/merge_requests/show/_diffs.html.haml
app/views/projects/merge_requests/show/_diffs.html.haml
+1
-1
doc/workflow/merge_requests.md
doc/workflow/merge_requests.md
+12
-0
doc/workflow/merge_requests/commit_compare.png
doc/workflow/merge_requests/commit_compare.png
+0
-0
doc/workflow/merge_requests/merge_request_diff.png
doc/workflow/merge_requests/merge_request_diff.png
+0
-0
doc/workflow/merge_requests/merge_request_diff_without_whitespace.png
.../merge_requests/merge_request_diff_without_whitespace.png
+0
-0
lib/gitlab/compare_result.rb
lib/gitlab/compare_result.rb
+2
-2
spec/controllers/projects/compare_controller_spec.rb
spec/controllers/projects/compare_controller_spec.rb
+16
-0
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+28
-0
No files found.
CHANGELOG
View file @
b72cbd8d
...
...
@@ -37,6 +37,7 @@ v 8.2.0 (unreleased)
- MR target branch is now visible on a list view when it is different from project's default one
- Improve Continuous Integration graphs page
- Make color of "Accept Merge Request" button consistent with current build status
- Add ignore white space option in merge request diff and commit and compare view
v 8.1.4
- Fix bug where manually merged branches in a MR would end up with an empty diff (Stan Hu)
...
...
app/controllers/projects/compare_controller.rb
View file @
b72cbd8d
...
...
@@ -12,9 +12,10 @@ class Projects::CompareController < Projects::ApplicationController
def
show
base_ref
=
Addressable
::
URI
.
unescape
(
params
[
:from
])
@ref
=
head_ref
=
Addressable
::
URI
.
unescape
(
params
[
:to
])
diff_options
=
{
ignore_whitespace_change:
true
}
if
params
[
:w
]
==
'1'
compare_result
=
CompareService
.
new
.
execute
(
@project
,
head_ref
,
@project
,
base_ref
)
execute
(
@project
,
head_ref
,
@project
,
base_ref
,
diff_options
)
if
compare_result
@commits
=
Commit
.
decorate
(
compare_result
.
commits
,
@project
)
...
...
app/models/merge_request.rb
View file @
b72cbd8d
...
...
@@ -40,7 +40,7 @@ class MergeRequest < ActiveRecord::Base
after_create
:create_merge_request_diff
after_update
:update_merge_request_diff
delegate
:commits
,
:diffs
,
to: :merge_request_diff
,
prefix:
nil
delegate
:commits
,
:diffs
,
:diffs_no_whitespace
,
to: :merge_request_diff
,
prefix:
nil
# When this attribute is true some MR validation is ignored
# It allows us to close or modify broken merge requests
...
...
app/models/merge_request_diff.rb
View file @
b72cbd8d
...
...
@@ -19,7 +19,7 @@ class MergeRequestDiff < ActiveRecord::Base
# Prevent store of diff if commits amount more then 500
COMMITS_SAFE_SIZE
=
500
attr_reader
:commits
,
:diffs
attr_reader
:commits
,
:diffs
,
:diffs_no_whitespace
belongs_to
:merge_request
...
...
@@ -47,6 +47,20 @@ class MergeRequestDiff < ActiveRecord::Base
@diffs
||=
(
load_diffs
(
st_diffs
)
||
[])
end
def
diffs_no_whitespace
# Get latest sha of branch from source project
source_sha
=
merge_request
.
source_project
.
commit
(
source_branch
).
sha
compare_result
=
Gitlab
::
CompareResult
.
new
(
Gitlab
::
Git
::
Compare
.
new
(
merge_request
.
target_project
.
repository
.
raw_repository
,
merge_request
.
target_branch
,
source_sha
,
),
{
ignore_whitespace_change:
true
}
)
@diffs_no_whitespace
||=
load_diffs
(
dump_commits
(
compare_result
.
diffs
))
end
def
commits
@commits
||=
load_commits
(
st_commits
||
[])
end
...
...
app/services/compare_service.rb
View file @
b72cbd8d
...
...
@@ -3,7 +3,7 @@ require 'securerandom'
# Compare 2 branches for one repo or between repositories
# and return Gitlab::CompareResult object that responds to commits and diffs
class
CompareService
def
execute
(
source_project
,
source_branch
,
target_project
,
target_branch
)
def
execute
(
source_project
,
source_branch
,
target_project
,
target_branch
,
diff_options
=
{}
)
source_commit
=
source_project
.
commit
(
source_branch
)
return
unless
source_commit
...
...
@@ -25,7 +25,7 @@ class CompareService
target_project
.
repository
.
raw_repository
,
target_branch
,
source_sha
,
)
)
,
diff_options
)
end
end
app/views/projects/merge_requests/show/_diffs.html.haml
View file @
b72cbd8d
-
if
@merge_request_diff
.
collected?
=
render
"projects/diffs/diffs"
,
diffs:
@merge_request
.
diffs
,
project:
@merge_request
.
project
=
render
"projects/diffs/diffs"
,
diffs:
params
[
:w
]
==
'1'
?
@merge_request
.
diffs_no_whitespace
:
@merge_request
.
diffs
,
project:
@merge_request
.
project
-
elsif
@merge_request_diff
.
empty?
.nothing-here-block
Nothing to merge from
#{
@merge_request
.
source_branch
}
into
#{
@merge_request
.
target_branch
}
-
else
...
...
doc/workflow/merge_requests.md
View file @
b72cbd8d
...
...
@@ -38,3 +38,15 @@ To check out a particular merge request:
```
$ git checkout origin/merge-requests/1
```
## Ignore whitespace changes in Merge Request diff view
![
MR diff
](
merge_requests/merge_request_diff.png
)
It you add
`w=1`
option to URL, you can see diff without whitespace changes.
![
MR diff without whitespace
](
merge_requests/merge_request_diff_without_whitespace.png
)
It is also working on commits compare view.
![
Commit Compare
](
merge_requests/commit_compare.png
)
doc/workflow/merge_requests/commit_compare.png
0 → 100644
View file @
b72cbd8d
87.5 KB
doc/workflow/merge_requests/merge_request_diff.png
0 → 100644
View file @
b72cbd8d
118 KB
doc/workflow/merge_requests/merge_request_diff_without_whitespace.png
0 → 100644
View file @
b72cbd8d
96.6 KB
lib/gitlab/compare_result.rb
View file @
b72cbd8d
...
...
@@ -2,8 +2,8 @@ module Gitlab
class
CompareResult
attr_reader
:commits
,
:diffs
def
initialize
(
compare
)
@commits
,
@diffs
=
compare
.
commits
,
compare
.
diffs
def
initialize
(
compare
,
diff_options
=
{}
)
@commits
,
@diffs
=
compare
.
commits
,
compare
.
diffs
(
nil
,
diff_options
)
end
end
end
spec/controllers/projects/compare_controller_spec.rb
View file @
b72cbd8d
...
...
@@ -23,6 +23,22 @@ describe Projects::CompareController do
expect
(
assigns
(
:commits
).
length
).
to
be
>=
1
end
it
'compare should show some diffs with ignore whitespace change option'
do
get
(
:show
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
from:
'08f22f25'
,
to:
'66eceea0'
,
w:
1
)
expect
(
response
).
to
be_success
expect
(
assigns
(
:diffs
).
length
).
to
be
>=
1
expect
(
assigns
(
:commits
).
length
).
to
be
>=
1
# without whitespace option, there are more than 2 diff_splits
diff_splits
=
assigns
(
:diffs
)[
0
].
diff
.
split
(
"
\n
"
)
expect
(
diff_splits
.
length
).
to
be
<=
2
end
describe
'non-existent refs'
do
it
'invalid source ref'
do
get
(
:show
,
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
b72cbd8d
...
...
@@ -147,6 +147,34 @@ describe Projects::MergeRequestsController do
end
end
describe
'GET diffs with ignore_whitespace_change'
do
def
go
(
format:
'html'
)
get
:diffs
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
merge_request
.
iid
,
format:
format
,
w:
1
end
context
'as html'
do
it
'renders the diff template'
do
go
expect
(
response
).
to
render_template
(
'diffs'
)
end
end
context
'as json'
do
it
'renders the diffs template to a string'
do
go
format:
'json'
expect
(
response
).
to
render_template
(
'projects/merge_requests/show/_diffs'
)
expect
(
JSON
.
parse
(
response
.
body
)).
to
have_key
(
'html'
)
end
end
end
describe
'GET commits'
do
def
go
(
format:
'html'
)
get
:commits
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment