Sha256: 78700bb4b6c441ba73a61f8eac5de160c2fffa7f68db89668bd95087d751689b

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'git/duet'
require 'git/duet/author_mapper'
require 'git/duet/command_methods'

class Git::Duet::SoloCommand
  include Git::Duet::CommandMethods

  def initialize(soloist, quiet = false, global = false)
    @soloist = soloist
    @quiet = !!quiet
    @global = !!global
    @author_mapper = Git::Duet::AuthorMapper.new
  end

  def execute!
    set_soloist_as_git_config_user
    unset_committer_vars
    report_env_vars
    write_env_vars
  end

  private
  attr_accessor :soloist, :author_mapper

  def set_soloist_as_git_config_user
    exec_check("git config #{@global ? '--global ' : ''}user.name '#{soloist_info[:name]}'")
    exec_check("git config #{@global ? '--global ' : ''}user.email '#{soloist_info[:email]}'")
  end

  def unset_committer_vars
    exec_check("git config #{@global ? '--global ' : ''}--unset-all duet.env.git-committer-name", [0, 5])
    exec_check("git config #{@global ? '--global ' : ''}--unset-all duet.env.git-committer-email", [0, 5])
  end

  def var_map
    {
      'GIT_AUTHOR_NAME' => soloist_info[:name],
      'GIT_AUTHOR_EMAIL' => soloist_info[:email]
    }
  end

  def soloist_info
    @soloist_info ||= author_mapper.map(@soloist).fetch(@soloist)
  rescue KeyError, IndexError => e
    error("git-solo: Failed to find author: #{e}")
    raise Git::Duet::ScriptDieError.new(86)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git-duet-0.1.3 lib/git/duet/solo_command.rb