Merge pull request #10306 from SeekingMeaning/git-repo-pwd

utils/git_repository: use `Pathname.pwd` if no `repo` specified
This commit is contained in:
Seeker 2021-01-13 16:14:27 -08:00 committed by GitHub
commit 663b972f44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
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])
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
@ -27,6 +31,10 @@ describe Utils 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, 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

View File

@ -7,7 +7,7 @@ module Utils
sig do
params(repo: T.any(String, Pathname), length: T.nilable(Integer), safe: T::Boolean).returns(T.nilable(String))
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?
repo = Pathname(repo).extend(GitRepositoryExtension)
@ -17,7 +17,7 @@ module Utils
sig do
params(repo: T.any(String, Pathname), length: T.nilable(Integer), safe: T::Boolean).returns(T.nilable(String))
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.git_short_head(length: length, safe: safe)
end