Class: Repository
- Inherits:
-
Object
- Object
- Repository
- Defined in:
- lib/hangover/repository.rb
Constant Summary collapse
- NAME =
'.hangover'
Class Method Summary collapse
Instance Method Summary collapse
- #add_all ⇒ Object
- #clean ⇒ Object
- #commit(message, args = '') ⇒ Object
- #commit_all(message) ⇒ Object
- #diff ⇒ Object
- #exists! ⇒ Object
- #git(args) ⇒ Object
- #gitk ⇒ Object
- #init ⇒ Object
-
#initialize(dir) ⇒ Repository
constructor
A new instance of Repository.
Constructor Details
#initialize(dir) ⇒ Repository
Returns a new instance of Repository.
20 21 22 23 24 |
# File 'lib/hangover/repository.rb', line 20 def initialize(dir) @repository = "#{dir}/#{NAME}" ENV['GIT_DIR'] = @repository ENV['GIT_WORK_TREE'] = dir end |
Class Method Details
.find(dir) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/hangover/repository.rb', line 8 def find(dir) path = Pathname.new(dir)..realpath begin try_path = path + NAME return new(path.to_s) if try_path.directory? end while (path = path.parent).to_s != '/' nil end |
Instance Method Details
#add_all ⇒ Object
50 51 52 |
# File 'lib/hangover/repository.rb', line 50 def add_all git 'add .' end |
#clean ⇒ Object
66 67 68 |
# File 'lib/hangover/repository.rb', line 66 def clean git 'clean' end |
#commit(message, args = '') ⇒ Object
54 55 56 |
# File 'lib/hangover/repository.rb', line 54 def commit(, args = '') git "commit #{args} -m \"#{}\"" end |
#commit_all(message) ⇒ Object
58 59 60 |
# File 'lib/hangover/repository.rb', line 58 def commit_all() commit(, '-a') end |
#diff ⇒ Object
62 63 64 |
# File 'lib/hangover/repository.rb', line 62 def diff git 'diff --unified=0' end |
#exists! ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hangover/repository.rb', line 26 def exists! if File.directory?(@repository) Hangover.logger.warn "Repository already exists at #{@repository}" return end Hangover.logger.info "Initializing new hangover repo at #{@repository}" init File.open("#{@repository}/info/exclude", "w") do |f| f.puts NAME f.puts ".git" end add_all commit_all("Initial commit") end |
#git(args) ⇒ Object
70 71 72 73 |
# File 'lib/hangover/repository.rb', line 70 def git(args) Hangover.logger.debug { "git #{args}" } `git #{args}` end |
#gitk ⇒ Object
42 43 44 |
# File 'lib/hangover/repository.rb', line 42 def gitk `gitk` end |
#init ⇒ Object
46 47 48 |
# File 'lib/hangover/repository.rb', line 46 def init git 'init' end |