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.



26
27
28
29
# File 'lib/teapot/repository.rb', line 26

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

Instance Method Details

#add(files) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/teapot/repository.rb', line 69

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

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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/teapot/repository.rb', line 35

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

	@root.mkpath

	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



77
78
79
# File 'lib/teapot/repository.rb', line 77

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

#init!Object



31
32
33
# File 'lib/teapot/repository.rb', line 31

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

#statusObject



81
82
83
84
85
86
87
# File 'lib/teapot/repository.rb', line 81

def status
	Commands.run("git", "status", "--porcelain", :passthrough => [:in, :err]) do |task|
		if task.wait == 0
			return task.output.readlines.collect{|line| line.chomp.split(/\s+/, 2)}
		end
	end
end

#update(branch, commit = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/teapot/repository.rb', line 53

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