module Git::Duet::CommandMethods
Private Instance Methods
check_env_var_config_key(config_key)
click to toggle source
# File lib/git/duet/command_methods.rb, line 74 def check_env_var_config_key(config_key) exec_check( "git config #{Git::Duet::Config.namespace}.#{config_key}" ).chomp end
current_config_command()
click to toggle source
# File lib/git/duet/command_methods.rb, line 47 def current_config_command "git config --get-regexp #{Git::Duet::Config.namespace}" end
dump_env_vars()
click to toggle source
# File lib/git/duet/command_methods.rb, line 55 def dump_env_vars extract_env_vars_from_git_config.each do |k, v| puts "#{k}='#{v}'" end end
error(msg)
click to toggle source
# File lib/git/duet/command_methods.rb, line 127 def error(msg) $stderr.puts(msg) unless quiet? end
exec_check(command, okay_statuses = [0].freeze)
click to toggle source
# File lib/git/duet/command_methods.rb, line 94 def exec_check(command, okay_statuses = [0].freeze) output = `#{command}` unless okay_statuses.include?($CHILD_STATUS.exitstatus) error("Command #{command.inspect} exited with #{$CHILD_STATUS.to_i}") fail Git::Duet::ScriptDieError, 1 end output end
exec_git_commit()
click to toggle source
# File lib/git/duet/command_methods.rb, line 80 def exec_git_commit if author_env_vars_set? exec 'git commit ' << signoff_arg << quoted_passthrough_args else fail Git::Duet::ScriptDieError, 17 end end
extract_env_vars_from_git_config()
click to toggle source
# File lib/git/duet/command_methods.rb, line 61 def extract_env_vars_from_git_config dest = {} env_vars.each do |env_var, config_key| begin value = check_env_var_config_key(config_key) dest[env_var] = value unless value.empty? rescue StandardError => e error("#{e.message}") end end dest end
git_config()
click to toggle source
# File lib/git/duet/command_methods.rb, line 30 def git_config "git config#{@global ? ' --global' : ''}" end
in_repo_root() { || ... }
click to toggle source
# File lib/git/duet/command_methods.rb, line 88 def in_repo_root Dir.chdir(exec_check('git rev-parse --show-toplevel').chomp) do yield end end
info(msg)
click to toggle source
# File lib/git/duet/command_methods.rb, line 123 def info(msg) $stdout.puts(msg) unless quiet? end
prompt()
click to toggle source
# File lib/git/duet/command_methods.rb, line 131 def prompt $stdout.print '> ' end
quiet?()
click to toggle source
# File lib/git/duet/command_methods.rb, line 135 def quiet? ENV['GIT_DUET_QUIET'] == '1' || @quiet end
report_env_vars()
click to toggle source
# File lib/git/duet/command_methods.rb, line 11 def report_env_vars var_map.each do |key, value| info("#{key}='#{value}'") end end
show_current_config()
click to toggle source
# File lib/git/duet/command_methods.rb, line 51 def show_current_config info(exec_check(current_config_command)) end
with_output_quieted(&block)
click to toggle source
# File lib/git/duet/command_methods.rb, line 113 def with_output_quieted(&block) @old_quiet = @quiet @quiet = true block.call rescue StandardError => e raise e ensure @quiet = @old_quiet end
with_output_unquieted(&block)
click to toggle source
# File lib/git/duet/command_methods.rb, line 103 def with_output_unquieted(&block) @old_quiet = @quiet @quiet = false block.call @quiet = @old_quiet rescue StandardError => e @quiet = @old_quiet raise e end
write_env_vars()
click to toggle source
# File lib/git/duet/command_methods.rb, line 17 def write_env_vars in_repo_root do var_map.each do |key, value| exec_check( "#{git_config} #{Git::Duet::Config.namespace}." \ "#{key.downcase.gsub(/_/, '-')} '#{value}'" ) end exec_check("#{git_config} #{Git::Duet::Config .namespace}.mtime #{Time.now.to_i}") end end