Class: Argus::Git
- Inherits:
-
Object
- Object
- Argus::Git
- Defined in:
- lib/argus/git.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#org ⇒ Object
readonly
Returns the value of attribute org.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
Instance Method Summary collapse
-
#checkout ⇒ Object
checkout branch of an existing repo.
-
#clone ⇒ Object
clone a new repo.
-
#initialize(org, repo, branch = 'master', sha = nil) ⇒ Git
constructor
A new instance of Git.
-
#is_inside_work_tree? ⇒ Boolean
is this dir a git repo?.
-
#pull ⇒ Object
pull existing, or new git repo, and return sha.
-
#reset ⇒ Object
get a specific commit.
-
#rev_parse ⇒ Object
get current sha.
- #to_s ⇒ Object
-
#url ⇒ Object
if we have a token, use https, else depend on ssh being set up.
Constructor Details
#initialize(org, repo, branch = 'master', sha = nil) ⇒ Git
Returns a new instance of Git.
5 6 7 8 9 10 |
# File 'lib/argus/git.rb', line 5 def initialize(org, repo, branch = 'master', sha = nil) @org = org @repo = repo @branch = branch @sha = sha end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
3 4 5 |
# File 'lib/argus/git.rb', line 3 def branch @branch end |
#org ⇒ Object (readonly)
Returns the value of attribute org.
3 4 5 |
# File 'lib/argus/git.rb', line 3 def org @org end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
3 4 5 |
# File 'lib/argus/git.rb', line 3 def repo @repo end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
3 4 5 |
# File 'lib/argus/git.rb', line 3 def sha @sha end |
Instance Method Details
#checkout ⇒ Object
checkout branch of an existing repo
42 43 44 45 46 |
# File 'lib/argus/git.rb', line 42 def checkout puts "repo exists, pulling #{self}" %x[git fetch && git checkout -f #{branch} && git reset --hard origin/#{branch}] raise ArgusError, "git checkout failed for #{self}" unless $? == 0 end |
#clone ⇒ Object
clone a new repo
49 50 51 52 53 |
# File 'lib/argus/git.rb', line 49 def clone puts "new repo, cloning #{self}" %x[git clone -b #{branch} #{url} .] # not found: clone it raise ArgusError, "git clone failed for #{self}" unless $? == 0 end |
#is_inside_work_tree? ⇒ Boolean
is this dir a git repo?
26 27 28 |
# File 'lib/argus/git.rb', line 26 def is_inside_work_tree? %x[git rev-parse --is-inside-work-tree 2> /dev/null].chomp == 'true' end |
#pull ⇒ Object
pull existing, or new git repo, and return sha
31 32 33 34 35 36 37 38 39 |
# File 'lib/argus/git.rb', line 31 def pull if is_inside_work_tree? checkout else clone end reset if sha # specific sha was requested @sha = rev_parse # return sha end |
#reset ⇒ Object
get a specific commit
56 57 58 59 |
# File 'lib/argus/git.rb', line 56 def reset puts "specific sha requested, resetting to #{sha}" %x[git fetch && git reset --hard #{sha}] end |
#rev_parse ⇒ Object
get current sha
62 63 64 |
# File 'lib/argus/git.rb', line 62 def rev_parse %x[git rev-parse #{branch} ].chomp end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/argus/git.rb', line 12 def to_s "#{org}/#{repo}:#{branch}" end |
#url ⇒ Object
if we have a token, use https, else depend on ssh being set up
17 18 19 20 21 22 23 |
# File 'lib/argus/git.rb', line 17 def url if ENV['GITHUB_TOKEN'] "https://#{ENV['GITHUB_TOKEN']}@github.com/#{org}/#{repo}.git" else "[email protected]:#{org}/#{repo}.git" end end |