-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent git commands if project is not a git repo
Prior to this commit, git commands (such as the command to get `remote.origin.url`) would always be run if git was installed. This caused "fatal: not a git repository" to be printed to `stderr` when the project was not a git repository. This commit modifies `SDoc::Helpers::Git#git?` such that git commands will only be run if git is installed _and_ the project is a git repository.
- Loading branch information
1 parent
f2d2369
commit e7b7e50
Showing
2 changed files
with
28 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,29 @@ | |
@helpers.options = RDoc::Options.new | ||
end | ||
|
||
describe "#git?" do | ||
it "returns false when git is not installed" do | ||
with_env("PATH" => "") do | ||
_(@helpers.git?).must_equal false | ||
end | ||
end | ||
|
||
it "returns false when project is not a git repository" do | ||
Dir.mktmpdir do |dir| | ||
@helpers.options.root = dir | ||
|
||
_(@helpers.git?).must_equal false | ||
end | ||
end | ||
end | ||
|
||
describe "#github_url" do | ||
before :each do | ||
@helpers.options.github = true | ||
end | ||
|
||
it "returns the URL for a given path in the project's GitHub repository at the current SHA1" do | ||
@helpers.git_bin_path = "path/to/git" | ||
@helpers.git_repo_path = "path/to/repo" | ||
@helpers.git_origin_url = "[email protected]:user/repo.git" | ||
@helpers.git_head_sha1 = "1337c0d3" | ||
|
||
|
@@ -51,8 +67,8 @@ | |
_(@helpers.github_url("foo/bar/qux.rb")).must_be_nil | ||
end | ||
|
||
it "returns nil when git is not installed" do | ||
@helpers.git_bin_path = "" | ||
it "returns nil when git is not installed or project is not a git repository" do | ||
@helpers.git_repo_path = "" | ||
|
||
_(@helpers.github_url("foo/bar/qux.rb")).must_be_nil | ||
end | ||
|
@@ -306,7 +322,7 @@ module Foo; module Bar; module Qux; end; end; end | |
|
||
describe "#project_git_head" do | ||
it "returns the branch name and abbreviated SHA1 of the most recent commit in HEAD" do | ||
@helpers.git_bin_path = "path/to/git" | ||
@helpers.git_repo_path = "path/to/repo" | ||
@helpers.git_head_branch = "1-0-stable" | ||
@helpers.git_head_sha1 = "1337c0d3d00d" * 3 | ||
|
||
|
@@ -317,8 +333,8 @@ module Foo; module Bar; module Qux; end; end; end | |
_(@helpers.project_git_head).must_match %r"\A.+@[[:xdigit:]]{12}\z" | ||
end | ||
|
||
it "returns nil when git is not installed" do | ||
@helpers.git_bin_path = "" | ||
it "returns nil when git is not installed or project is not a git repository" do | ||
@helpers.git_repo_path = "" | ||
|
||
_(@helpers.project_git_head).must_be_nil | ||
end | ||
|
@@ -367,7 +383,7 @@ module Foo; module Bar; module Qux; end; end; end | |
|
||
describe "#og_modified_time" do | ||
it "returns the commit time of the most recent commit in HEAD" do | ||
@helpers.git_bin_path = "path/to/git" | ||
@helpers.git_repo_path = "path/to/repo" | ||
@helpers.git_head_timestamp = "1999-12-31T12:34:56Z" | ||
|
||
_(@helpers.og_modified_time).must_equal "1999-12-31T12:34:56Z" | ||
|
@@ -378,8 +394,8 @@ module Foo; module Bar; module Qux; end; end; end | |
must_match %r"\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[-+]\d{2}:\d{2}\z" | ||
end | ||
|
||
it "returns nil when git is not installed" do | ||
@helpers.git_bin_path = "" | ||
it "returns nil when git is not installed or project is not a git repository" do | ||
@helpers.git_repo_path = "" | ||
|
||
_(@helpers.og_modified_time).must_be_nil | ||
end | ||
|