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

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Bajao <ebajao@gitlab.com>2019-02-15 08:06:12 +0300
committerPatrick Bajao <ebajao@gitlab.com>2019-03-01 03:39:02 +0300
commitb3da055d2ab2e14ab441c6263bdf8ca03148fde9 (patch)
treeea0a38ecd08c49b1fcaa01a509ec37707422f684
parent71eacd7564310e89b1518408380ff6d2de652a34 (diff)
Accept force option to overwrite branch on commit
-rw-r--r--internal/service/operations/commit_files_test.go49
-rw-r--r--ruby/lib/gitaly_server/operations_service.rb3
-rw-r--r--ruby/lib/gitlab/git/operation_service.rb11
-rw-r--r--ruby/lib/gitlab/git/repository.rb5
4 files changed, 61 insertions, 7 deletions
diff --git a/internal/service/operations/commit_files_test.go b/internal/service/operations/commit_files_test.go
index 3026c431d..50d02ede6 100644
--- a/internal/service/operations/commit_files_test.go
+++ b/internal/service/operations/commit_files_test.go
@@ -201,6 +201,55 @@ func TestSuccessfulUserCommitFilesRequestMove(t *testing.T) {
}
}
+func TestSuccessfulUserCommitFilesRequestForceCommit(t *testing.T) {
+ server, serverSocketPath := runFullServer(t)
+ defer server.Stop()
+
+ client, conn := operations.NewOperationClient(t, serverSocketPath)
+ defer conn.Close()
+
+ testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
+ defer cleanupFn()
+
+ ctxOuter, cancel := testhelper.Context()
+ defer cancel()
+
+ branchName := "feature"
+ authorName := []byte("Jane Doe")
+ authorEmail := []byte("janedoe@gitlab.com")
+ startBranchName := []byte("master")
+ filePath := "TEST.md"
+
+ md := testhelper.GitalyServersMetadata(t, serverSocketPath)
+ ctx := metadata.NewOutgoingContext(ctxOuter, md)
+ headerRequest := headerRequest(testRepo, user, branchName, commitFilesMessage, authorName, authorEmail, startBranchName, nil, true)
+ actionsRequest1 := createFileHeaderRequest(filePath)
+ actionsRequest2 := actionContentRequest("Test")
+
+ t.Run("existing repo and branch starting from another branch", func(t *testing.T) {
+ startBranchHeadCommit, err := log.GetCommit(ctxOuter, testRepo, string(startBranchName))
+ require.NoError(t, err)
+
+ oldHeadCommit, err := log.GetCommit(ctxOuter, testRepo, branchName)
+ require.NoError(t, err)
+
+ stream, err := client.UserCommitFiles(ctx)
+ require.NoError(t, err)
+ require.NoError(t, stream.Send(headerRequest))
+ require.NoError(t, stream.Send(actionsRequest1))
+ require.NoError(t, stream.Send(actionsRequest2))
+
+ r, err := stream.CloseAndRecv()
+ require.NoError(t, err)
+ require.NotNil(t, r.GetBranchUpdate())
+
+ headCommit, err := log.GetCommit(ctxOuter, testRepo, branchName)
+ require.NoError(t, err)
+ require.NotEqual(t, oldHeadCommit.Id, headCommit.Id)
+ require.Contains(t, headCommit.ParentIds, startBranchHeadCommit.Id)
+ })
+}
+
func TestFailedUserCommitFilesRequestDueToHooks(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
diff --git a/ruby/lib/gitaly_server/operations_service.rb b/ruby/lib/gitaly_server/operations_service.rb
index 9e52d06ff..64b52f6fb 100644
--- a/ruby/lib/gitaly_server/operations_service.rb
+++ b/ruby/lib/gitaly_server/operations_service.rb
@@ -321,7 +321,8 @@ module GitalyServer
optional_fields = {
start_branch_name: 'start_branch_name',
author_name: 'commit_author_name',
- author_email: 'commit_author_email'
+ author_email: 'commit_author_email',
+ force: 'force'
}.transform_values { |v| header[v].presence }
opts.merge(optional_fields)
diff --git a/ruby/lib/gitlab/git/operation_service.rb b/ruby/lib/gitlab/git/operation_service.rb
index ac6998dc2..74951ade0 100644
--- a/ruby/lib/gitlab/git/operation_service.rb
+++ b/ruby/lib/gitlab/git/operation_service.rb
@@ -77,6 +77,7 @@ module Gitlab
branch_name,
start_branch_name: nil,
start_repository: repository,
+ force: false,
&block
)
@@ -87,7 +88,7 @@ module Gitlab
raise ArgumentError, "Cannot find branch #{start_branch_name} in #{start_repository.relative_path}" if start_branch_name && !start_repository.branch_exists?(start_branch_name)
- update_branch_with_hooks(branch_name) do
+ update_branch_with_hooks(branch_name, force) do
repository.with_repo_branch_commit(
start_repository,
start_branch_name || branch_name,
@@ -130,7 +131,7 @@ module Gitlab
private
# Returns [newrev, should_run_after_create, should_run_after_create_branch]
- def update_branch_with_hooks(branch_name)
+ def update_branch_with_hooks(branch_name, force)
update_autocrlf_option
was_empty = repository.empty?
@@ -141,7 +142,7 @@ module Gitlab
raise Gitlab::Git::CommitError.new('Failed to create commit') unless newrev
branch = repository.find_branch(branch_name)
- oldrev = find_oldrev_from_branch(newrev, branch)
+ oldrev = find_oldrev_from_branch(newrev, branch, force)
ref = Gitlab::Git::BRANCH_REF_PREFIX + branch_name
update_ref_in_hooks(ref, newrev, oldrev)
@@ -149,11 +150,13 @@ module Gitlab
BranchUpdate.new(newrev, was_empty, was_empty || Gitlab::Git.blank_ref?(oldrev))
end
- def find_oldrev_from_branch(newrev, branch)
+ def find_oldrev_from_branch(newrev, branch, force)
return Gitlab::Git::BLANK_SHA unless branch
oldrev = branch.target
+ return oldrev if force
+
merge_base = repository.merge_base(newrev, branch.target)
raise Gitlab::Git::Repository::InvalidRef unless merge_base
diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb
index 8576ee8c4..e72315f25 100644
--- a/ruby/lib/gitlab/git/repository.rb
+++ b/ruby/lib/gitlab/git/repository.rb
@@ -540,13 +540,14 @@ module Gitlab
def multi_action(
user, branch_name:, message:, actions:,
author_email: nil, author_name: nil,
- start_branch_name: nil, start_repository: self
+ start_branch_name: nil, start_repository: self, force: false
)
OperationService.new(user, self).with_branch(
branch_name,
start_branch_name: start_branch_name,
- start_repository: start_repository
+ start_repository: start_repository,
+ force: force
) do |start_commit|
index = Gitlab::Git::Index.new(self)