Skip to content
Snippets Groups Projects
Commit 5daf44b7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Merge branch 'revert-satellites' into 'master'

Revert satellites

Return satellites to master for 7.14

We remove satellites in next release (8.0)

See merge request !1136
parents 2f706fbd 3a63c005
No related branches found
No related tags found
No related merge requests found
Showing
with 300 additions and 380 deletions
Loading
Loading
@@ -45,10 +45,7 @@ v 7.14.0 (unreleased)
- Remove redis-store TTL monkey patch
- Add support for CI skipped status
- Fetch code from forks to refs/merge-requests/:id/head when merge request created
- Remove satellites
- Remove comments and email addresses when publicly exposing ssh keys (Zeger-Jan van de Weg)
- Improve MR merge widget text and UI consistency.
- Improve text in MR "How To Merge" modal.
- Cache all events
- Order commits by date when comparing branches
- Fix bug causing error when the target branch of a symbolic ref was deleted
Loading
Loading
@@ -199,7 +196,6 @@ v 7.12.0
- Add SAML support as an omniauth provider
- Allow to configure a URL to show after sign out
- Add an option to automatically sign-in with an Omniauth provider
- Better performance for web editor (switched from satellites to rugged)
- GitLab CI service sends .gitlab-ci.yml in each push call
- When remove project - move repository and schedule it removal
- Improve group removing logic
Loading
Loading
Loading
Loading
@@ -875,4 +875,4 @@ DEPENDENCIES
wikicloth (= 0.8.1)
 
BUNDLED WITH
1.10.4
1.10.5
Loading
Loading
@@ -19,7 +19,7 @@ class @MergeRequestWidget
when 'merged'
location.reload()
else
setTimeout(merge_request_widget.mergeInProgress, 2000)
setTimeout(merge_request_widget.mergeInProgress, 3000)
dataType: 'json'
 
getMergeStatus: ->
Loading
Loading
@@ -49,8 +49,10 @@ class @MergeRequestWidget
@setMergeButtonClass('btn-danger')
 
showCiCoverage: (coverage) ->
text = 'Coverage ' + coverage + '%'
$('.ci_widget:visible .ci-coverage').text(text)
cov_html = $('<span>')
cov_html.addClass('ci-coverage')
cov_html.text('Coverage ' + coverage + '%')
$('.ci_widget:visible').append(cov_html)
 
setMergeButtonClass: (css_class) ->
$('.accept_merge_request').removeClass("btn-create").addClass(css_class)
/**
* MR -> show: Automerge widget
/**
* MR -> show: Automerge widget
*
*/
.mr-state-widget {
background: #FAFAFA;
margin-bottom: 20px;
color: #666;
border: 1px solid #e5e5e5;
@include box-shadow(0 1px 1px rgba(0, 0, 0, 0.05));
@include border-radius(3px);
form {
margin-bottom: 0;
.clearfix {
Loading
Loading
@@ -26,67 +20,16 @@
display: inline-block;
margin: 0;
margin-left: 20px;
padding: 5px;
padding: 10px 0;
line-height: 20px;
font-weight: bold;
 
.remove_source_checkbox {
margin: 0;
font-weight: bold;
}
}
}
.ci_widget {
border-bottom: 1px solid #EEE;
i {
margin-right: 4px;
}
&.ci-success {
color: $gl-success;
}
&.ci-skipped {
background-color: #eee;
color: #888;
}
&.ci-pending,
&.ci-running {
color: $gl-warning;
}
&.ci-failed,
&.ci-canceled,
&.ci-error {
color: $gl-danger;
}
}
.mr-widget-body,
.ci_widget,
.mr-widget-footer {
padding: 15px;
}
.mr-widget-body {
h4 {
font-weight: bold;
margin: 5px 0;
}
p:last-child {
margin-bottom: 0;
}
}
.mr-widget-footer {
border-top: 1px solid #EEE;
}
.ci-coverage {
float: right;
}
}
 
