Class: HookSpec::GitEnv

Inherits:
Object
  • Object
show all
Defined in:
lib/hookspec/git_env.rb

Constant Summary collapse

AGAINST =

an empty tree object hash

'4b825dc642cb6eb9a060e54bf8d69288fbee4904'

Instance Method Summary collapse

Constructor Details

#initializeGitEnv

Returns a new instance of GitEnv.



6
7
# File 'lib/hookspec/git_env.rb', line 6

def initialize
end

Instance Method Details

#conf_of(conf_name) ⇒ Object

git confs



31
32
33
# File 'lib/hookspec/git_env.rb', line 31

def conf_of conf_name
  `git config #{conf_name}`.chomp
end

#current_branchObject



9
10
11
# File 'lib/hookspec/git_env.rb', line 9

def current_branch
  `git rev-parse --abbrev-ref HEAD`.chomp
end

#diff(model: nil, filter: nil) ⇒ Object

git diff –cached –name-only –diff-filter=



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hookspec/git_env.rb', line 18

def diff model: nil, filter: nil
  cmd = 'git diff '
  if !model.nil? && model.downcase == 'cached'
    cmd = cmd + '--cached '
  end
  cmd = cmd + '--name-only '
  if !filter.nil?
    cmd = cmd + '--diff-filter=' + filter
  end
  `#{cmd}`.chomp.split
end

#exec(cmd) ⇒ Object



41
42
43
# File 'lib/hookspec/git_env.rb', line 41

def exec cmd
  `#{cmd}`.chomp
end

#filesObject



13
14
15
# File 'lib/hookspec/git_env.rb', line 13

def files
  `git ls-files`.chomp.split
end

#white_spacesObject



35
36
37
38
39
# File 'lib/hookspec/git_env.rb', line 35

def white_spaces
  against = get_against

  `git diff-index --check --cached #{against} --`.chomp
end