Class: Teapot::Git::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/teapot/repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, options = {}) ⇒ Repository

Returns a new instance of Repository.



53
54
55
56
# File 'lib/teapot/repository.rb', line 53

def initialize(root, options = {})
  @root = root
  @options = options
end

Instance Method Details

#add(files) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/teapot/repository.rb', line 96

def add(files)
  if files == :all
    run("add", "--all")
  else
    run("add", *files)
  end
end

#clone!(remote_url, branch = nil, commit = nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/teapot/repository.rb', line 62

def clone!(remote_url, branch = nil, commit = nil)
  branch_args = branch ? ["--branch", branch] : []

  @root.create

  run!("clone", remote_url, @root, *branch_args)

  if commit
    run("reset", "--hard", commit)
  end

  run("submodule", "update", "--init", "--recursive")
rescue
  #@root.rmtree

  raise
end

#commit(message) ⇒ Object



104
105
106
# File 'lib/teapot/repository.rb', line 104

def commit(message)
  run("commit", "-m", message)
end

#init!Object



58
59
60
# File 'lib/teapot/repository.rb', line 58

def init!
  run!("init", @root)
end

#statusObject



108
109
110
111
112
113
114
115
116
# File 'lib/teapot/repository.rb', line 108

def status
  input, output = IO.pipe
  
  Commands.run("git", "status", "--porcelain", :out => output)
  
  output.close
  
  return input.readlines.collect{|line| line.chomp.split(/\s+/, 2)}
end

#update(branch, commit = nil) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/teapot/repository.rb', line 80

def update(branch, commit = nil)
  run("fetch", "origin")
  run("checkout", branch)

  # Pull any changes, if you might get the error from above:
  # Your branch is behind 'origin/0.1' by 1 commit, and can be fast-forwarded.
  run("pull")

  # Checkout the specific version if it was given:
  if commit
    run("reset", "--hard", commit)
  end

  run("submodule", "update", "--init", "--recursive")
end