@media(min-width: $screen-sm-max) {
Loading
Loading
@@ -118,10 +61,23 @@
}
 
.label-branch {
color: #222;
@include border-radius(4px);
padding: 3px 4px;
border: none;
background: $hover;
color: #333;
font-family: $monospace_font;
font-weight: bold;
font-weight: normal;
overflow: hidden;
.label-project {
@include border-radius-left(4px);
padding: 3px 4px;
background: #279;
position: relative;
left: -4px;
letter-spacing: -1px;
}
}
 
.mr-list {
Loading
Loading
@@ -168,6 +124,64 @@
display: none;
}
 
.mr-state-widget {
font-size: 13px;
background: #FAFAFA;
margin-bottom: 20px;
color: #666;
border: 1px solid #e5e5e5;
@include box-shadow(0 1px 1px rgba(0, 0, 0, 0.05));
@include border-radius(3px);
.ci_widget {
padding: 10px 15px;
font-size: 15px;
border-bottom: 1px solid #EEE;
&.ci-success {
color: $gl-success;
}
&.ci-skipped {
background-color: #eee;
color: #888;
}
&.ci-pending,
&.ci-running {
color: $gl-warning;
}
&.ci-failed,
&.ci-canceled,
&.ci-error {
color: $gl-danger;
}
}
.mr-widget-body {
padding: 10px 15px;
h4 {
font-weight: bold;
margin: 5px 0;
}
p:last-child {
margin-bottom: 0;
}
}
.mr-widget-footer {
padding: 10px 15px;
border-top: 1px solid #EEE;
}
.ci-coverage {
float: right;
}
}
.merge-request-show-labels {
a {
margin-right: 5px;
Loading
Loading
@@ -182,7 +196,3 @@
.merge-request-form .select2-container {
width: 250px !important;
}
#modal_merge_info .modal-dialog {
width: 600px;
}
Loading
Loading
@@ -13,20 +13,27 @@ class Projects::BlobController < Projects::ApplicationController
before_action :commit, except: [:new, :create]
before_action :blob, except: [:new, :create]
before_action :from_merge_request, only: [:edit, :update]
before_action :require_branch_head, only: [:edit, :update]
before_action :editor_variables, except: [:show, :preview, :diff]
before_action :after_edit_path, only: [:edit, :update]
before_action :require_branch_head, only: [:edit, :update]
 
def new
commit unless @repository.empty?
end
 
def create
result = Files::CreateService.new(@project, current_user, @commit_params).execute
file_path = File.join(@path, File.basename(params[:file_name]))
result = Files::CreateService.new(
@project,
current_user,
params.merge(new_branch: sanitized_new_branch_name),
@ref,
file_path
).execute
 
if result[:status] == :success
flash[:notice] = "Your changes have been successfully committed"
redirect_to namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @file_path))
ref = sanitized_new_branch_name.presence || @ref
redirect_to namespace_project_blob_path(@project.namespace, @project, File.join(ref, file_path))
else
flash[:alert] = result[:message]
render :new
Loading
Loading
@@ -41,10 +48,22 @@ class Projects::BlobController < Projects::ApplicationController
end
 
def update
result = Files::UpdateService.new(@project, current_user, @commit_params).execute
result = Files::UpdateService.
new(
@project,
current_user,
params.merge(new_branch: sanitized_new_branch_name),
@ref,
@path
).execute
 
if result[:status] == :success
flash[:notice] = "Your changes have been successfully committed"
if from_merge_request
from_merge_request.reload_code
end
redirect_to after_edit_path
else
flash[:alert] = result[:message]
Loading
Loading
@@ -61,11 +80,12 @@ class Projects::BlobController < Projects::ApplicationController
end
 
def destroy
result = Files::DeleteService.new(@project, current_user, @commit_params).execute
result = Files::DeleteService.new(@project, current_user, params, @ref, @path).execute
 
