Class: RuboCop::ChangedFiles Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/changed_files.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Lists the files that differ from a git revision, for --changed.

Shelling out to git keeps RuboCop free of a version control dependency, and means the answer is exactly what git would give on the command line.

Constant Summary collapse

DEFAULT_REVISION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'HEAD'
FILESYSTEM_ENCODING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Encoding.find('filesystem')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(revision = nil) ⇒ ChangedFiles

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ChangedFiles.



25
26
27
# File 'lib/rubocop/changed_files.rb', line 25

def initialize(revision = nil)
  @revision = revision || DEFAULT_REVISION
end

Class Method Details

.revision?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Whether git can resolve name to a commit in the current repository.

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/rubocop/changed_files.rb', line 17

def self.revision?(name)
  _stdout, _stderr, status =
    Open3.capture3('git', 'rev-parse', '--verify', '--quiet', "#{name}^{commit}")
  status.success?
rescue Errno::ENOENT
  false
end

Instance Method Details

#filter(files) ⇒ Array<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the files among these that changed.

Returns:

  • (Array<String>) —

    the files among these that changed



42
43
44
45
# File 'lib/rubocop/changed_files.rb', line 42

def filter(files)
  changed = paths
  files.select { |file| changed.include?(file) }
end

#paths ⇒ Set<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Files that were added or modified since the revision, as absolute paths. Deleted files are left out - there is nothing left to inspect - and untracked files are included, since a file that is new to the working tree has changed as surely as one git already knows about.

Returns:



35
36
37
38
39
# File 'lib/rubocop/changed_files.rb', line 35

def paths
  root = repository_root

  (modified_paths + untracked_paths).to_set { |path| File.expand_path(path, root) }
end