Class: Gas::Gitconfig

Inherits:
Object
  • Object
show all
Defined in:
lib/gas/gitconfig.rb

Overview

Class that class that interacts with the git config

Constant Summary collapse

@@nickname =
''

Instance Method Summary collapse

Instance Method Details

#change_user(user) ⇒ Object

Changes the user

Parameters:

  • name (String)

    The new name

  • email (String)

    The new email



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gas/gitconfig.rb', line 31

def change_user(user)
  nickname = user.nickname
  @@nickname = nickname                  # maybe we should make nickname a class variable?
  name = user.name
  email = user.email

  `git config --global user.name "#{name}"`
  `git config --global user.email "#{email}"`

  # confirm that this user has an ssh and if so, swap it in safely
  Ssh.swap_in_rsa nickname
end

#current_userUser

Parse out the current user from the gitconfig

Parameters:

  • gitconfig (String)

    The git configuration

Returns:

  • (User)

    The current user or nil if not present



9
10
11
12
13
14
15
16
# File 'lib/gas/gitconfig.rb', line 9

def current_user
  name = `git config --global --get user.name`
  email = `git config --global --get user.email`

  return nil if name.nil? && email.nil?

  User.new name.delete("\n"), email.delete("\n"), @@nickname   # git cli returns the name and email with \n at the end
end

#current_user_objectObject

Get current user



19
20
21
22
23
24
25
26
# File 'lib/gas/gitconfig.rb', line 19

def current_user_object
  name = `git config --global --get user.name`
  email = `git config --global --get user.email`

  return nil if name.nil? && email.nil?

  return {:name => name.strip, :email => email.strip}
end