Class: MultiRepo::TrackingFiles
- Inherits:
-
Object
- Object
- MultiRepo::TrackingFiles
- Defined in:
- lib/multirepo/files/tracking-files.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
Instance Method Summary collapse
- #commit(message) ⇒ Object
- #delete ⇒ Object
- #ensure_tool_not_outdated ⇒ Object
- #files_pathspec ⇒ Object
-
#initialize(path) ⇒ TrackingFiles
constructor
A new instance of TrackingFiles.
- #stage ⇒ Object
- #update ⇒ Object
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 = MetaFile.new(path) @lock_file = LockFile.new(path) @files = [, @lock_file] end |
Instance Attribute Details
#files ⇒ Object
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() 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 |
#delete ⇒ Object
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_outdated ⇒ Object
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 !.exists? = "Can't update tracking files with an outdated version of git-multirepo." current_version = MultiRepo::VERSION = .load.version outdated_tool = !VersionComparer.is_latest(current: current_version, last: ) = + " Current version is #{current_version} and repo is tracked by #{meta_version}" fail MultiRepoException, if outdated_tool end |
#files_pathspec ⇒ Object
60 61 62 |
# File 'lib/multirepo/files/tracking-files.rb', line 60 def files_pathspec files.map{ |f| File.basename(f.file) }.join(" ") end |
#stage ⇒ Object
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 |
#update ⇒ Object
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 |