class Done::GitRepo

Attributes

git_url[R]
log_dir[R]
log_file[R]

Public Class Methods

new(git_url, log_dir, log_file) click to toggle source
# File lib/done_log/git_repo.rb, line 9
def initialize git_url, log_dir, log_file
  @git_url = git_url
  @log_dir = log_dir
  @log_file = log_file
end

Public Instance Methods

add() click to toggle source
# File lib/done_log/git_repo.rb, line 15
def add
  unless File.empty? log_file
    run "git add #{log_file}"
  end
end
commit() click to toggle source
# File lib/done_log/git_repo.rb, line 21
def commit
  unless run "git diff --no-patch --cached --exit-code" # Check if there are any changes
    unless run "git commit #{log_file} -m 'Update #{File.basename log_file}'"
      raise 'Could not commit update to git'
    end
  end
end
has_remote?() click to toggle source
# File lib/done_log/git_repo.rb, line 29
def has_remote?
  run "git remote -v | grep -q -F #{git_url.inspect}"
end
init() click to toggle source
# File lib/done_log/git_repo.rb, line 33
def init
  unless Dir.exist? File.join(log_dir, ".git")
    if git_url
      run "git clone -q #{git_url} #{log_dir}"
    else
      run "git init -q #{log_dir}"
    end
  end
end
pull() click to toggle source
# File lib/done_log/git_repo.rb, line 43
def pull
  return unless git_url
  return unless has_remote?

  unless run 'git pull -q'
    raise 'Could not pull from git'
  end
end
push() click to toggle source
# File lib/done_log/git_repo.rb, line 52
def push
  return unless git_url
  return unless has_remote?

  unless run 'git push'
    raise 'Could not push to git'
  end
end
run(cmd) click to toggle source
# File lib/done_log/git_repo.rb, line 61
def run cmd
  FileUtils.cd(log_dir) do
    system cmd
  end
end