Module: VagrantGitHooks::Util::Git

Defined in:
lib/vagrant-git-hooks/util/git.rb

Class Method Summary collapse

Class Method Details

.absolute?(path) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/vagrant-git-hooks/util/git.rb', line 53

def absolute?(path)
  File.absolute_path?(path)
end

.available?Boolean

Returns:

  • (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



48
49
50
51
# File 'lib/vagrant-git-hooks/util/git.rb', line 48

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

Returns:

  • (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) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/vagrant-git-hooks/util/git.rb', line 38

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.expand_path(path, root.to_s)
end

.toplevel(root) ⇒ Object



24
25
26
27
# File 'lib/vagrant-git-hooks/util/git.rb', line 24

def toplevel(root)
  out, _err, st = capture(root, "rev-parse", "--show-toplevel")
  st.success? && !out.strip.empty? ? out.strip : nil
end