if result[:status] == :success
flash[:notice] = "Your changes have been successfully committed"
redirect_to namespace_project_tree_path(@project.namespace, @project, @target_branch)
redirect_to namespace_project_tree_path(@project.namespace, @project,
@ref)
else
flash[:alert] = result[:message]
render :show
Loading
Loading
@@ -115,6 +135,7 @@ class Projects::BlobController < Projects::ApplicationController
@id = params[:id]
@ref, @path = extract_ref(@id)
 
rescue InvalidPathError
not_found!
end
Loading
Loading
@@ -124,8 +145,8 @@ class Projects::BlobController < Projects::ApplicationController
if from_merge_request
diffs_namespace_project_merge_request_path(from_merge_request.target_project.namespace, from_merge_request.target_project, from_merge_request) +
"#file-path-#{hexdigest(@path)}"
elsif @target_branch.present?
namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @path))
elsif sanitized_new_branch_name.present?
namespace_project_blob_path(@project.namespace, @project, File.join(sanitized_new_branch_name, @path))
else
namespace_project_blob_path(@project.namespace, @project, @id)
end
Loading
Loading
@@ -139,25 +160,4 @@ class Projects::BlobController < Projects::ApplicationController
def sanitized_new_branch_name
@new_branch ||= sanitize(strip_tags(params[:new_branch]))
end
def editor_variables
@current_branch = @ref
@target_branch = (sanitized_new_branch_name || @ref)
@file_path =
if action_name.to_s == 'create'
File.join(@path, File.basename(params[:file_name]))
else
@path
end
@commit_params = {
file_path: @file_path,
current_branch: @current_branch,
target_branch: @target_branch,
commit_message: params[:commit_message],
file_content: params[:content],
file_content_encoding: params[:encoding]
}
end
end
Loading
Loading
@@ -13,8 +13,13 @@ class Projects::CompareController < Projects::ApplicationController
base_ref = Addressable::URI.unescape(params[:from])
@ref = head_ref = Addressable::URI.unescape(params[:to])
 
compare_result = CompareService.new.
execute(@project, head_ref, @project, base_ref)
compare_result = CompareService.new.execute(
current_user,
@project,
head_ref,
@project,
base_ref
)
 
@commits = compare_result.commits
@diffs = compare_result.diffs
Loading
Loading
require 'gitlab/satellite/satellite'
class Projects::MergeRequestsController < Projects::ApplicationController
before_action :module_enabled
before_action :merge_request, only: [
:edit, :update, :show, :diffs, :commits, :merge, :merge_check,
:edit, :update, :show, :diffs, :commits, :automerge, :automerge_check,
:ci_status, :toggle_subscription
]
before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits]
Loading
Loading
@@ -135,7 +137,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
end
 
def merge_check
def automerge_check
if @merge_request.unchecked?
@merge_request.check_if_can_be_merged
end
Loading
Loading
@@ -145,11 +147,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render partial: "projects/merge_requests/widget/show.html.haml", layout: false
end
 
def merge
def automerge
return access_denied! unless @merge_request.can_be_merged_by?(current_user)
 
if @merge_request.mergeable?
MergeWorker.perform_async(@merge_request.id, current_user.id, params)
if @merge_request.automergeable?
AutoMergeWorker.perform_async(@merge_request.id, current_user.id, params)
@status = true
else
@status = false
Loading
Loading
Loading
Loading
@@ -61,14 +61,4 @@ module MergeRequestsHelper
}
)
end
def source_branch_with_namespace(merge_request)
if merge_request.for_fork?
namespace = link_to(merge_request.source_project_namespace,
project_path(merge_request.source_project))
namespace + ":#{merge_request.source_branch}"
else
merge_request.source_branch
end
end
end
Loading
Loading
@@ -41,6 +41,8 @@ class MergeRequest < ActiveRecord::Base
 
delegate :commits, :diffs, :last_commit, :last_commit_short_sha, to: :merge_request_diff, prefix: nil
 
