Class: Artifact::Repo
- Inherits:
-
Object
- Object
- Artifact::Repo
- Defined in:
- lib/artifact.rb
Defined Under Namespace
Classes: SyncError
Instance Method Summary collapse
- #exists?(path) ⇒ Boolean
-
#initialize(full_path) ⇒ Repo
constructor
A new instance of Repo.
- #move(from, to, author) ⇒ Object
- #remove(path, author) ⇒ Object
- #save(path, author, check = true) ⇒ Object
- #sync! ⇒ Object
Constructor Details
#initialize(full_path) ⇒ Repo
Returns a new instance of Repo.
152 153 154 155 |
# File 'lib/artifact.rb', line 152 def initialize(full_path) @root = full_path @git = Rugged::Repository.new(full_path) end |
Instance Method Details
#exists?(path) ⇒ Boolean
188 189 190 |
# File 'lib/artifact.rb', line 188 def exists?(path) !!file_status(path) rescue false end |
#move(from, to, author) ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/artifact.rb', line 172 def move(from, to, ) Artifact.ensure_dir!(Artifact.full_path(to)) FileUtils.mv(Artifact.full_path(from), Artifact.full_path(to)) @git.index.remove(from) @git.index.add(to) @git.index.write write_commit("Moved #{from} --> #{to}", ) end |
#remove(path, author) ⇒ Object
182 183 184 185 186 |
# File 'lib/artifact.rb', line 182 def remove(path, ) @git.index.remove(path) @git.index.write write_commit("Removed #{path}", ) end |
#save(path, author, check = true) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/artifact.rb', line 157 def save(path, , check = true) # index.add expects a clean path, without any leading ./ # so make sure we're passing a clean pathname path = path.sub(/^\.\//, '') if check && !new_file?(path) && !modified?(path) raise "No changes in file: #{path}" end # puts "Adding to index: #{path}" @git.index.add(path) @git.index.write write_commit("Saved #{path}", ) end |
#sync! ⇒ Object
192 193 194 195 196 197 |
# File 'lib/artifact.rb', line 192 def sync! code, out = pull raise SyncError.new("Error when pulling changes: #{out.strip}") unless code == 0 code, out = push raise SyncError.new("Error when pushing changes: #{out.strip}") unless code == 0 end |