Class: Giturl::GitDirectory
- Inherits:
-
Object
- Object
- Giturl::GitDirectory
- Defined in:
- lib/giturl/git_directory.rb
Overview
A directory on disk, asked about through git: whether git manages it, and what GitHub page shows it. Every git invocation in giturl happens here.
Constant Summary collapse
- FAILURE =
'Git commands failed. Please check if the directory is a git repository.'
Instance Method Summary collapse
-
#initialize(path) ⇒ GitDirectory
constructor
A new instance of GitDirectory.
-
#managed? ⇒ Boolean
git prints to stderr when the path is not a repository, which is noise for a question that is allowed to answer "no", so stderr is silenced around it.
-
#url ⇒ String
The GitHub page URL for this directory, or '' (after a warning) when git could not answer.
Constructor Details
#initialize(path) ⇒ GitDirectory
Returns a new instance of GitDirectory.
12 13 14 |
# File 'lib/giturl/git_directory.rb', line 12 def initialize(path) @path = path end |
Instance Method Details
#managed? ⇒ Boolean
git prints to stderr when the path is not a repository, which is noise for a question that is allowed to answer "no", so stderr is silenced around it.
20 21 22 23 24 25 26 27 |
# File 'lib/giturl/git_directory.rb', line 20 def managed? stderr_old = $stderr.dup $stderr.reopen(File::NULL) inside, = capture('rev-parse', '--is-inside-work-tree') $stderr.flush $stderr.reopen stderr_old inside == 'true' end |
#url ⇒ String
Returns the GitHub page URL for this directory, or '' (after a warning) when git could not answer.
31 32 33 34 35 36 37 38 39 |
# File 'lib/giturl/git_directory.rb', line 31 def url here = location unless here warn FAILURE return '' end "#{RemoteUrl.new(here.remote).https}/tree/#{here.encoded_branch}/#{here.prefix}" end |