Class: Artifact::Repo

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

Defined Under Namespace

Classes: SyncError

Instance Method Summary collapse

Constructor Details

#initialize(full_path) ⇒ Repo

Returns a new instance of Repo.



151
152
153
154
# File 'lib/artifact.rb', line 151

def initialize(full_path)
  @root = full_path
  @git = Rugged::Repository.new(full_path)
end

Instance Method Details

#exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/artifact.rb', line 187

def exists?(path)
  !!file_status(path) rescue false
end

#move(from, to, author) ⇒ Object



171
172
173
174
175
176
177
178
179
# File 'lib/artifact.rb', line 171

def move(from, to, author)
  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}", author)
end

#remove(path, author) ⇒ Object



181
182
183
184
185
# File 'lib/artifact.rb', line 181

def remove(path, author)
  @git.index.remove(path)
  @git.index.write
  write_commit("Removed #{path}", author)
end

#save(path, author, check = true) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/artifact.rb', line 156

def save(path, author, 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}", author)
end

#sync!Object

Raises:



191
192
193
194
195
196
# File 'lib/artifact.rb', line 191

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