Class: Rubycritic::SourceControlSystem::Git

Inherits:
Base
  • Object
show all
Defined in:
lib/rubycritic/source_control_systems/git.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connected_system_names, create, register_system, 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

#date_of_last_commit(path) ⇒ Object



18
19
20
# File 'lib/rubycritic/source_control_systems/git.rb', line 18

def date_of_last_commit(path)
  `git log -1 --date=iso --format=%ad #{path.shellescape}`.chomp!
end

#head_referenceObject



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

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

#revision?Boolean

Returns:

  • (Boolean)


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

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

#revisions_count(path) ⇒ Object



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

def revisions_count(path)
  `git log --follow --format=%h #{path.shellescape}`.count("\n")
end

#travel_to_headObject



30
31
32
33
34
35
# File 'lib/rubycritic/source_control_systems/git.rb', line 30

def travel_to_head
  stash_successful = stash_changes
  yield
ensure
  travel_to_original_state if stash_successful
end