Class: Ding::Git
- Inherits:
-
Object
- Object
- Ding::Git
- Defined in:
- lib/ding/models/git.rb
Instance Method Summary collapse
- #branch_exists?(branch) ⇒ Boolean
- #branches(pattern) ⇒ Object
- #checkout(branch) ⇒ Object
- #create_branch(branch) ⇒ Object
- #delete_branch(branch) ⇒ Object
-
#initialize(options = {}) ⇒ Git
constructor
A new instance of Git.
- #push(branch) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Git
4 5 6 7 |
# File 'lib/ding/models/git.rb', line 4 def initialize(={}) raise "#{repo} is NOT a git repository" unless git_repo? = end |
Instance Method Details
#branch_exists?(branch) ⇒ Boolean
13 14 15 |
# File 'lib/ding/models/git.rb', line 13 def branch_exists?(branch) ! %x(git branch --list #{branch}).empty? end |
#branches(pattern) ⇒ Object
9 10 11 |
# File 'lib/ding/models/git.rb', line 9 def branches(pattern) %x(git branch --remote --list #{remote_version(pattern)}).split.map {|b| b.split('/').last} end |
#checkout(branch) ⇒ Object
17 18 19 |
# File 'lib/ding/models/git.rb', line 17 def checkout(branch) raise "Unable to checkout #{branch}" unless run_cmd "git checkout #{branch}" end |
#create_branch(branch) ⇒ Object
21 22 23 |
# File 'lib/ding/models/git.rb', line 21 def create_branch(branch) raise "Unable to create #{branch}" unless run_cmd "git branch --track #{branch}" end |
#delete_branch(branch) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ding/models/git.rb', line 25 def delete_branch(branch) local_branch = local_version(branch) remote_branch = remote_version(branch) raise "You are not allowed to delete #{local_branch}" if Ding::SACROSANCT_BRANCHES.include?(local_branch) if branch_exists?(local_branch) branch_cmd = "git branch #{options[:force] ? '-D' : '-d'} #{local_branch}" raise "Unable to delete #{local_branch}" unless run_cmd branch_cmd end if branch_exists?(remote_branch) branch_cmd = "git push #{remote_name} :#{local_branch} #{options[:force] ? '-f' : ''}" raise "Unable to delete #{remote_branch}" unless run_cmd branch_cmd end end |
#push(branch) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/ding/models/git.rb', line 39 def push(branch) checkout branch push_cmd = "git push #{remote_name} #{branch}" push_cmd << " --force" if [:force] raise "Unable to push #{branch} branch!" unless run_cmd push_cmd end |
#update ⇒ Object
46 47 48 |
# File 'lib/ding/models/git.rb', line 46 def update raise "Error synchronising with the remote" unless run_cmd "git up" end |