Module: Licensed::Git
- Defined in:
- lib/licensed/git.rb
Class Method Summary collapse
-
.available? ⇒ Boolean
Returns whether git commands are available.
-
.commit_date(sha) ⇒ Object
Returns the commit date for the provided SHA as a timestamp.
-
.files ⇒ Object
Returns the files in the git repository from ‘git ls-files –recurse-submodules`.
-
.git_repo? ⇒ Boolean
Returns true if a git repository is found, false otherwise.
-
.repository_root ⇒ Object
Returns the root of the current git repository or nil if not in a git repository.
-
.version(descriptor) ⇒ Object
Returns the most recent git SHA for a file or directory or nil if SHA is not available.
Class Method Details
.available? ⇒ Boolean
Returns whether git commands are available
6 7 8 |
# File 'lib/licensed/git.rb', line 6 def available? @git ||= Licensed::Shell.tool_available?("git") end |
.commit_date(sha) ⇒ Object
Returns the commit date for the provided SHA as a timestamp
sha - commit sha to retrieve date
34 35 36 37 |
# File 'lib/licensed/git.rb', line 34 def commit_date(sha) return unless git_repo? && sha Licensed::Shell.execute("git", "show", "-s", "-1", "--format=%ct", sha) end |
.files ⇒ Object
Returns the files in the git repository from ‘git ls-files –recurse-submodules`
40 41 42 43 44 |
# File 'lib/licensed/git.rb', line 40 def files return unless git_repo? output = Licensed::Shell.execute("git", "ls-files", "--full-name", "--recurse-submodules") output.lines.map(&:strip) end |
.git_repo? ⇒ Boolean
Returns true if a git repository is found, false otherwise
18 19 20 |
# File 'lib/licensed/git.rb', line 18 def git_repo? !repository_root.to_s.empty? end |
.repository_root ⇒ Object
Returns the root of the current git repository or nil if not in a git repository.
12 13 14 15 |
# File 'lib/licensed/git.rb', line 12 def repository_root return unless available? Licensed::Shell.execute("git", "rev-parse", "--show-toplevel", allow_failure: true) end |
.version(descriptor) ⇒ Object
Returns the most recent git SHA for a file or directory or nil if SHA is not available
descriptor - file or directory to retrieve latest SHA for
26 27 28 29 |
# File 'lib/licensed/git.rb', line 26 def version(descriptor) return unless git_repo? && descriptor Licensed::Shell.execute("git", "rev-list", "-1", "HEAD", "--", descriptor, allow_failure: true) end |