未验证 提交 663b972f 编辑于 作者: Seeker's avatar Seeker 提交者: GitHub
浏览文件

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

utils/git_repository: use `Pathname.pwd` if no `repo` specified
......@@ -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
......@@ -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
......
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册