utils/git: add cherry-pick function
This commit is contained in:
parent
49d2e4cbab
commit
3a8bd8514f
@ -44,6 +44,14 @@ describe Utils::Git do
|
|||||||
let(:files_hash1) { [@h3[0..6], ["LICENSE.txt"]] }
|
let(:files_hash1) { [@h3[0..6], ["LICENSE.txt"]] }
|
||||||
let(:files_hash2) { [@h2[0..6], ["README.md"]] }
|
let(:files_hash2) { [@h2[0..6], ["README.md"]] }
|
||||||
|
|
||||||
|
describe "#cherry_pick!" do
|
||||||
|
it "aborts when cherry picking an existing hash" do
|
||||||
|
expect {
|
||||||
|
described_class.cherry_pick!(HOMEBREW_CACHE, file_hash1)
|
||||||
|
}.to raise_error(ErrorDuringExecution, /Merge conflict in README.md/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#last_revision_commit_of_file" do
|
describe "#last_revision_commit_of_file" do
|
||||||
it "gives last revision commit when before_commit is nil" do
|
it "gives last revision commit when before_commit is nil" do
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
@ -119,5 +119,19 @@ module Utils
|
|||||||
Utils.popen_read(git, "-C", repo, "symbolic-ref", "-q", "--short",
|
Utils.popen_read(git, "-C", repo, "symbolic-ref", "-q", "--short",
|
||||||
"refs/remotes/origin/HEAD").chomp.presence
|
"refs/remotes/origin/HEAD").chomp.presence
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Special case of `git cherry-pick` that permits non-verbose output and
|
||||||
|
# optional resolution on merge conflict.
|
||||||
|
def cherry_pick!(repo, *args, resolve: false, verbose: false)
|
||||||
|
cmd = [git, "-C", repo, "cherry-pick"] + args
|
||||||
|
output = Utils.popen_read(*cmd, err: :out)
|
||||||
|
if $CHILD_STATUS.success?
|
||||||
|
puts output if verbose
|
||||||
|
output
|
||||||
|
else
|
||||||
|
system git, "-C", repo, "cherry-pick", "--abort" unless resolve
|
||||||
|
raise ErrorDuringExecution.new(cmd, status: $CHILD_STATUS, output: [[:stdout, output]])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user