Class: Panoramix::Plugin::Git
Instance Attribute Summary collapse
-
#dst ⇒ Object
readonly
Returns the value of attribute dst.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
-
#clean ⇒ Object
Action clean fot this task.
-
#created? ⇒ Boolean
Has this instance already been created.
-
#initialize(dst, src, tag) ⇒ Git
constructor
A new instance of Git.
-
#needed?(timestamps) ⇒ Boolean
When this instance needs to be executed.
-
#run_default ⇒ Object
Default action for this task.
-
#timestamp ⇒ Object
Return current timestamp.
Methods inherited from Base
Constructor Details
#initialize(dst, src, tag) ⇒ Git
Returns a new instance of Git.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/panoramix/plugin/git.rb', line 12 def initialize(dst, src, tag) # Get git project name repo_name=src.split("/").last.gsub(".git", "") # Base path under which project will be downloaded base_path=dst.split(repo_name)[0..-1].join(repo_name) @dst=File.join(base_path, repo_name) @src = src @tag = tag end |
Instance Attribute Details
#dst ⇒ Object (readonly)
Returns the value of attribute dst.
8 9 10 |
# File 'lib/panoramix/plugin/git.rb', line 8 def dst @dst end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
9 10 11 |
# File 'lib/panoramix/plugin/git.rb', line 9 def src @src end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
10 11 12 |
# File 'lib/panoramix/plugin/git.rb', line 10 def tag @tag end |
Instance Method Details
#clean ⇒ Object
Action clean fot this task
60 61 62 |
# File 'lib/panoramix/plugin/git.rb', line 60 def clean shell "rm -rf #{@dst}" end |
#created? ⇒ Boolean
Has this instance already been created
55 56 57 |
# File 'lib/panoramix/plugin/git.rb', line 55 def created? File.directory?(@dst) end |
#needed?(timestamps) ⇒ Boolean
When this instance needs to be executed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/panoramix/plugin/git.rb', line 33 def needed? return true if !created? # Get remote branches remote = shell("git ls-remote #{src}", true)[:out].split("\n") # Is @tag a branch? is_branch = remote.select { |r| r.include?("refs/heads/#{tag}") } if is_branch.any? # Compare local refs with remote ref remote_ref = is_branch.first.gsub /\t/, ' ' local_refs = shell("git -C #{@dst} show-ref", true)[:out].split("\n") return !local_refs.include?(remote_ref) end #TODO: To be implemented for tags and commits return true end |
#run_default ⇒ Object
Default action for this task
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/panoramix/plugin/git.rb', line 65 def run_default if created? shell "git -C #{@dst} pull" # File does not exists, so clone the full repository else shell "git clone #{@src} #{@dst}" end # Switch to tag shell "git -C #{@dst} checkout #{@tag}" end |
#timestamp ⇒ Object
Return current timestamp
25 26 27 28 29 30 |
# File 'lib/panoramix/plugin/git.rb', line 25 def return Time.at 0 unless created? git_time = shell("git -C #{@dst} log -1 --format=\"%cd\"", true)[:out] #TODO check exit code Time.parse(git_time) end |