class Panoramix::Plugin::Git

Attributes

dst[R]
src[R]
tag[R]

Public Class Methods

new(dst, src, tag) click to toggle source
# 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

Public Instance Methods

clean() click to toggle source

Action clean fot this task

# File lib/panoramix/plugin/git.rb, line 60
def clean
        shell "rm -rf #{@dst}"
end
created?() click to toggle source

Has this instance already been created

# File lib/panoramix/plugin/git.rb, line 55
def created?
        File.directory?(@dst)
end
needed?(timestamps) click to toggle source

When this instance needs to be executed

# File lib/panoramix/plugin/git.rb, line 33
def needed? timestamps
        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() click to toggle source

Default action for this task

# 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() click to toggle source

Return current timestamp

# File lib/panoramix/plugin/git.rb, line 25
    def timestamp
            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