attr_accessor :should_remove_source_branch
# When this attribute is true some MR validation is ignored
# It allows us to close or modify broken merge requests
attr_accessor :allow_broken
Loading
Loading
@@ -55,7 +57,7 @@ class MergeRequest < ActiveRecord::Base
transition [:reopened, :opened] => :closed
end
 
event :mark_as_merged do
event :merge do
transition [:reopened, :opened, :locked] => :merged
end
 
Loading
Loading
@@ -203,10 +205,7 @@ class MergeRequest < ActiveRecord::Base
end
 
def check_if_can_be_merged
can_be_merged =
project.repository.can_be_merged?(source_sha, target_branch)
if can_be_merged
if Gitlab::Satellite::MergeAction.new(self.author, self).can_be_merged?
mark_as_mergeable
else
mark_as_unmergeable
Loading
Loading
@@ -221,6 +220,18 @@ class MergeRequest < ActiveRecord::Base
self.target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last
end
 
def automerge!(current_user, commit_message = nil)
return unless automergeable?
MergeRequests::AutoMergeService.
new(target_project, current_user).
execute(self, commit_message)
end
def remove_source_branch?
self.should_remove_source_branch && !self.source_project.root_ref?(self.source_branch) && !self.for_fork?
end
def open?
opened? || reopened?
end
Loading
Loading
@@ -229,11 +240,11 @@ class MergeRequest < ActiveRecord::Base
title =~ /\A\[?WIP\]?:? /i
end
 
def mergeable?
def automergeable?
open? && !work_in_progress? && can_be_merged?
end
 
def gitlab_merge_status
def automerge_status
if work_in_progress?
"work_in_progress"
else
Loading
Loading
@@ -260,14 +271,14 @@ class MergeRequest < ActiveRecord::Base
#
# see "git diff"
def to_diff(current_user)
target_project.repository.diff_text(target_branch, source_sha)
Gitlab::Satellite::MergeAction.new(current_user, self).diff_in_satellite
end
 
# Returns the commit as a series of email patches.
#
# see "git format-patch"
def to_patch(current_user)
target_project.repository.format_patch(target_branch, source_sha)
Gitlab::Satellite::MergeAction.new(current_user, self).format_patch
end
 
def hook_attrs
Loading
Loading
@@ -418,30 +429,4 @@ class MergeRequest < ActiveRecord::Base
"Open"
end
end
def target_sha
@target_sha ||= target_project.
repository.commit(target_branch).sha
end
def source_sha
commits.first.sha
end
def fetch_ref
target_project.repository.fetch_ref(
source_project.repository.path_to_repo,
"refs/heads/#{source_branch}",
"refs/merge-requests/#{iid}/head"
)
end
def in_locked_state
begin
lock_mr
yield
ensure
unlock_mr if locked?
end
end
end
Loading
Loading
@@ -16,8 +16,9 @@ require Rails.root.join("app/models/commit")
class MergeRequestDiff < ActiveRecord::Base
include Sortable
 
# Prevent store of diff if commits amount more then 500
COMMITS_SAFE_SIZE = 500
# Prevent store of diff
# if commits amount more then 200
COMMITS_SAFE_SIZE = 200
 
attr_reader :commits, :diffs
 
Loading
Loading
@@ -123,12 +124,12 @@ class MergeRequestDiff < ActiveRecord::Base
if new_diffs.any?
if new_diffs.size > Commit::DIFF_HARD_LIMIT_FILES
self.state = :overflow_diff_files_limit
new_diffs = new_diffs.first[Commit::DIFF_HARD_LIMIT_LINES]
new_diffs = []
end
 
if new_diffs.sum { |diff| diff.diff.lines.count } > Commit::DIFF_HARD_LIMIT_LINES
self.state = :overflow_diff_lines_limit
new_diffs = new_diffs.first[Commit::DIFF_HARD_LIMIT_LINES]
new_diffs = []
end
end
 
Loading
Loading
@@ -159,21 +160,12 @@ class MergeRequestDiff < ActiveRecord::Base
private
 
