Module: VagrantGitHooks::Util::Git
- Defined in:
- lib/vagrant-git-hooks/util/git.rb
Class Method Summary collapse
- .absolute?(path) ⇒ Boolean
- .available? ⇒ Boolean
- .capture(root, *args) ⇒ Object
- .hooks_dir(root) ⇒ Object
- .manifest_path(root) ⇒ Object
- .repo?(root) ⇒ Boolean
-
.resolve(root, name) ⇒ String?
Resolves a path under the repository's real hooks directory via
git rev-parse --git-path, rather than assuming.git/<name>, socore.hooksPathand worktrees are honored. - .toplevel(root) ⇒ Object
Class Method Details
.absolute?(path) ⇒ Boolean
60 61 62 |
# File 'lib/vagrant-git-hooks/util/git.rb', line 60 def absolute?(path) File.absolute_path?(path) end |
.available? ⇒ Boolean
11 12 13 14 15 16 17 |
# File 'lib/vagrant-git-hooks/util/git.rb', line 11 def available? Verbose.log("git", "--version") _out, _err, st = Open3.capture3("git", "--version") st.success? rescue StandardError false end |
.capture(root, *args) ⇒ Object
55 56 57 58 |
# File 'lib/vagrant-git-hooks/util/git.rb', line 55 def capture(root, *args) Verbose.log("git", "-C", root.to_s, *args) Open3.capture3("git", "-C", root.to_s, *args) end |
.hooks_dir(root) ⇒ Object
29 30 31 |
# File 'lib/vagrant-git-hooks/util/git.rb', line 29 def hooks_dir(root) resolve(root, "hooks") || File.join(toplevel(root) || root.to_s, ".git", "hooks") end |
.manifest_path(root) ⇒ Object
33 34 35 36 |
# File 'lib/vagrant-git-hooks/util/git.rb', line 33 def manifest_path(root) resolve(root, "vagrant-git-hooks.json") || File.join(toplevel(root) || root.to_s, ".git", "vagrant-git-hooks.json") end |
.repo?(root) ⇒ Boolean
19 20 21 22 |
# File 'lib/vagrant-git-hooks/util/git.rb', line 19 def repo?(root) out, _err, st = capture(root, "rev-parse", "--is-inside-work-tree") st.success? && out.strip == "true" end |
.resolve(root, name) ⇒ String?
Resolves a path under the repository's real hooks directory via
git rev-parse --git-path, rather than assuming .git/<name>, so
core.hooksPath and worktrees are honored.
45 46 47 48 49 50 51 52 53 |
# File 'lib/vagrant-git-hooks/util/git.rb', line 45 def resolve(root, name) out, _err, st = capture(root, "rev-parse", "--git-path", name) return nil unless st.success? path = out.strip return nil if path.empty? absolute?(path) ? path : File.(path, root.to_s) end |