Class: GitProc::GitConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/git-process/git_config.rb

Overview

Provides Git configuration

Instance Method Summary collapse

Constructor Details

#initialize(lib) ⇒ GitConfig

Returns a new instance of GitConfig.



45
46
47
# File 'lib/git-process/git_config.rb', line 45

def initialize(lib)
  @lib = lib
end

Instance Method Details

#[](key) ⇒ String

Returns the value of the configuration; nil if not found.

Parameters:

  • key (String)

    the key for the Git configuration, as would be passed to ‘git config –get`

Returns:

  • (String)

    the value of the configuration; nil if not found



52
53
54
55
56
57
58
59
60
# File 'lib/git-process/git_config.rb', line 52

def [](key)
  value = config_hash[key]
  unless value
    value = gitlib.command(:config, ['--get', key])
    value = nil if value.empty?
    config_hash[key] = value unless config_hash.empty?
  end
  value
end

#[]=(key, value) ⇒ String

Sets to configuration value for this repository.

Parameters:

  • key (String)

    the key for the Git configuration

  • value (String)

    the value for the local configuration

Returns:



69
70
71
72
73
# File 'lib/git-process/git_config.rb', line 69

def []=(key, value)
  gitlib.command(:config, [key, value])
  config_hash[key] = value unless config_hash.empty?
  value
end

#default_rebase_sync(re, global = true) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/git-process/git_config.rb', line 101

def default_rebase_sync(re, global = true)
  if global
    set_global('gitProcess.defaultRebaseSync', re)
  else
    self['gitProcess.defaultRebaseSync'] = re
  end
end

#default_rebase_sync=(re) ⇒ Object



110
111
112
# File 'lib/git-process/git_config.rb', line 110

def default_rebase_sync=(re)
  default_rebase_sync(re, false)
end

#default_rebase_sync?Boolean

Returns true if no value has been set; the value of the config otherwise.

Returns:

  • (Boolean)

    true if no value has been set; the value of the config otherwise



95
96
97
98
# File 'lib/git-process/git_config.rb', line 95

def default_rebase_sync?
  val = self['gitProcess.defaultRebaseSync']
  val.nil? or val.to_boolean
end

#gitlibGitLib

Returns the GitLib this was initialized with.

Returns:

  • (GitLib)

    the GitLib this was initialized with



84
85
86
# File 'lib/git-process/git_config.rb', line 84

def gitlib
  @lib
end

#integration_branchObject



127
128
129
# File 'lib/git-process/git_config.rb', line 127

def integration_branch
  remote.exists? ? remote.master_branch_name : self.master_branch
end

#loggerObject



89
90
91
# File 'lib/git-process/git_config.rb', line 89

def logger
  gitlib.logger
end

#master_branchString

Returns the name of the integration branch; defaults to ‘master’.

Returns:

  • (String)

    the name of the integration branch; defaults to ‘master’



116
117
118
# File 'lib/git-process/git_config.rb', line 116

def master_branch
  @master_branch ||= self['gitProcess.integrationBranch'] || 'master'
end

#remote_master_branchObject

Deprecated.


122
123
124
# File 'lib/git-process/git_config.rb', line 122

def remote_master_branch
  remote.master_branch_name
end

#set_global(key, value) ⇒ Object



76
77
78
79
80
# File 'lib/git-process/git_config.rb', line 76

def set_global(key, value)
  gitlib.command(:config, ['--global', key, value])
  config_hash[key] = value unless config_hash.empty?
  value
end