Module: Perfer::Git

Defined in:
lib/perfer/git.rb

Class Method Summary collapse

Class Method Details

.current_branchObject



16
17
18
19
20
# File 'lib/perfer/git.rb', line 16

def current_branch
  branch = git 'symbolic-ref --quiet HEAD'
  branch = branch[/[^\/]+$/] if branch
  branch
end

.current_commitObject



22
23
24
# File 'lib/perfer/git.rb', line 22

def current_commit
  git 'rev-parse --quiet --verify HEAD'
end

.git(command) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/perfer/git.rb', line 4

def git(command)
  output = `git #{command}`
  output.chomp!
  return nil if output.empty?
  return false if $?.exitstatus != 0
  output
end

.goto_commit(commit) ⇒ Object

Raises:



30
31
32
33
# File 'lib/perfer/git.rb', line 30

def goto_commit(commit)
  raise Error, Errors::WORKING_DIR_DIRTY unless working_directory_clean?
  git "reset --quiet --hard #{commit}"
end

.repository?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/perfer/git.rb', line 12

def repository?
  git "rev-parse --git-dir 2>#{File::NULL}"
end

.working_directory_clean?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/perfer/git.rb', line 26

def working_directory_clean?
  git('status --porcelain --untracked-files=no') == nil
end