def compare_result
@compare_result ||=
begin
# Update ref for merge request
merge_request.fetch_ref
# Get latest sha of branch from source project
source_sha = merge_request.source_project.commit(source_branch).sha
Gitlab::CompareResult.new(
Gitlab::Git::Compare.new(
merge_request.target_project.repository.raw_repository,
merge_request.target_branch,
source_sha,
)
)
end
@compare_result ||= CompareService.new.execute(
merge_request.author,
merge_request.source_project,
merge_request.source_branch,
merge_request.target_project,
merge_request.target_branch,
)
end
end
Loading
Loading
@@ -118,11 +118,12 @@ class Namespace < ActiveRecord::Base
gitlab_shell.add_namespace(path_was)
 
if gitlab_shell.mv_namespace(path_was, path)
# If repositories moved successfully we need to
# send update instructions to users.
# If repositories moved successfully we need to remove old satellites
# and send update instructions to users.
# However we cannot allow rollback since we moved namespace dir
# So we basically we mute exceptions in next actions
begin
gitlab_shell.rm_satellites(path_was)
send_update_instructions
rescue
# Returning false does not rollback after_* transaction but gives
Loading
Loading
Loading
Loading
@@ -520,6 +520,14 @@ class Project < ActiveRecord::Base
!repository.exists? || repository.empty?
end
 
def ensure_satellite_exists
self.satellite.create unless self.satellite.exists?
end
def satellite
@satellite ||= Gitlab::Satellite::Satellite.new(self)
end
def repo
repository.raw
end
Loading
Loading
@@ -589,11 +597,14 @@ class Project < ActiveRecord::Base
new_path_with_namespace = File.join(namespace_dir, path)
 
if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace)
# If repository moved successfully we need to send update instructions to users.
# If repository moved successfully we need to remove old satellite
# and send update instructions to users.
# However we cannot allow rollback since we moved repository
# So we basically we mute exceptions in next actions
begin
gitlab_shell.mv_repository("#{old_path_with_namespace}.wiki", "#{new_path_with_namespace}.wiki")
gitlab_shell.rm_satellites(old_path_with_namespace)
ensure_satellite_exists
send_move_instructions
reset_events_cache
rescue
Loading
Loading
@@ -691,6 +702,7 @@ class Project < ActiveRecord::Base
def create_repository
if forked?
if gitlab_shell.fork_repository(forked_from_project.path_with_namespace, self.namespace.path)
ensure_satellite_exists
true
else
errors.add(:base, 'Failed to fork repository via gitlab-shell')
Loading
Loading
Loading
Loading
@@ -74,8 +74,6 @@ class GitlabCiService < CiService
else
:error
end
rescue Errno::ECONNREFUSED
:error
end
 
def fork_registration(new_project, private_token)
Loading
Loading
@@ -105,8 +103,6 @@ class GitlabCiService < CiService
if response.code == 200 and response["coverage"]
response["coverage"]
end
rescue Errno::ECONNREFUSED
nil
end
 
def build_page(sha, ref)
Loading
Loading
Loading
Loading
@@ -364,83 +364,6 @@ class Repository
@root_ref ||= raw_repository.root_ref
end
 
