Class: RubyCritic::SourceControlSystem::Git
- Inherits:
-
Base
- Object
- Base
- RubyCritic::SourceControlSystem::Git
show all
- Defined in:
- lib/rubycritic/source_control_systems/git.rb
Constant Summary
collapse
- GIT_EXECUTABLE =
TTY::Which.which('git')
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
connected_system_names, create, register_system, systems
Class Method Details
.git(arg) ⇒ Object
11
12
13
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 11
def self.git(arg)
`#{GIT_EXECUTABLE} #{arg}`
end
|
.supported? ⇒ Boolean
19
20
21
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 19
def self.supported?
git('branch 2>&1') && $?.success?
end
|
.to_s ⇒ Object
23
24
25
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 23
def self.to_s
'Git'
end
|
Instance Method Details
#date_of_last_commit(path) ⇒ Object
31
32
33
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 31
def date_of_last_commit(path)
git("log -1 --date=iso --format=%ad #{path.shellescape}").chomp!
end
|
#git(arg) ⇒ Object
15
16
17
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 15
def git(arg)
self.class.git(arg)
end
|
#head_reference ⇒ Object
39
40
41
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 39
def head_reference
git('rev-parse --verify HEAD').chomp!
end
|
#revision? ⇒ Boolean
35
36
37
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 35
def revision?
head_reference && $?.success?
end
|
#revisions_count(path) ⇒ Object
27
28
29
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 27
def revisions_count(path)
git("log --follow --format=%h #{path.shellescape}").count("\n")
end
|
#travel_to_head ⇒ Object
43
44
45
46
47
48
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 43
def travel_to_head
stash_successful = stash_changes
yield
ensure
travel_to_original_state if stash_successful
end
|