class Rebuild::Repository
Public Class Methods
new(path, options)
click to toggle source
# File lib/rebuild/repository.rb, line 6 def initialize(path, options) @user, @repo = path.split('/') @directory = options[:directory] @update = options[:update] abort "Invalid repository `#{path}`" if @repo.nil? end
Public Instance Methods
fetch()
click to toggle source
# File lib/rebuild/repository.rb, line 14 def fetch if File.exists?(repo_path) sync_repository else clone_repository end repo_path end
Private Instance Methods
clone_repository()
click to toggle source
# File lib/rebuild/repository.rb, line 26 def clone_repository Logger.info("Create repository to #{repo_path}...") FileUtils.mkdir_p(upper_directory) `git clone #{github_repository} #{repo_path}` end
default_directory()
click to toggle source
# File lib/rebuild/repository.rb, line 69 def default_directory File.expand_path('~') end
dirty_repository?()
click to toggle source
# File lib/rebuild/repository.rb, line 42 def dirty_repository? run_with_repository('[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]') end
github_repository()
click to toggle source
# File lib/rebuild/repository.rb, line 53 def github_repository "https://github.com/#{@user}/#{@repo}" end
repo_path()
click to toggle source
# File lib/rebuild/repository.rb, line 57 def repo_path if @directory File.expand_path(@directory) else File.join(default_directory, @repo) end end
run_with_repository(script)
click to toggle source
# File lib/rebuild/repository.rb, line 46 def run_with_repository(script) system(<<-EOS) cd #{repo_path} #{script} EOS end
sync_repository()
click to toggle source
# File lib/rebuild/repository.rb, line 32 def sync_repository return unless @update if dirty_repository? puts 'Repository has unstaged changes. Sync skipped.' else run_with_repository('git pull origin master') end end
upper_directory()
click to toggle source
# File lib/rebuild/repository.rb, line 65 def upper_directory repo_path.gsub(/[^\/]+\/?$/, '') end