class Artifact::Repo
Public Class Methods
new(full_path)
click to toggle source
# File lib/artifact.rb, line 151 def initialize(full_path) @root = full_path @git = Rugged::Repository.new(full_path) end
Public Instance Methods
exists?(path)
click to toggle source
# File lib/artifact.rb, line 187 def exists?(path) !!file_status(path) rescue false end
move(from, to, author)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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!()
click to toggle source
# 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
Private Instance Methods
file_status(file_path)
click to toggle source
# File lib/artifact.rb, line 208 def file_status(file_path) if s = @git.status(file_path).first return s.to_s.sub('worktree_', '') end end
modified?(file_path)
click to toggle source
# File lib/artifact.rb, line 204 def modified?(file_path) file_status(file_path) == 'modified' end
new_file?(file_path)
click to toggle source
# File lib/artifact.rb, line 200 def new_file?(file_path) file_status(file_path) == 'new' end
pull()
click to toggle source
# File lib/artifact.rb, line 232 def pull # updated = false code, out = nil, nil Dir.chdir(@root) do out = `git pull --rebase` code = $? # updated = out.strip != 'Current branch master is up to date.' # updated = res.strip != 'Already up-to-date.' end # updated return code, out end
push()
click to toggle source
# File lib/artifact.rb, line 245 def push Artifact.run_hook(:before_push) # updated = false code, out = nil, nil Dir.chdir(@root) do out = `git push` code = $? # updated = out.strip != 'Everything up-to-date' end Artifact.run_hook(:after_push) # updated return code, out end
write_commit(message, author)
click to toggle source
the author signature is a Hash containing :name, :email of the author and :time of the change.
# File lib/artifact.rb, line 216 def write_commit(message, author) Artifact.run_hook(:before_commit, message) author[:time] = Time.now commit_sha = Rugged::Commit.create(@git, :author => author, :message => message, :committer => author, :parents => @git.empty? ? [] : [ @git.head.target ].compact, :tree => @git.index.write_tree, :update_ref => 'HEAD' ) Artifact.run_hook(:after_commit, message) end