Method: Git::Lib#ls_files

Defined in:
lib/git/lib.rb

#ls_files(location = nil) ⇒ Hash<String, Hash>

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.

List all files that are in the index

Parameters:

  • location (String) (defaults to: nil)

    the location to list the files from

Returns:

  • (Hash<String, Hash>)

    a hash of files in the index

    • key: file [String] the file path
    • value: file_info [Hash] the file information containing the following keys:
      • :path [String] the file path
      • :mode_index [String] the file mode
      • :sha_index [String] the file sha
      • :stage [String] the file stage


974
975
976
977
978
979
980
981
982
983
984
985
# File 'lib/git/lib.rb', line 974

def ls_files(location = nil)
  location ||= '.'
  {}.tap do |files|
    command_lines('ls-files', '--stage', location).each do |line|
      (info, file) = split_status_line(line)
      (mode, sha, stage) = info.split
      files[file] = {
        path: file, mode_index: mode, sha_index: sha, stage: stage
      }
    end
  end
end