Class: Repository::Inspector

Inherits:
Object
  • Object
show all
Defined in:
lib/repository/inspector.rb

Instance Method Summary collapse

Constructor Details

#initialize(repository) ⇒ Inspector

Returns a new instance of Inspector.



4
5
6
# File 'lib/repository/inspector.rb', line 4

def initialize(repository)
  @repo = repository
end

Instance Method Details

#compare_index_to_workspace(entry, stat) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/repository/inspector.rb', line 23

def compare_index_to_workspace(entry, stat)
  return :untracked unless entry
  return :deleted unless stat
  return :modified unless entry.stat_match?(stat)
  return nil if entry.times_match?(stat)

  data = @repo.workspace.read_file(entry.path)
  blob = Database::Blob.new(data)
  oid  = @repo.database.hash_object(blob)

  unless entry.oid == oid
    :modified
  end
end

#compare_tree_to_index(item, entry) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/repository/inspector.rb', line 38

def compare_tree_to_index(item, entry)
  return nil unless item or entry
  return :added unless item
  return :deleted unless entry

  unless entry.mode == item.mode and entry.oid == item.oid
    :modified
  end
end

#trackable_file?(path, stat) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/repository/inspector.rb', line 8

def trackable_file?(path, stat)
  return false unless stat

  return !@repo.index.tracked_file?(path) if stat.file?
  return false unless stat.directory?

  items = @repo.workspace.list_dir(path)
  files = items.select { |_, item_stat| item_stat.file? }
  dirs  = items.select { |_, item_stat| item_stat.directory? }

  [files, dirs].any? do |list|
    list.any? { |item_path, item_stat| trackable_file?(item_path, item_stat) }
  end
end