module Rake::Jekyll::GitDeployTask::GitCommands

@private Functions that wraps calls to git command.

Public Instance Methods

any_changes?() click to toggle source
# File lib/rake-jekyll/git_deploy_task.rb, line 15
def any_changes?
  ! `git status --porcelain`.empty?
end
checkout_remote_branch(name) click to toggle source
# File lib/rake-jekyll/git_deploy_task.rb, line 23
def checkout_remote_branch(name)
  sh "git checkout --track #{name}"
end
clone_repo(url) click to toggle source
# File lib/rake-jekyll/git_deploy_task.rb, line 19
def clone_repo(url)
  sh "git clone '#{url}' ."
end
commit_all(message, author = '', date = '') click to toggle source
# File lib/rake-jekyll/git_deploy_task.rb, line 27
def commit_all(message, author = '', date = '')
  opts = [ "--message='#{message}'" ]
  opts << "--author='#{author}'" unless author.empty?
  opts << "--date='#{date}'" unless date.empty?

  sh "git add --all && git commit #{opts.join(' ')}"
end
config_set?(key) click to toggle source
# File lib/rake-jekyll/git_deploy_task.rb, line 35
def config_set?(key)
  ! `git config --get #{key}`.empty?
end
config_user_set(name_email) click to toggle source
# File lib/rake-jekyll/git_deploy_task.rb, line 39
def config_user_set(name_email)
  name, email = parse_name_email(name_email)
  sh "git config --local user.name '#{name}'"
  sh "git config --local user.email '#{email}'"
end
create_orphan_branch(name) click to toggle source
# File lib/rake-jekyll/git_deploy_task.rb, line 45
def create_orphan_branch(name)
  sh "git checkout --orphan #{name}"
  sh 'git rm -rf . &>/dev/null || true'
end
current_branch() click to toggle source

@return [String] name of the current active branch.

# File lib/rake-jekyll/git_deploy_task.rb, line 51
def current_branch
  `git symbolic-ref --short -q HEAD`.strip
end
push(remote_url, branch) click to toggle source
# File lib/rake-jekyll/git_deploy_task.rb, line 55
def push(remote_url, branch)
  sh "git push -q #{remote_url} #{branch}:#{branch}"
end
sh(*cmd, &block) click to toggle source

Runs the system command cmd using Rake.sh, but filters sensitive data (userinfo part of URIs) in the output message.

# File lib/rake-jekyll/git_deploy_task.rb, line 62
def sh(*cmd, &block)
  Rake.rake_output_message(filter_sensitive_data(cmd.join(' '))) if verbose
  verbose false do
    Rake.sh(*cmd, &block)
  end
end

Private Instance Methods

filter_sensitive_data(str) click to toggle source
# File lib/rake-jekyll/git_deploy_task.rb, line 79
def filter_sensitive_data(str)
  URI.extract(str).each_with_object(str.dup) do |uri, s|
    filtered = URI.parse(uri).tap { |u| u.userinfo &&= '***:***' }.to_s
    s.gsub!(uri, filtered)
  end
end
parse_name_email(str) click to toggle source
# File lib/rake-jekyll/git_deploy_task.rb, line 71
def parse_name_email(str)
  if matched = str.match(/^([^<]*)(?:<([^>]*)>)?$/)
    matched[1..2].map do |val|
      val.strip.empty? ? nil : val.strip if val
    end
  end
end