utils/git_repository: use Pathname.pwd if no repo specified

This commit is contained in:
Seeker 2021-01-12 11:04:49 -08:00
parent 9f4105f325
commit 4f02c1c8a8
2 changed files with 10 additions and 2 deletions

View File

@ -20,6 +20,10 @@ describe Utils do
it "returns the revision at HEAD" do it "returns the revision at HEAD" do
expect(described_class.git_head(HOMEBREW_CACHE)).to eq(head_revision) expect(described_class.git_head(HOMEBREW_CACHE)).to eq(head_revision)
expect(described_class.git_head(HOMEBREW_CACHE, length: 5)).to eq(head_revision[0...5]) expect(described_class.git_head(HOMEBREW_CACHE, length: 5)).to eq(head_revision[0...5])
HOMEBREW_CACHE.cd do
expect(described_class.git_head).to eq(head_revision)
expect(described_class.git_head(length: 5)).to eq(head_revision[0...5])
end
end end
end end
@ -27,6 +31,10 @@ describe Utils do
it "returns the short revision at HEAD" do it "returns the short revision at HEAD" do
expect(described_class.git_short_head(HOMEBREW_CACHE)).to eq(short_head_revision) expect(described_class.git_short_head(HOMEBREW_CACHE)).to eq(short_head_revision)
expect(described_class.git_short_head(HOMEBREW_CACHE, length: 5)).to eq(head_revision[0...5]) expect(described_class.git_short_head(HOMEBREW_CACHE, length: 5)).to eq(head_revision[0...5])
HOMEBREW_CACHE.cd do
expect(described_class.git_short_head).to eq(short_head_revision)
expect(described_class.git_short_head(length: 5)).to eq(head_revision[0...5])
end
end end
end end
end end

View File

@ -7,7 +7,7 @@ module Utils
sig do sig do
params(repo: T.any(String, Pathname), length: T.nilable(Integer), safe: T::Boolean).returns(T.nilable(String)) params(repo: T.any(String, Pathname), length: T.nilable(Integer), safe: T::Boolean).returns(T.nilable(String))
end end
def self.git_head(repo, length: nil, safe: true) def self.git_head(repo = Pathname.pwd, length: nil, safe: true)
return git_short_head(repo, length: length) if length.present? return git_short_head(repo, length: length) if length.present?
repo = Pathname(repo).extend(GitRepositoryExtension) repo = Pathname(repo).extend(GitRepositoryExtension)
@ -17,7 +17,7 @@ module Utils
sig do sig do
params(repo: T.any(String, Pathname), length: T.nilable(Integer), safe: T::Boolean).returns(T.nilable(String)) params(repo: T.any(String, Pathname), length: T.nilable(Integer), safe: T::Boolean).returns(T.nilable(String))
end end
def self.git_short_head(repo, length: nil, safe: true) def self.git_short_head(repo = Pathname.pwd, length: nil, safe: true)
repo = Pathname(repo).extend(GitRepositoryExtension) repo = Pathname(repo).extend(GitRepositoryExtension)
repo.git_short_head(length: length, safe: safe) repo.git_short_head(length: length, safe: safe)
end end