class Bookwatch::Ingest::GitAccessor
Constants
- InvalidTagRef
- TagExists
Public Instance Methods
clone(url, name, path: nil, checkout: 'master')
click to toggle source
# File lib/bookwatch/ingest/git_accessor.rb, line 14 def clone(url, name, path: nil, checkout: 'master') cached_clone(url, name, Pathname(path)).tap do |git| git.checkout(checkout) end end
remote_tag(url, tagname, commit_or_object)
click to toggle source
# File lib/bookwatch/ingest/git_accessor.rb, line 34 def remote_tag(url, tagname, commit_or_object) Dir.mktmpdir do |dir| path = Pathname(dir) git = cached_clone(url, temp_name("tag"), path) git.config('user.name', 'Bookwatch') git.config('user.email', 'bookwatch@cloudfoundry.org') begin git.add_tag(tagname, "origin/#{commit_or_object}", message: 'Tagged by Bookwatch') rescue Git::GitExecuteError => e case e.message when /already exists/ raise TagExists when /as a valid ref/ raise InvalidTagRef else raise end end git.push("origin", "master", tags: true) end end
update(cloned_path)
click to toggle source
# File lib/bookwatch/ingest/git_accessor.rb, line 20 def update(cloned_path) Git.open(cloned_path).pull Ingest::UpdateSuccess.new rescue ArgumentError, Git::GitExecuteError => e case e.message when /overwritten by merge/ Ingest::UpdateFailure.new('merge error') when /path does not exist/ Ingest::UpdateFailure.new('not found') else raise end end
Private Instance Methods
cached_clone(url, name, path)
click to toggle source
# File lib/bookwatch/ingest/git_accessor.rb, line 92 def cached_clone(url, name, path) dest_dir = path.join(name) if dest_dir.exist? Git.open(dest_dir) else Git.clone(url, name, path: path, recursive: true) end end
temp_name(purpose)
click to toggle source
# File lib/bookwatch/ingest/git_accessor.rb, line 88 def temp_name(purpose) "bookwatch-git-accessor-#{purpose}" end