Class: DropGit::Repository
- Inherits:
-
Object
- Object
- DropGit::Repository
- Defined in:
- lib/dropgit/repository.rb
Class Method Summary collapse
Instance Method Summary collapse
- #data ⇒ Object
- #git_init(remote) ⇒ Object
-
#initialize(data) ⇒ Repository
constructor
A new instance of Repository.
- #update ⇒ Object
Constructor Details
#initialize(data) ⇒ Repository
Returns a new instance of Repository.
13 14 15 16 17 18 |
# File 'lib/dropgit/repository.rb', line 13 def initialize(data) @name = data['name'] @path = data['path'] @git_dir = File.join(DropGit.settings.git_base, @name) @git_cmd = "git --git-dir=#{@git_dir} --work-tree=#{@path}" end |
Class Method Details
.create(path, remote) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/dropgit/repository.rb', line 3 def self.create(path, remote) data = { 'name' => File.basename(path), 'path' => path } new_repo = Repository.new(data) new_repo.git_init(remote) new_repo end |
Instance Method Details
#data ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/dropgit/repository.rb', line 42 def data { 'name' => @name, 'path' => @path, 'remote' => @remote } end |
#git_init(remote) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dropgit/repository.rb', line 31 def git_init(remote) @remote = remote raise "Repository '#{@name}' already exists in '#{@git_dir}'" if File.exists?(@git_dir) puts "Initializing git repository in #{@git_dir} from data in #{@path}" puts git "init" puts git "add ." puts git "commit -m 'DropGit initial commit'" puts git "remote add origin #{@remote}" puts git "push -u origin master" end |
#update ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dropgit/repository.rb', line 20 def update if need_sync? git_commit git_push puts "#{@name} remote was out of sync, pushed" end if git_pull puts "#{@name} local was out of sync, pulled" end end |