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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
271b9658
Commit
271b9658
authored
Dec 15, 2018
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
326f9025
8d2e1b72
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
150 additions
and
3 deletions
+150
-3
app/assets/javascripts/diffs/components/diff_content.vue
app/assets/javascripts/diffs/components/diff_content.vue
+5
-2
app/assets/javascripts/vue_shared/components/diff_viewer/viewers/empty_file.vue
.../vue_shared/components/diff_viewer/viewers/empty_file.vue
+3
-0
app/serializers/diff_file_entity.rb
app/serializers/diff_file_entity.rb
+1
-0
changelogs/unreleased/54786-mr-empty-file-display.yml
changelogs/unreleased/54786-mr-empty-file-display.yml
+5
-0
lib/gitlab/diff/file.rb
lib/gitlab/diff/file.rb
+4
-0
locale/gitlab.pot
locale/gitlab.pot
+3
-0
spec/javascripts/diffs/components/diff_content_spec.js
spec/javascripts/diffs/components/diff_content_spec.js
+39
-0
spec/lib/gitlab/diff/file_spec.rb
spec/lib/gitlab/diff/file_spec.rb
+89
-0
spec/support/shared_examples/serializers/diff_file_entity_examples.rb
.../shared_examples/serializers/diff_file_entity_examples.rb
+1
-1
No files found.
app/assets/javascripts/diffs/components/diff_content.vue
View file @
271b9658
<
script
>
import
{
mapActions
,
mapGetters
,
mapState
}
from
'
vuex
'
;
import
DiffViewer
from
'
~/vue_shared/components/diff_viewer/diff_viewer.vue
'
;
import
EmptyFileViewer
from
'
~/vue_shared/components/diff_viewer/viewers/empty_file.vue
'
;
import
InlineDiffView
from
'
./inline_diff_view.vue
'
;
import
ParallelDiffView
from
'
./parallel_diff_view.vue
'
;
import
NoteForm
from
'
../../notes/components/note_form.vue
'
;
...
...
@@ -17,6 +18,7 @@ export default {
NoteForm
,
DiffDiscussions
,
ImageDiffOverlay
,
EmptyFileViewer
,
},
props
:
{
diffFile
:
{
...
...
@@ -75,14 +77,15 @@ export default {
<div
class=
"diff-content"
>
<div
class=
"diff-viewer"
>
<template
v-if=
"isTextFile"
>
<empty-file-viewer
v-if=
"diffFile.empty"
/>
<inline-diff-view
v-if=
"isInlineView"
v-
else-
if=
"isInlineView"
:diff-file=
"diffFile"
:diff-lines=
"diffFile.highlighted_diff_lines || []"
:help-page-path=
"helpPagePath"
/>
<parallel-diff-view
v-if=
"isParallelView"
v-
else-
if=
"isParallelView"
:diff-file=
"diffFile"
:diff-lines=
"diffFile.parallel_diff_lines || []"
:help-page-path=
"helpPagePath"
...
...
app/assets/javascripts/vue_shared/components/diff_viewer/viewers/empty_file.vue
0 → 100644
View file @
271b9658
<
template
>
<div
class=
"nothing-here-block"
>
{{
__
(
'
Empty file
'
)
}}
</div>
</
template
>
app/serializers/diff_file_entity.rb
View file @
271b9658
...
...
@@ -5,6 +5,7 @@ class DiffFileEntity < DiffFileBaseEntity
include
IconsHelper
expose
:too_large?
,
as: :too_large
expose
:empty?
,
as: :empty
expose
:added_lines
expose
:removed_lines
...
...
changelogs/unreleased/54786-mr-empty-file-display.yml
0 → 100644
View file @
271b9658
---
title
:
Display empty files properly on MR diffs
merge_request
:
23671
author
:
Sean Nichols
type
:
fixed
lib/gitlab/diff/file.rb
View file @
271b9658
...
...
@@ -255,6 +255,10 @@ module Gitlab
end
# rubocop: enable CodeReuse/ActiveRecord
def
empty?
valid_blobs
.
map
(
&
:empty?
).
all?
end
def
raw_binary?
try_blobs
(
:raw_binary?
)
end
...
...
locale/gitlab.pot
View file @
271b9658
...
...
@@ -3150,6 +3150,9 @@ msgstr ""
msgid "Embed"
msgstr ""
msgid "Empty file"
msgstr ""
msgid "Enable"
msgstr ""
...
...
spec/javascripts/diffs/components/diff_content_spec.js
View file @
271b9658
...
...
@@ -50,6 +50,45 @@ describe('DiffContent', () => {
});
});
describe
(
'
empty files
'
,
()
=>
{
beforeEach
(()
=>
{
vm
.
diffFile
.
empty
=
true
;
vm
.
diffFile
.
highlighted_diff_lines
=
[];
vm
.
diffFile
.
parallel_diff_lines
=
[];
});
it
(
'
should render a message
'
,
done
=>
{
vm
.
$nextTick
(()
=>
{
const
block
=
vm
.
$el
.
querySelector
(
'
.diff-viewer .nothing-here-block
'
);
expect
(
block
).
not
.
toBe
(
null
);
expect
(
block
.
textContent
.
trim
()).
toContain
(
'
Empty file
'
);
done
();
});
});
it
(
'
should not render multiple messages
'
,
done
=>
{
vm
.
diffFile
.
mode_changed
=
true
;
vm
.
diffFile
.
b_mode
=
'
100755
'
;
vm
.
diffFile
.
viewer
.
name
=
'
mode_changed
'
;
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelectorAll
(
'
.nothing-here-block
'
).
length
).
toBe
(
1
);
done
();
});
});
it
(
'
should not render diff table
'
,
done
=>
{
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
table
'
)).
toBe
(
null
);
done
();
});
});
});
describe
(
'
Non-Text diffs
'
,
()
=>
{
beforeEach
(()
=>
{
vm
.
diffFile
.
viewer
.
name
=
'
image
'
;
...
...
spec/lib/gitlab/diff/file_spec.rb
View file @
271b9658
...
...
@@ -583,6 +583,12 @@ describe Gitlab::Diff::File do
end
end
describe
'#empty?'
do
it
'returns true'
do
expect
(
diff_file
.
empty?
).
to
be_truthy
end
end
describe
'#different_type?'
do
it
'returns false'
do
expect
(
diff_file
).
not_to
be_different_type
...
...
@@ -662,4 +668,87 @@ describe Gitlab::Diff::File do
end
end
end
describe
'#empty?'
do
let
(
:project
)
do
create
(
:project
,
:custom_repo
,
files:
{})
end
let
(
:branch_name
)
{
'master'
}
def
create_file
(
file_name
,
content
)
Files
::
CreateService
.
new
(
project
,
project
.
owner
,
commit_message:
'Update'
,
start_branch:
branch_name
,
branch_name:
branch_name
,
file_path:
file_name
,
file_content:
content
).
execute
project
.
commit
(
branch_name
).
diffs
.
diff_files
.
first
end
def
update_file
(
file_name
,
content
)
Files
::
UpdateService
.
new
(
project
,
project
.
owner
,
commit_message:
'Update'
,
start_branch:
branch_name
,
branch_name:
branch_name
,
file_path:
file_name
,
file_content:
content
).
execute
project
.
commit
(
branch_name
).
diffs
.
diff_files
.
first
end
def
delete_file
(
file_name
)
Files
::
DeleteService
.
new
(
project
,
project
.
owner
,
commit_message:
'Update'
,
start_branch:
branch_name
,
branch_name:
branch_name
,
file_path:
file_name
).
execute
project
.
commit
(
branch_name
).
diffs
.
diff_files
.
first
end
context
'when empty file is created'
do
it
'returns true'
do
diff_file
=
create_file
(
'empty.md'
,
''
)
expect
(
diff_file
.
empty?
).
to
be_truthy
end
end
context
'when empty file is deleted'
do
it
'returns true'
do
create_file
(
'empty.md'
,
''
)
diff_file
=
delete_file
(
'empty.md'
)
expect
(
diff_file
.
empty?
).
to
be_truthy
end
end
context
'when file with content is truncated'
do
it
'returns false'
do
create_file
(
'with-content.md'
,
'file content'
)
diff_file
=
update_file
(
'with-content.md'
,
''
)
expect
(
diff_file
.
empty?
).
to
be_falsey
end
end
context
'when empty file has content added'
do
it
'returns false'
do
create_file
(
'empty.md'
,
''
)
diff_file
=
update_file
(
'empty.md'
,
'new content'
)
expect
(
diff_file
.
empty?
).
to
be_falsey
end
end
end
end
spec/support/shared_examples/serializers/diff_file_entity_examples.rb
View file @
271b9658
...
...
@@ -32,7 +32,7 @@ shared_examples 'diff file entity' do
it
'exposes correct attributes'
do
expect
(
subject
).
to
include
(
:too_large
,
:added_lines
,
:removed_lines
,
:context_lines_path
,
:highlighted_diff_lines
,
:parallel_diff_lines
)
:parallel_diff_lines
,
:empty
)
end
it
'includes viewer'
do
...
...
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