utils/git: helper function to get commit msg
This commit is contained in:
parent
d116087af6
commit
cdfb1badcf
@ -18,26 +18,26 @@ describe Utils::Git do
|
|||||||
|
|
||||||
File.open("README.md", "w") { |f| f.write("README") }
|
File.open("README.md", "w") { |f| f.write("README") }
|
||||||
system git, "add", HOMEBREW_CACHE/"README.md"
|
system git, "add", HOMEBREW_CACHE/"README.md"
|
||||||
system git, "commit", "-m", "'File added'"
|
system git, "commit", "-m", "File added"
|
||||||
@h1 = `git rev-parse HEAD`
|
@h1 = `git rev-parse HEAD`
|
||||||
|
|
||||||
File.open("README.md", "w") { |f| f.write("# README") }
|
File.open("README.md", "w") { |f| f.write("# README") }
|
||||||
system git, "add", HOMEBREW_CACHE/"README.md"
|
system git, "add", HOMEBREW_CACHE/"README.md"
|
||||||
system git, "commit", "-m", "'written to File'"
|
system git, "commit", "-m", "written to File"
|
||||||
@h2 = `git rev-parse HEAD`
|
@h2 = `git rev-parse HEAD`
|
||||||
|
|
||||||
File.open("LICENSE.txt", "w") { |f| f.write("LICENCE") }
|
File.open("LICENSE.txt", "w") { |f| f.write("LICENCE") }
|
||||||
system git, "add", HOMEBREW_CACHE/"LICENSE.txt"
|
system git, "add", HOMEBREW_CACHE/"LICENSE.txt"
|
||||||
system git, "commit", "-m", "'File added'"
|
system git, "commit", "-m", "File added"
|
||||||
@h3 = `git rev-parse HEAD`
|
@h3 = `git rev-parse HEAD`
|
||||||
|
|
||||||
File.open("LICENSE.txt", "w") { |f| f.write("LICENSE") }
|
File.open("LICENSE.txt", "w") { |f| f.write("LICENSE") }
|
||||||
system git, "add", HOMEBREW_CACHE/"LICENSE.txt"
|
system git, "add", HOMEBREW_CACHE/"LICENSE.txt"
|
||||||
system git, "commit", "-m", "'written to File'"
|
system git, "commit", "-m", "written to File"
|
||||||
|
|
||||||
File.open("LICENSE.txt", "w") { |f| f.write("test") }
|
File.open("LICENSE.txt", "w") { |f| f.write("test") }
|
||||||
system git, "add", HOMEBREW_CACHE/"LICENSE.txt"
|
system git, "add", HOMEBREW_CACHE/"LICENSE.txt"
|
||||||
system git, "commit", "-m", "'written to File'"
|
system git, "commit", "-m", "written to File"
|
||||||
@cherry_pick_commit = `git rev-parse HEAD`
|
@cherry_pick_commit = `git rev-parse HEAD`
|
||||||
system git, "reset", "--hard", "HEAD^"
|
system git, "reset", "--hard", "HEAD^"
|
||||||
end
|
end
|
||||||
@ -51,6 +51,19 @@ describe Utils::Git do
|
|||||||
let(:files_hash2) { [@h2[0..6], ["README.md"]] }
|
let(:files_hash2) { [@h2[0..6], ["README.md"]] }
|
||||||
let(:cherry_pick_commit) { @cherry_pick_commit[0..6] }
|
let(:cherry_pick_commit) { @cherry_pick_commit[0..6] }
|
||||||
|
|
||||||
|
describe "#commit_message" do
|
||||||
|
it "returns the commit message" do
|
||||||
|
expect(described_class.commit_message(HOMEBREW_CACHE, file_hash1)).to eq("File added")
|
||||||
|
expect(described_class.commit_message(HOMEBREW_CACHE, file_hash2)).to eq("written to File")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "errors when commit doesn't exist" do
|
||||||
|
expect {
|
||||||
|
described_class.commit_message(HOMEBREW_CACHE, "bad_refspec")
|
||||||
|
}.to raise_error(ErrorDuringExecution, /bad revision/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#cherry_pick!" do
|
describe "#cherry_pick!" do
|
||||||
it "can cherry pick a commit" do
|
it "can cherry pick a commit" do
|
||||||
expect(described_class.cherry_pick!(HOMEBREW_CACHE, cherry_pick_commit)).to be_truthy
|
expect(described_class.cherry_pick!(HOMEBREW_CACHE, cherry_pick_commit)).to be_truthy
|
||||||
|
|||||||
@ -86,6 +86,11 @@ module Utils
|
|||||||
Utils.popen_read(git, "-C", repo, "show", "#{commit}:#{relative_file}")
|
Utils.popen_read(git, "-C", repo, "show", "#{commit}:#{relative_file}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def commit_message(repo, commit = nil)
|
||||||
|
commit ||= "HEAD"
|
||||||
|
Utils.safe_popen_read(git, "-C", repo, "log", "-1", "--pretty=%B", commit, "--", err: :out).strip
|
||||||
|
end
|
||||||
|
|
||||||
def ensure_installed!
|
def ensure_installed!
|
||||||
return if available?
|
return if available?
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user