Module: Git_Repo::Base

Included in:
Git_Repo
Defined in:
lib/Git_Repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



10
11
12
# File 'lib/Git_Repo.rb', line 10

def address
  @address
end

Instance Method Details

#add(str) ⇒ Object



19
20
21
# File 'lib/Git_Repo.rb', line 19

def add str
  shell "git add #{str}"
end

#bundle_updateObject



60
61
62
# File 'lib/Git_Repo.rb', line 60

def bundle_update
  shell "bundle update"
end

#changes_to_be_committed?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/Git_Repo.rb', line 44

def changes_to_be_committed?
  status['Changes to be committed']
end

#commit(msg) ⇒ Object



36
37
38
# File 'lib/Git_Repo.rb', line 36

def commit msg
  shell "git commit -m \"#{msg.gsub(%r!\r|\n!, ' ').gsub('"', "'")}\""
end

#commit_pending?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/Git_Repo.rb', line 52

def commit_pending?
  !nothing_to_commit?
end

#initObject



15
16
17
# File 'lib/Git_Repo.rb', line 15

def init
  shell "git init"
end

#initialize(dir) ⇒ Object



11
12
13
# File 'lib/Git_Repo.rb', line 11

def initialize dir
  @address = File.expand_path(dir)
end

#nothing_to_commit?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/Git_Repo.rb', line 48

def nothing_to_commit?
  !!( status['nothing to commit (working directory clean)'] )
end

#resetObject



32
33
34
# File 'lib/Git_Repo.rb', line 32

def reset
  shell "git reset"
end

#shell(cmd) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/Git_Repo.rb', line 64

def shell cmd
  val = `cd #{address} && #{cmd} 2>&1`.to_s.strip
  print cmd, "\n"
  if $?.exitstatus != 0
    raise Failed_Shell_Command, "Results:\n#{val}"
  end
  print val, "\n"
  val
end

#staged?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/Git_Repo.rb', line 56

def staged?
  commit_pending?
end

#statusObject



40
41
42
# File 'lib/Git_Repo.rb', line 40

def status
  shell "git status"
end

#tag(str) ⇒ Object



28
29
30
# File 'lib/Git_Repo.rb', line 28

def tag str
  shell "git tag #{str}"
end

#updateObject



23
24
25
26
# File 'lib/Git_Repo.rb', line 23

def update
  add '.'
  add '-u'
end