utils/git: new file_at_commit function
This commit is contained in:
parent
04687aef93
commit
d09ebf428f
@ -68,6 +68,17 @@ describe Utils::Git do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#file_at_commit" do
|
||||||
|
it "returns file contents when file exists" do
|
||||||
|
expect(described_class.file_at_commit(HOMEBREW_CACHE, file, file_hash1)).to eq("README")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns empty when file doesn't exist" do
|
||||||
|
expect(described_class.file_at_commit(HOMEBREW_CACHE, "foo.txt", file_hash1)).to eq("")
|
||||||
|
expect(described_class.file_at_commit(HOMEBREW_CACHE, "LICENSE.txt", file_hash1)).to eq("")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#last_revision_commit_of_files" do
|
describe "#last_revision_commit_of_files" do
|
||||||
context "when before_commit is nil" do
|
context "when before_commit is nil" do
|
||||||
it "gives last revision commit" do
|
it "gives last revision commit" do
|
||||||
|
|||||||
@ -76,9 +76,14 @@ module Utils
|
|||||||
|
|
||||||
def last_revision_of_file(repo, file, before_commit: nil)
|
def last_revision_of_file(repo, file, before_commit: nil)
|
||||||
relative_file = Pathname(file).relative_path_from(repo)
|
relative_file = Pathname(file).relative_path_from(repo)
|
||||||
|
|
||||||
commit_hash = last_revision_commit_of_file(repo, relative_file, before_commit: before_commit)
|
commit_hash = last_revision_commit_of_file(repo, relative_file, before_commit: before_commit)
|
||||||
Utils.popen_read(git, "-C", repo, "show", "#{commit_hash}:#{relative_file}")
|
file_at_commit(repo, file, commit_hash)
|
||||||
|
end
|
||||||
|
|
||||||
|
def file_at_commit(repo, file, commit)
|
||||||
|
relative_file = Pathname(file)
|
||||||
|
relative_file = relative_file.relative_path_from(repo) if relative_file.absolute?
|
||||||
|
Utils.popen_read(git, "-C", repo, "show", "#{commit}:#{relative_file}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_installed!
|
def ensure_installed!
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user