class GitSu::Git

Public Class Methods

new(shell) click to toggle source
# File lib/gitsu/git.rb, line 22
def initialize(shell)
    @shell = shell
end

Public Instance Methods

clear_user(scope) click to toggle source
# File lib/gitsu/git.rb, line 71
def clear_user(scope)
    unset_config(scope, "user.name")
    unset_config(scope, "user.email")
    if list_config(scope).select { |e| e =~ /^user\./ }.empty?
        remove_config_section(scope, "user")
    end
end
color_output?() click to toggle source
# File lib/gitsu/git.rb, line 79
def color_output?
    execute_config_command(:derived, "--get-colorbool color.ui")
end
commit(file, message) click to toggle source
# File lib/gitsu/git.rb, line 98
def commit(file, message)
    @shell.execute("git commit #{file} --message='#{message}'")
end
edit_gitsu_config() click to toggle source
# File lib/gitsu/git.rb, line 67
def edit_gitsu_config
    execute_config_command(:derived, "--edit --file #{File.expand_path '~/.gitsu'}")
end
get_color(color_name) click to toggle source
# File lib/gitsu/git.rb, line 48
def get_color(color_name)
    capture_config_command(:derived, "--get-color '' '#{color_name}'")
end
get_config(scope, key) click to toggle source
# File lib/gitsu/git.rb, line 26
def get_config(scope, key)
    capture_config_command(scope, key)
end
list_config(scope) click to toggle source
# File lib/gitsu/git.rb, line 40
def list_config(scope)
    capture_config_command(scope, "--list").chomp.split("\n")
end
list_files(*options) click to toggle source
# File lib/gitsu/git.rb, line 102
def list_files(*options)
    flags = options.map {|o| "--#{o}"}.join " "
    @shell.capture("git ls-files #{flags}").split "\n"
end
remove_config_section(scope, section) click to toggle source
# File lib/gitsu/git.rb, line 44
def remove_config_section(scope, section)
    capture_config_command(scope, "--remove-section #{section} 2>/dev/null")
end
render(user) click to toggle source
# File lib/gitsu/git.rb, line 83
def render(user)
    if color_output?
        user_color = get_color "blue"
        email_color = get_color "green"
        reset_color = get_color "reset"
        user.to_ansi_s(user_color, email_color, reset_color)
    else
        user.to_s
    end
end
render_user(scope) click to toggle source
# File lib/gitsu/git.rb, line 94
def render_user(scope)
    render selected_user(scope)
end
select_user(user, scope) click to toggle source
# File lib/gitsu/git.rb, line 52
def select_user(user, scope)
    set_config(scope, "user.name", user.name) or raise ConfigSettingError, "Couldn't update user config in '#{scope}' scope"
    set_config(scope, "user.email", user.email)
end
selected_user(scope) click to toggle source
# File lib/gitsu/git.rb, line 57
def selected_user(scope)
    name = get_config(scope, "user.name")
    if name.empty?
        User::NONE
    else
        email = get_config(scope, "user.email")
        User.new(name, email)
    end
end
set_config(scope, key, value) click to toggle source
# File lib/gitsu/git.rb, line 30
def set_config(scope, key, value)
    # replace <'> with <'\''>. E.g. O'Grady -> O'\''Grady
    escaped_value = value.gsub(/'/, "'\\\\\''")
    execute_config_command(scope, "#{key} '#{escaped_value}'")
end
unset_config(scope, key) click to toggle source
# File lib/gitsu/git.rb, line 36
def unset_config(scope, key)
    capture_config_command(scope, "--unset #{key}")
end

Private Instance Methods

capture_config_command(scope, command) click to toggle source
# File lib/gitsu/git.rb, line 120
def capture_config_command(scope, command)
    @shell.capture config_command(scope, command)
end
config_command(scope, suffix) click to toggle source
# File lib/gitsu/git.rb, line 108
def config_command(scope, suffix)
    command = "git config "
    unless scope == :derived
        command << "--#{scope} "
    end 
    command << suffix
end
execute_config_command(scope, command) click to toggle source
# File lib/gitsu/git.rb, line 116
def execute_config_command(scope, command)
    @shell.execute config_command(scope, command)
end