Class: RubyCritic::SourceControlSystem::Git
- Inherits:
-
Base
- Object
- Base
- RubyCritic::SourceControlSystem::Git
show all
- Defined in:
- lib/rubycritic/source_control_systems/git.rb,
lib/rubycritic/source_control_systems/git/churn.rb
Defined Under Namespace
Classes: Churn, Renames, Stats
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
.check_git_repository?(path) ⇒ Boolean
:reek:DuplicateMethodCall
38
39
40
41
42
43
44
45
46
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 38
def self.check_git_repository?(path)
current_path = File.expand_path(path)
while current_path != File.dirname(current_path)
return true if Dir.exist?(File.join(current_path, '.git'))
current_path = File.dirname(current_path)
end
false
end
|
.current_branch ⇒ Object
102
103
104
105
106
107
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 102
def self.current_branch
branch_list = `git branch`
branch = branch_list.match(/\*.*$/)[0].gsub('* ', '')
branch = branch.gsub(/\(HEAD detached at (.*)\)$/, '\1') if /\(HEAD detached at (.*)\)$/.match?(branch)
branch
end
|
.git(arg) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 12
def self.git(arg)
if Gem.win_platform?
`\"#{GIT_EXECUTABLE}\" #{arg}`
else
`#{GIT_EXECUTABLE} #{arg}`
end
end
|
.modified_files ⇒ Object
92
93
94
95
96
97
98
99
100
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 92
def self.modified_files
modified_files = `git diff --name-status #{Config.base_branch} #{Config.feature_branch}`
modified_files.split("\n").filter_map do |line|
next if line.start_with?('D')
file_name = line.split("\t")[1]
file_name
end
end
|
.supported? ⇒ Boolean
:reek:DuplicateMethodCall :reek:NilCheck
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 26
def self.supported?
return true if git('branch 2>&1') && $CHILD_STATUS.success?
return false if Config.paths.nil? || Config.paths.empty?
Config.paths.any? do |path|
absolute_path = File.expand_path(path)
check_git_repository?(absolute_path)
end
end
|
.switch_branch(branch) ⇒ Object
79
80
81
82
83
84
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 79
def self.switch_branch(branch)
dirty = !uncommitted_changes.empty?
abort("Uncommitted changes are present: #{uncommitted_changes}") if dirty
git("checkout #{branch}")
end
|
.to_s ⇒ Object
48
49
50
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 48
def self.to_s
'Git'
end
|
.uncommitted_changes ⇒ Object
86
87
88
89
90
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 86
def self.uncommitted_changes
return @uncommitted_changes if defined? @uncommitted_changes
@uncommitted_changes = git('diff-index HEAD --').chomp! || ''
end
|
Instance Method Details
#churn ⇒ Object
52
53
54
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 52
def churn
@churn ||= Churn.new(churn_after: Config.churn_after, paths: Config.paths)
end
|
#date_of_last_commit(path) ⇒ Object
60
61
62
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 60
def date_of_last_commit(path)
churn.date_of_last_commit(path)
end
|
#git(arg) ⇒ Object
20
21
22
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 20
def git(arg)
self.class.git(arg)
end
|
#head_reference ⇒ Object
68
69
70
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 68
def head_reference
git('rev-parse --verify HEAD').chomp!
end
|
#revision? ⇒ Boolean
64
65
66
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 64
def revision?
head_reference && $CHILD_STATUS.success?
end
|
#revisions_count(path) ⇒ Object
56
57
58
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 56
def revisions_count(path)
churn.revisions_count(path)
end
|
#travel_to_head ⇒ Object
72
73
74
75
76
77
|
# File 'lib/rubycritic/source_control_systems/git.rb', line 72
def travel_to_head
stash_successful = stash_changes?
yield
ensure
travel_to_original_state if stash_successful
end
|