def commit_file(user, path, content, message, ref)
path[0] = '' if path[0] == '/'
committer = user_to_comitter(user)
options = {}
options[:committer] = committer
options[:author] = committer
options[:commit] = {
message: message,
branch: ref
}
options[:file] = {
content: content,
path: path
}
Gitlab::Git::Blob.commit(raw_repository, options)
end
def remove_file(user, path, message, ref)
path[0] = '' if path[0] == '/'
committer = user_to_comitter(user)
options = {}
options[:committer] = committer
options[:author] = committer
options[:commit] = {
message: message,
branch: ref
}
options[:file] = {
path: path
}
Gitlab::Git::Blob.remove(raw_repository, options)
end
def user_to_comitter(user)
{
email: user.email,
name: user.name,
time: Time.now
}
end
def can_be_merged?(source_sha, target_branch)
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)
if our_commit && their_commit
!rugged.merge_commits(our_commit, their_commit).conflicts?
else
false
end
end
def merge(source_sha, target_branch, options = {})
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)
raise "Invalid merge target" if our_commit.nil?
raise "Invalid merge source" if their_commit.nil?
merge_index = rugged.merge_commits(our_commit, their_commit)
return false if merge_index.conflicts?
actual_options = options.merge(
parents: [our_commit, their_commit],
tree: merge_index.write_tree(rugged),
update_ref: "refs/heads/#{target_branch}"
)
Rugged::Commit.create(rugged, actual_options)
end
def search_files(query, ref)
offset = 2
args = %W(git grep -i -n --before-context #{offset} --after-context #{offset} #{query} #{ref || root_ref})
Loading
Loading
@@ -474,11 +397,6 @@ class Repository
)
end
 
