Class: CIQuantum::Git
- Inherits:
-
Struct
- Object
- Struct
- CIQuantum::Git
- Defined in:
- lib/ciquantum/git.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #branch ⇒ Object
- #branches ⇒ Object
- #branches_with_commit(commit_sha) ⇒ Object
- #checkout(other_branch) ⇒ Object
- #current_branch_contains_commit?(commit_sha) ⇒ Boolean
- #exec(command) ⇒ Object
- #fetch ⇒ Object
- #is_current_branch?(other_branch) ⇒ Boolean
- #sha ⇒ Object
- #update ⇒ Object
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path
2 3 4 |
# File 'lib/ciquantum/git.rb', line 2 def path @path end |
Instance Method Details
#branch ⇒ Object
28 29 30 31 32 33 |
# File 'lib/ciquantum/git.rb', line 28 def branch if !@branch && exec("cd #{path} && git branch 2>/dev/null | grep -e '\*' ") =~ /^\*\s(\w+)/ @branch = $1.strip end @branch end |
#branches ⇒ Object
20 21 22 |
# File 'lib/ciquantum/git.rb', line 20 def branches branches_to_list `cd #{path} && git branch -r` end |
#branches_with_commit(commit_sha) ⇒ Object
48 49 50 51 |
# File 'lib/ciquantum/git.rb', line 48 def branches_with_commit commit_sha fetch branches_to_list exec("cd #{path} && git branch -r --contains #{commit_sha}") end |
#checkout(other_branch) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/ciquantum/git.rb', line 39 def checkout other_branch unless is_current_branch?(other_branch) fetch exec("cd #{path} && git checkout #{other_branch}") if branches.include?(other_branch) @branch = nil end update end |
#current_branch_contains_commit?(commit_sha) ⇒ Boolean
53 54 55 56 |
# File 'lib/ciquantum/git.rb', line 53 def current_branch_contains_commit? commit_sha return false if commit_sha.nil? || commit_sha.empty? branches_with_commit(commit_sha).include?(branch) end |
#exec(command) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/ciquantum/git.rb', line 4 def exec command puts "Executing git command: #{command}" res = `#{command}` puts "Result for git command:\n#{res}" res end |
#fetch ⇒ Object
24 25 26 |
# File 'lib/ciquantum/git.rb', line 24 def fetch exec("cd #{path} && git fetch origin") end |
#is_current_branch?(other_branch) ⇒ Boolean
35 36 37 |
# File 'lib/ciquantum/git.rb', line 35 def is_current_branch? other_branch return branch.eql? other_branch end |
#sha ⇒ Object
11 12 13 |
# File 'lib/ciquantum/git.rb', line 11 def sha exec("cd #{path} && git rev-parse origin/#{branch}").chomp end |
#update ⇒ Object
15 16 17 18 |
# File 'lib/ciquantum/git.rb', line 15 def update fetch exec("cd #{path} && git reset --hard origin/#{branch} && git submodule update --init") end |