Class: Crackin::Scm::Git

Inherits:
Base
  • Object
show all
Defined in:
lib/crackin/scm/git.rb

Direct Known Subclasses

Tags

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#tag

Constructor Details

#initialize(config = {}) ⇒ Git

Returns a new instance of Git.



8
9
10
11
12
13
14
# File 'lib/crackin/scm/git.rb', line 8

def initialize(config={})
  super
  #@git = ::Git.open(@options[:working], log: Logger.new(STDOUT))
  o = {}
  o['log'] = Logger.new(STDOUT) if config['debug']
  @git = ::Git.open(@options[:working], o.deep_symbolize_keys)
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



7
8
9
# File 'lib/crackin/scm/git.rb', line 7

def git
  @git
end

Instance Method Details

#add(options = {}) ⇒ Object



16
17
18
# File 'lib/crackin/scm/git.rb', line 16

def add(options={})
  @git.add(options)
end

#between(from, to) ⇒ Object



24
25
26
# File 'lib/crackin/scm/git.rb', line 24

def between(from, to)
  @git.log.between(from, to)
end

#change_branch(to) ⇒ Object



57
58
59
# File 'lib/crackin/scm/git.rb', line 57

def change_branch(to)
  @git.checkout(to)
end

#commit(message) ⇒ Object



32
33
34
# File 'lib/crackin/scm/git.rb', line 32

def commit(message)
  @git.commit_all(message)
end

#create_branch(name) ⇒ Object



61
62
63
64
65
# File 'lib/crackin/scm/git.rb', line 61

def create_branch(name)
  branch = @git.branch(Shellwords.escape(name))
  branch.create
  branch.checkout
end

#current_branchObject



53
54
55
# File 'lib/crackin/scm/git.rb', line 53

def current_branch
  @git.branch_current
end

#delete_branch(name) ⇒ Object



67
68
69
70
# File 'lib/crackin/scm/git.rb', line 67

def delete_branch(name)
  @git.checkout
  @git.branch(Shellwords.escape(name)).delete
end

#logObject



20
21
22
# File 'lib/crackin/scm/git.rb', line 20

def log
  @git.log
end

#merge_from(from) ⇒ Object



49
50
51
# File 'lib/crackin/scm/git.rb', line 49

def merge_from(from)
  @git.branch(from).merge
end

#pendingObject



84
85
86
87
88
89
90
91
92
# File 'lib/crackin/scm/git.rb', line 84

def pending
  s = @git.status
  d = {}
  d.merge! s.changed
  d.merge! s.added
  d.merge! s.deleted
  d.merge! s.untracked
  d
end

#pending?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/crackin/scm/git.rb', line 94

def pending?
  pending.count > 0
end

#pullObject



72
73
74
# File 'lib/crackin/scm/git.rb', line 72

def pull
  @git.pull
end

#push(remote = @git.remote, branch = current_branch) ⇒ Object



76
77
78
# File 'lib/crackin/scm/git.rb', line 76

def push(remote=@git.remote, branch=current_branch)
  @git.push(remote, branch)
end

#push_tags(remote = @git.remote, branch = current_branch) ⇒ Object



80
81
82
# File 'lib/crackin/scm/git.rb', line 80

def push_tags(remote=@git.remote, branch=current_branch)
  @git.push(remote, branch, true)
end

#resetObject



40
41
42
43
44
45
46
47
# File 'lib/crackin/scm/git.rb', line 40

def reset
  @git.checkout_file('--', '.')
  @git.clean(d: true, force: true)
  #pending.keys.each do |p|
  #  puts "pending: #{p}"
  #  @git.checkout_file('--', p)
  #end
end

#tagsObject



28
29
30
# File 'lib/crackin/scm/git.rb', line 28

def tags
  Tags.new(@git)
end

#uncommitObject



36
37
38
# File 'lib/crackin/scm/git.rb', line 36

def uncommit
  @git.reset_hard('HEAD^')
end