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
# File 'lib/crackin/scm/git.rb', line 8

def initialize(config={})
  super
  #@git = ::Git.open(@options[:working], log: Logger.new(STDOUT))
  @git = ::Git.open(@options[:working])
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



14
15
16
# File 'lib/crackin/scm/git.rb', line 14

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

#between(from, to) ⇒ Object



22
23
24
# File 'lib/crackin/scm/git.rb', line 22

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

#change_branch(to) ⇒ Object



55
56
57
# File 'lib/crackin/scm/git.rb', line 55

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

#commit(message) ⇒ Object



30
31
32
# File 'lib/crackin/scm/git.rb', line 30

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

#create_branch(name) ⇒ Object



59
60
61
62
63
# File 'lib/crackin/scm/git.rb', line 59

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

#current_branchObject



51
52
53
# File 'lib/crackin/scm/git.rb', line 51

def current_branch
  @git.branch_current
end

#delete_branch(name) ⇒ Object



65
66
67
68
# File 'lib/crackin/scm/git.rb', line 65

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

#logObject



18
19
20
# File 'lib/crackin/scm/git.rb', line 18

def log
  @git.log
end

#merge_from(from) ⇒ Object



47
48
49
# File 'lib/crackin/scm/git.rb', line 47

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

#pendingObject



78
79
80
81
82
83
84
85
86
# File 'lib/crackin/scm/git.rb', line 78

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)


88
89
90
# File 'lib/crackin/scm/git.rb', line 88

def pending?
  pending.count > 0
end

#pushObject



70
71
72
# File 'lib/crackin/scm/git.rb', line 70

def push
  @git.push
end

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



74
75
76
# File 'lib/crackin/scm/git.rb', line 74

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

#resetObject



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

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



26
27
28
# File 'lib/crackin/scm/git.rb', line 26

def tags
  Tags.new(@git)
end

#uncommitObject



34
35
36
# File 'lib/crackin/scm/git.rb', line 34

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