Class: Rubycritic::Git

Inherits:
SourceControlSystem show all
Defined in:
lib/rubycritic/source_control_systems/git.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SourceControlSystem

create, register_system, system_names, systems

Class Method Details

.supported?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/rubycritic/source_control_systems/git.rb', line 6

def self.supported?
  `git branch 2>&1` && $?.success?
end

.to_sObject



10
11
12
# File 'lib/rubycritic/source_control_systems/git.rb', line 10

def self.to_s
  "Git"
end

Instance Method Details

#has_revision?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rubycritic/source_control_systems/git.rb', line 14

def has_revision?
  head_reference && $?.success?
end

#head_referenceObject



27
28
29
# File 'lib/rubycritic/source_control_systems/git.rb', line 27

def head_reference
  `git rev-parse --verify HEAD`.chomp
end

#travel_to_headObject



18
19
20
21
22
23
24
25
# File 'lib/rubycritic/source_control_systems/git.rb', line 18

def travel_to_head
  if uncommited_changes?
    stashed_changes = `git stash` && $?.success?
  end
  yield
ensure
  `git stash pop` if stashed_changes
end