Class: MultiRepo::TrackingFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/multirepo/files/tracking-files.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ TrackingFiles

Returns a new instance of TrackingFiles.



11
12
13
14
15
16
# File 'lib/multirepo/files/tracking-files.rb', line 11

def initialize(path)
  @path = path
  @meta_file = MetaFile.new(path)
  @lock_file = LockFile.new(path)
  @files = [@meta_file, @lock_file]
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



9
10
11
# File 'lib/multirepo/files/tracking-files.rb', line 9

def files
  @files
end

Instance Method Details

#commit(message) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/multirepo/files/tracking-files.rb', line 41

def commit(message)
  stage
  
  output = GitRunner.run(@path, "ls-files --modified --others -- #{files_pathspec}", Verbosity::OUTPUT_NEVER)
  files_are_untracked_or_modified = output.strip != ""
  
  output = GitRunner.run(@path, "diff --name-only --cached -- #{files_pathspec}", Verbosity::OUTPUT_NEVER)
  files_are_staged = output.strip != ""
  
  must_commit = files_are_untracked_or_modified || files_are_staged
  GitRunner.run(@path, "commit --no-verify -m \"#{message}\" --only -- #{files_pathspec}", Verbosity::OUTPUT_ON_ERROR) if must_commit
  
  return must_commit
end

#deleteObject



56
57
58
# File 'lib/multirepo/files/tracking-files.rb', line 56

def delete
  files.each { |f| FileUtils.rm_f(f.file) }
end

#ensure_tool_not_outdatedObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/multirepo/files/tracking-files.rb', line 25

def ensure_tool_not_outdated
  return if !@meta_file.exists?

  base_message = "Can't update tracking files with an outdated version of git-multirepo."
  current_version = MultiRepo::VERSION
  meta_version = @meta_file.load.version
  outdated_tool = !VersionComparer.is_latest(current: current_version, last: meta_version)
  message = base_message + " Current version is #{current_version} and repo is tracked by #{meta_version}"
  
  fail MultiRepoException, message if outdated_tool
end

#files_pathspecObject



60
61
62
# File 'lib/multirepo/files/tracking-files.rb', line 60

def files_pathspec
  files.map{ |f| File.basename(f.file) }.join(" ")
end

#stageObject



37
38
39
# File 'lib/multirepo/files/tracking-files.rb', line 37

def stage
  GitRunner.run(@path, "add --force -- #{files_pathspec}", Verbosity::OUTPUT_ON_ERROR)
end

#updateObject



18
19
20
21
22
23
# File 'lib/multirepo/files/tracking-files.rb', line 18

def update
  ensure_tool_not_outdated
  updated = false
  files.each { |f| updated |= f.update }
  return updated
end