def fetch_ref(source_path, source_ref, target_ref)
args = %W(git fetch #{source_path} #{source_ref}:#{target_ref})
Gitlab::Popen.popen(args, path_to_repo)
end
private
 
def cache
Loading
Loading
Loading
Loading
@@ -31,10 +31,6 @@ class BaseService
SystemHooksService.new
end
 
def repository
project.repository
end
# Add an error to the specified model for restricted visibility levels
def deny_visibility_level(model, denied_visibility_level = nil)
denied_visibility_level ||= model.visibility_level
Loading
Loading
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)
source_sha = source_project.commit(source_branch).sha
# If compare with other project we need to fetch ref first
unless target_project == source_project
random_string = SecureRandom.hex
target_project.repository.fetch_ref(
source_project.repository.path_to_repo,
"refs/heads/#{source_branch}",
"refs/tmp/#{random_string}/head"
def execute(current_user, source_project, source_branch, target_project, target_branch)
# Try to compare branches to get commits list and diffs
#
# Note: Use satellite only when need to compare between two repos
# because satellites are slower than operations on bare repo
if target_project == source_project
Gitlab::CompareResult.new(
Gitlab::Git::Compare.new(
target_project.repository.raw_repository,
target_branch,
source_branch,
)
)
end
Gitlab::CompareResult.new(
Gitlab::Git::Compare.new(
target_project.repository.raw_repository,
else
Gitlab::Satellite::CompareAction.new(
current_user,
target_project,
target_branch,
source_sha,
)
)
source_project,
source_branch
).result
end
end
end
module Files
class BaseService < ::BaseService
class ValidationError < StandardError; end
attr_reader :ref, :path
 
def execute
@current_branch = params[:current_branch]
@target_branch = params[:target_branch]
@commit_message = params[:commit_message]
@file_path = params[:file_path]
@file_content = if params[:file_content_encoding] == 'base64'
Base64.decode64(params[:file_content])
else
params[:file_content]
end
# Validate parameters
validate
# Create new branch if it different from current_branch
if @target_branch != @current_branch
create_target_branch
end
if sha = commit
after_commit(sha, @target_branch)
success
else
error("Something went wrong. Your changes were not committed")
end
rescue ValidationError => ex
error(ex.message)
def initialize(project, user, params, ref, path = nil)
@project, @current_user, @params = project, user, params.dup
@ref = ref
@path = path
end
 
private
 
def after_commit(sha, branch)
PostCommitService.new(project, current_user).execute(sha, branch)
end
def current_branch
@current_branch ||= params[:current_branch]
end
def target_branch
@target_branch ||= params[:target_branch]
end
def raise_error(message)
raise ValidationError.new(message)
end
def validate
allowed = ::Gitlab::GitAccess.new(current_user, project).can_push_to_branch?(@target_branch)
unless allowed
raise_error("You are not allowed to push into this branch")
end
unless project.empty_repo?
unless repository.branch_names.include?(@current_branch)
raise_error("You can only create files if you are on top of a branch")
end
if @current_branch != @target_branch
if repository.branch_names.include?(@target_branch)
raise_error("Branch with such name already exists. You need to switch to this branch in order to make changes")
end
end
end
end
def create_target_branch
result = CreateBranchService.new(project, current_user).execute(@target_branch, @current_branch)
unless result[:status] == :success
raise_error("Something went wrong when we tried to create #{@target_branch} for you")
end
def repository
project.repository
end
end
end
require_relative "base_service"
 
module Files
class CreateService < Files::BaseService
def commit
repository.commit_file(current_user, @file_path, @file_content, @commit_message, @target_branch)
end
class CreateService < BaseService
def execute
allowed = Gitlab::GitAccess.new(current_user, project).can_push_to_branch?(ref)
 
def validate
super
unless allowed
return error("You are not allowed to create file in this branch")
end
 
file_name = File.basename(@file_path)
file_name = File.basename(path)
file_path = path
 
unless file_name =~ Gitlab::Regex.file_name_regex
raise_error(
return error(
'Your changes could not be committed, because the file name ' +
Gitlab::Regex.file_name_regex_message
)
end
 
unless project.empty_repo?
blob = repository.blob_at_branch(@current_branch, @file_path)
if project.empty_repo?
# everything is ok because repo does not have a commits yet
else
unless repository.branch_names.include?(ref)
return error("You can only create files if you are on top of a branch")
end
blob = repository.blob_at_branch(ref, file_path)
 
if blob
raise_error("Your changes could not be committed, because file with such name exists")
return error("Your changes could not be committed, because file with such name exists")
end
end
new_file_action = Gitlab::Satellite::NewFileAction.new(current_user, project, ref, file_path)
created_successfully = new_file_action.commit!(
params[:content],
params[:commit_message],
params[:encoding],
params[:new_branch]
)
if created_successfully
success
else
error("Your changes could not be committed, because the file has been changed")
end
end
end
end
require_relative "base_service"
 
module Files
class DeleteService < Files::BaseService
def commit
repository.remove_file(current_user, @file_path, @commit_message, @target_branch)
class DeleteService < BaseService
def execute
allowed = ::Gitlab::GitAccess.new(current_user, project).can_push_to_branch?(ref)
unless allowed
return error("You are not allowed to push into this branch")
end
unless repository.branch_names.include?(ref)
return error("You can only create files if you are on top of a branch")
end
blob = repository.blob_at_branch(ref, path)
unless blob
return error("You can only edit text files")
end
delete_file_action = Gitlab::Satellite::DeleteFileAction.new(current_user, project, ref, path)
deleted_successfully = delete_file_action.commit!(
nil,
params[:commit_message]
)
if deleted_successfully
success
else
error("Your changes could not be committed, because the file has been changed")
end
end
end
end
require_relative "base_service"
 
module Files
class UpdateService < Files::BaseService
def commit
repository.commit_file(current_user, @file_path, @file_content, @commit_message, @target_branch)
class UpdateService < BaseService
def execute
allowed = ::Gitlab::GitAccess.new(current_user, project).can_push_to_branch?(ref)
unless allowed
return error("You are not allowed to push into this branch")
end
unless repository.branch_names.include?(ref)
return error("You can only create files if you are on top of a branch")
end
blob = repository.blob_at_branch(ref, path)
unless blob
return error("You can only edit text files")
end
edit_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path)
edit_file_action.commit!(
params[:content],
params[:commit_message],
params[:encoding],
params[:new_branch]
)
success
rescue Gitlab::Satellite::CheckoutFailed => ex
error("Your changes could not be committed because ref '#{ref}' could not be checked out", 400)
rescue Gitlab::Satellite::CommitFailed => ex
error("Your changes could not be committed. Maybe there was nothing to commit?", 409)
rescue Gitlab::Satellite::PushFailed => ex
error("Your changes could not be committed. Maybe the file was changed by another process?", 409)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment