Sha256: fd4ab4df085fb4db718ddb0571299152400641df8b554aad02343055c3e9d827

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

# vim:fileencoding=utf-8
require 'git/duet'
require 'git/duet/author_mapper'
require 'git/duet/command_methods'

module Git
  module Duet
    class 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!
        unset_committer_vars
        if soloist
          set_soloist_as_git_config_user
          report_env_vars
          write_env_vars
        else
          show_current_config
        end
      end

      private

      attr_accessor :soloist, :author_mapper

      def set_soloist_as_git_config_user
        exec_check("#{git_config} user.name '#{soloist_info[:name]}'")
        exec_check("#{git_config} user.email '#{soloist_info[:email]}'")
      end

      def unset_committer_vars
        exec_check(
          "#{git_config} --unset-all #{Git::Duet::Config.namespace}." \
          'git-committer-name',
          [0, 5]
        )
        exec_check(
          "#{git_config} --unset-all #{Git::Duet::Config.namespace}." \
          '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, 86
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
git-duet-0.5.1 lib/git/duet/solo_command.rb
git-duet-0.5.0 lib/git/duet/solo_command.rb
git-duet-0.4.1 lib/git/duet/solo_command.rb
git-duet-0.4.0 lib/git/duet/solo_command.rb