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:
authorRobert Speicher <rspeicher@gmail.com>2020-07-14 23:44:22 +0300
committerRobert Speicher <rspeicher@gmail.com>2020-07-20 18:19:07 +0300
commitdcc1fe0504f87feb1d7a239e742db3abd5e20693 (patch)
treef974747ee0a9dfbe89b069bfba0309f129167ca4
parent623be367ff5fa7822c9ca71dca4897376f30b999 (diff)
Support dry-run cherry-picks and reverts
This will perform a cherry-pick or revert with the specified arguments, but not actually create a resulting commit. This allows a user to check for a `CreateTreeError` on an operation but not modify the repository. One example use case is in the Delivery team. We want to know if a security merge request targeting `master` will cherry-pick cleanly to the previous stable branches. If it does, we can simply cherry-pick it prior to release; if it doesn't, we need to inform the developer that they need to create a backport.
-rw-r--r--changelogs/unreleased/rs-cherry-pick-revert-dry-run.yml5
-rw-r--r--ruby/lib/gitaly_server/operations_service.rb6
-rw-r--r--ruby/lib/gitlab/git/repository.rb65
3 files changed, 52 insertions, 24 deletions
diff --git a/changelogs/unreleased/rs-cherry-pick-revert-dry-run.yml b/changelogs/unreleased/rs-cherry-pick-revert-dry-run.yml
new file mode 100644
index 000000000..18b3632be
--- /dev/null
+++ b/changelogs/unreleased/rs-cherry-pick-revert-dry-run.yml
@@ -0,0 +1,5 @@
+---
+title: Support dry-run cherry-picks and reverts
+merge_request: 2382
+author:
+type: added
diff --git a/ruby/lib/gitaly_server/operations_service.rb b/ruby/lib/gitaly_server/operations_service.rb
index a6cd3f13d..f85ba5c9c 100644
--- a/ruby/lib/gitaly_server/operations_service.rb
+++ b/ruby/lib/gitaly_server/operations_service.rb
@@ -168,7 +168,8 @@ module GitalyServer
branch_name: request.branch_name,
message: request.message.dup,
start_branch_name: request.start_branch_name.presence,
- start_repository: start_repository
+ start_repository: start_repository,
+ dry_run: request.dry_run
)
branch_update = branch_update_result(result)
@@ -196,7 +197,8 @@ module GitalyServer
branch_name: request.branch_name,
message: request.message.dup,
start_branch_name: request.start_branch_name.presence,
- start_repository: start_repository
+ start_repository: start_repository,
+ dry_run: request.dry_run
)
branch_update = branch_update_result(result)
diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb
index 540e61a18..43c0b2a85 100644
--- a/ruby/lib/gitlab/git/repository.rb
+++ b/ruby/lib/gitlab/git/repository.rb
@@ -321,7 +321,7 @@ module Gitlab
raise ArgumentError, 'Invalid merge source'
end
- def revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:)
+ def revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false)
OperationService.new(user, self).with_branch(
branch_name,
start_branch_name: start_branch_name,
@@ -330,24 +330,35 @@ module Gitlab
revert_tree_id = check_revert_content(commit, start_commit.sha)
- committer = user_to_committer(user)
-
- create_commit(message: message,
- author: committer,
- committer: committer,
- tree: revert_tree_id,
- parents: [start_commit.sha])
+ if dry_run
+ # At this point the tree has been written to the object database but
+ # not committed, so we'll leave it to be cleaned up by `gc`.
+ #
+ # The response expects a SHA, so just return the starting one.
+ start_commit.sha
+ else
+ committer = user_to_committer(user)
+
+ create_commit(
+ message: message,
+ author: committer,
+ committer: committer,
+ tree: revert_tree_id,
+ parents: [start_commit.sha]
+ )
+ end
end
end
- def cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:)
+ def cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false)
args = {
user: user,
commit: commit,
branch_name: branch_name,
message: message,
start_branch_name: start_branch_name,
- start_repository: start_repository
+ start_repository: start_repository,
+ dry_run: dry_run
}
rugged_cherry_pick(args)
@@ -822,7 +833,7 @@ module Gitlab
raise GitError, "Could not delete refs #{ref_names}: #{message}" unless status.zero?
end
- def rugged_cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:)
+ def rugged_cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false)
OperationService.new(user, self).with_branch(
branch_name,
start_branch_name: start_branch_name,
@@ -831,17 +842,27 @@ module Gitlab
cherry_pick_tree_id = check_cherry_pick_content(commit, start_commit.sha)
- committer = user_to_committer(user)
-
- create_commit(message: message,
- author: {
- email: commit.author_email,
- name: commit.author_name,
- time: commit.authored_date
- },
- committer: committer,
- tree: cherry_pick_tree_id,
- parents: [start_commit.sha])
+ if dry_run
+ # At this point the tree has been written to the object database but
+ # not committed, so we'll leave it to be cleaned up by `gc`.
+ #
+ # The response expects a SHA, so just return the starting one.
+ start_commit.sha
+ else
+ committer = user_to_committer(user)
+
+ create_commit(
+ message: message,
+ author: {
+ email: commit.author_email,
+ name: commit.author_name,
+ time: commit.authored_date
+ },
+ committer: committer,
+ tree: cherry_pick_tree_id,
+ parents: [start_commit.sha]
+ )
+ end
end
end