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
iv
gitlab-ce
Commits
b8295fc3
Commit
b8295fc3
authored
Feb 10, 2016
by
Rubén Dávila
Committed by
Robert Speicher
Feb 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix build and add specs
parent
ccd2a8d6
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
26 deletions
+71
-26
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+8
-1
app/controllers/concerns/creates_commit.rb
app/controllers/concerns/creates_commit.rb
+3
-1
app/controllers/projects/application_controller.rb
app/controllers/projects/application_controller.rb
+0
-8
app/helpers/commits_helper.rb
app/helpers/commits_helper.rb
+4
-7
app/models/repository.rb
app/models/repository.rb
+1
-2
spec/controllers/commit_controller_spec.rb
spec/controllers/commit_controller_spec.rb
+49
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+6
-7
No files found.
app/controllers/application_controller.rb
View file @
b8295fc3
...
@@ -25,7 +25,7 @@ class ApplicationController < ActionController::Base
...
@@ -25,7 +25,7 @@ class ApplicationController < ActionController::Base
helper_method
:abilities
,
:can?
,
:current_application_settings
helper_method
:abilities
,
:can?
,
:current_application_settings
helper_method
:import_sources_enabled?
,
:github_import_enabled?
,
:github_import_configured?
,
:gitlab_import_enabled?
,
:gitlab_import_configured?
,
:bitbucket_import_enabled?
,
:bitbucket_import_configured?
,
:gitorious_import_enabled?
,
:google_code_import_enabled?
,
:fogbugz_import_enabled?
,
:git_import_enabled?
helper_method
:import_sources_enabled?
,
:github_import_enabled?
,
:github_import_configured?
,
:gitlab_import_enabled?
,
:gitlab_import_configured?
,
:bitbucket_import_enabled?
,
:bitbucket_import_configured?
,
:gitorious_import_enabled?
,
:google_code_import_enabled?
,
:fogbugz_import_enabled?
,
:git_import_enabled?
helper_method
:repository
helper_method
:repository
,
:can_collaborate_with_project?
rescue_from
Encoding
::
CompatibilityError
do
|
exception
|
rescue_from
Encoding
::
CompatibilityError
do
|
exception
|
log_exception
(
exception
)
log_exception
(
exception
)
...
@@ -410,6 +410,13 @@ class ApplicationController < ActionController::Base
...
@@ -410,6 +410,13 @@ class ApplicationController < ActionController::Base
current_user
.
nil?
&&
root_path
==
request
.
path
current_user
.
nil?
&&
root_path
==
request
.
path
end
end
def
can_collaborate_with_project?
(
project
=
nil
)
project
||=
@project
can?
(
current_user
,
:push_code
,
project
)
||
(
current_user
&&
current_user
.
already_forked?
(
project
))
end
private
private
def
set_default_sort
def
set_default_sort
...
...
app/controllers/concerns/creates_commit.rb
View file @
b8295fc3
...
@@ -82,7 +82,9 @@ module CreatesCommit
...
@@ -82,7 +82,9 @@ module CreatesCommit
return
@merge_request
if
defined?
(
@merge_request
)
return
@merge_request
if
defined?
(
@merge_request
)
@merge_request
=
@mr_target_project
.
merge_requests
.
opened
.
find_by
(
@merge_request
=
@mr_target_project
.
merge_requests
.
opened
.
find_by
(
source_branch:
@mr_source_branch
,
target_branch:
@mr_target_branch
)
source_branch:
@mr_source_branch
,
target_branch:
@mr_target_branch
)
end
end
def
different_project?
def
different_project?
...
...
app/controllers/projects/application_controller.rb
View file @
b8295fc3
...
@@ -3,7 +3,6 @@ class Projects::ApplicationController < ApplicationController
...
@@ -3,7 +3,6 @@ class Projects::ApplicationController < ApplicationController
before_action
:repository
before_action
:repository
layout
'project'
layout
'project'
helper_method
:can_collaborate_with_project?
def
authenticate_user!
def
authenticate_user!
# Restrict access to Projects area only
# Restrict access to Projects area only
# for non-signed users
# for non-signed users
...
@@ -37,11 +36,4 @@ class Projects::ApplicationController < ApplicationController
...
@@ -37,11 +36,4 @@ class Projects::ApplicationController < ApplicationController
def
builds_enabled
def
builds_enabled
return
render_404
unless
@project
.
builds_enabled?
return
render_404
unless
@project
.
builds_enabled?
end
end
def
can_collaborate_with_project?
(
project
=
nil
)
project
||=
@project
can?
(
current_user
,
:push_code
,
project
)
||
(
current_user
&&
current_user
.
already_forked?
(
project
))
end
end
end
app/helpers/commits_helper.rb
View file @
b8295fc3
...
@@ -128,8 +128,7 @@ module CommitsHelper
...
@@ -128,8 +128,7 @@ module CommitsHelper
if
show_modal_condition
if
show_modal_condition
content_tag
:span
,
'data-toggle'
=>
'modal'
,
'data-target'
=>
'#modal-revert-commit'
do
content_tag
:span
,
'data-toggle'
=>
'modal'
,
'data-target'
=>
'#modal-revert-commit'
do
link_to
'Revert'
,
'#modal-revert-commit'
,
'data-toggle'
=>
'tooltip'
,
link_to
'Revert'
,
'#modal-revert-commit'
,
'data-toggle'
=>
'tooltip'
,
'data-original-title'
=>
'Create merge request to revert commit'
,
class:
"btn btn-close btn-
#{
btn_class
}
"
'data-original-title'
=>
'Create merge request to revert commit'
,
class:
"btn btn-close btn-
#{
btn_class
}
"
end
end
else
else
continue_params
=
{
continue_params
=
{
...
@@ -139,11 +138,9 @@ module CommitsHelper
...
@@ -139,11 +138,9 @@ module CommitsHelper
}
}
fork_path
=
namespace_project_forks_path
(
@project
.
namespace
,
@project
,
fork_path
=
namespace_project_forks_path
(
@project
.
namespace
,
@project
,
namespace_key:
current_user
.
namespace
.
id
,
namespace_key:
current_user
.
namespace
.
id
,
continue:
continue_params
continue:
continue_params
)
)
link_to
'Revert'
,
fork_path
,
class:
'btn btn-grouped btn-close'
,
method: :post
,
link_to
'Revert'
,
fork_path
,
class:
'btn btn-grouped btn-close'
,
method: :post
,
'data-toggle'
=>
'tooltip'
,
'data-original-title'
=>
'Create merge request to revert commit'
'data-toggle'
=>
'tooltip'
,
'data-original-title'
=>
'Create merge request to revert commit'
end
end
end
end
...
...
app/models/repository.rb
View file @
b8295fc3
...
@@ -642,8 +642,7 @@ class Repository
...
@@ -642,8 +642,7 @@ class Repository
committer:
committer
,
committer:
committer
,
tree:
revert_index
.
write_tree
(
rugged
),
tree:
revert_index
.
write_tree
(
rugged
),
parents:
[
rugged
.
lookup
(
source_sha
)],
parents:
[
rugged
.
lookup
(
source_sha
)],
update_ref:
ref
update_ref:
ref
)
)
end
end
end
end
...
...
spec/controllers/commit_controller_spec.rb
View file @
b8295fc3
...
@@ -143,4 +143,53 @@ describe Projects::CommitController do
...
@@ -143,4 +143,53 @@ describe Projects::CommitController do
expect
(
assigns
(
:tags
)).
to
include
(
"v1.1.0"
)
expect
(
assigns
(
:tags
)).
to
include
(
"v1.1.0"
)
end
end
end
end
describe
'#revert'
do
context
'when target branch is not provided'
do
it
'should render the 404 page'
do
post
(
:revert
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
commit
.
id
)
expect
(
response
).
not_to
be_success
expect
(
response
.
status
).
to
eq
(
404
)
end
end
context
'when the revert was successful'
do
it
'should redirect to the commits page'
do
post
(
:revert
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
target_branch:
'master'
,
id:
commit
.
id
)
expect
(
response
).
to
redirect_to
namespace_project_commits_path
(
project
.
namespace
,
project
,
'master'
)
expect
(
flash
[
:notice
]).
to
eq
(
'The commit has been successfully reverted.'
)
end
end
context
'when the revert failed'
do
before
do
post
(
:revert
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
target_branch:
'master'
,
id:
commit
.
id
)
end
it
'should redirect to the commit page'
do
# Reverting a commit that has been already reverted.
post
(
:revert
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
target_branch:
'master'
,
id:
commit
.
id
)
expect
(
response
).
to
redirect_to
namespace_project_commit_path
(
project
.
namespace
,
project
,
commit
.
id
)
expect
(
flash
[
:alert
]).
to
match
(
'Sorry, we cannot revert this commit automatically.'
)
end
end
end
end
end
spec/models/repository_spec.rb
View file @
b8295fc3
...
@@ -9,9 +9,10 @@ describe Repository, models: true do
...
@@ -9,9 +9,10 @@ describe Repository, models: true do
author
=
repository
.
user_to_committer
(
user
)
author
=
repository
.
user_to_committer
(
user
)
{
message:
'Test message'
,
committer:
author
,
author:
author
}
{
message:
'Test message'
,
committer:
author
,
author:
author
}
end
end
let
(
:merge_commit
_id
)
do
let
(
:merge_commit
)
do
source_sha
=
repository
.
find_branch
(
'feature'
).
target
source_sha
=
repository
.
find_branch
(
'feature'
).
target
repository
.
merge
(
user
,
source_sha
,
'master'
,
commit_options
)
merge_commit_id
=
repository
.
merge
(
user
,
source_sha
,
'master'
,
commit_options
)
repository
.
commit
(
merge_commit_id
)
end
end
describe
:branch_names_contains
do
describe
:branch_names_contains
do
...
@@ -437,16 +438,14 @@ describe Repository, models: true do
...
@@ -437,16 +438,14 @@ describe Repository, models: true do
describe
'#merge'
do
describe
'#merge'
do
it
'should merge the code and return the commit id'
do
it
'should merge the code and return the commit id'
do
expect
(
merge_commit
_id
).
to
be_present
expect
(
merge_commit
).
to
be_present
expect
(
repository
.
blob_at
(
merge_commit
_
id
,
'files/ruby/feature.rb'
)).
to
be_present
expect
(
repository
.
blob_at
(
merge_commit
.
id
,
'files/ruby/feature.rb'
)).
to
be_present
end
end
end
end
describe
'#revert_merge'
do
describe
'#revert_merge'
do
it
'should revert the changes'
do
it
'should revert the changes'
do
repository
.
revert_merge
(
user
,
merge_commit_id
,
'revert-changes'
,
'Revert changes'
)
repository
.
revert
(
user
,
merge_commit
,
'master'
)
source_sha
=
repository
.
find_branch
(
'revert-changes'
).
target
repository
.
merge
(
user
,
source_sha
,
'master'
,
commit_options
)
expect
(
repository
.
blob_at_branch
(
'master'
,
'files/ruby/feature.rb'
)).
not_to
be_present
expect
(
repository
.
blob_at_branch
(
'master'
,
'files/ruby/feature.rb'
)).
not_to
be_present
end
end
...
...
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