Class: Sunshine::GitRepo
Overview
Simple wrapper for git repos. Constructor supports :tree option to specify either a branch or tree-ish to checkout:
git = GitRepo.new "git://mygitrepo.git", :tree => "tags/release001"
Constant Summary collapse
- LOG_FORMAT =
[ ":revision: %H", ":committer: %cn", ":date: %cd", ":message: %s", ":refs: '%d'", ":tree: %t" ].join("%n")
- NAME_MATCH =
/\/([^\/]+)(\/?)\.git/
Instance Attribute Summary collapse
-
#tree ⇒ Object
Returns the value of attribute tree.
Attributes inherited from Repo
Class Method Summary collapse
-
.get_info(path = ".", shell = nil) ⇒ Object
Get the repo info from the path to a checked out git repo.
-
.git_log(path, shell) ⇒ Object
Returns the git logs for a path, formatted as yaml.
-
.git_origin(path, shell, public_url = true) ⇒ Object
Returns the fetch origin of the current git repo.
-
.make_public_url(git_url) ⇒ Object
Returns the git url for a public checkout.
-
.valid?(path = ".") ⇒ Boolean
Check if this is an svn repo.
Instance Method Summary collapse
- #do_checkout(path, shell) ⇒ Object
-
#initialize(url, options = {}) ⇒ GitRepo
constructor
A new instance of GitRepo.
- #name ⇒ Object
Methods inherited from Repo
#checkout_to, detect, #get_repo_info, inherited, new_of_type, #scm_flags
Constructor Details
#initialize(url, options = {}) ⇒ GitRepo
Returns a new instance of GitRepo.
90 91 92 93 |
# File 'lib/sunshine/repos/git_repo.rb', line 90 def initialize url, ={} super @tree = [:branch] || [:tree] || "master" end |
Instance Attribute Details
#tree ⇒ Object
Returns the value of attribute tree.
88 89 90 |
# File 'lib/sunshine/repos/git_repo.rb', line 88 def tree @tree end |
Class Method Details
.get_info(path = ".", shell = nil) ⇒ Object
Get the repo info from the path to a checked out git repo
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sunshine/repos/git_repo.rb', line 31 def self.get_info path=".", shell=nil shell ||= Sunshine.shell info = YAML.load git_log(path, shell) info[:date] = Time.parse info[:date] info[:branch] = parse_branch info info[:url] = git_origin path, shell info rescue => e raise RepoError, e end |
.git_log(path, shell) ⇒ Object
Returns the git logs for a path, formatted as yaml.
49 50 51 52 |
# File 'lib/sunshine/repos/git_repo.rb', line 49 def self.git_log path, shell = "-1 --no-color --format=\"#{LOG_FORMAT}\"" shell.call "cd #{path} && git log #{}" end |
.git_origin(path, shell, public_url = true) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sunshine/repos/git_repo.rb', line 63 def self.git_origin path, shell, public_url=true get_origin_cmd = "cd #{path} && git remote -v | grep \\(fetch\\)" origin = shell.call get_origin_cmd origin = origin.split(/\t|\s/)[1] origin = make_public_url origin if public_url origin end |
.make_public_url(git_url) ⇒ Object
Returns the git url for a public checkout
78 79 80 81 82 83 84 85 |
# File 'lib/sunshine/repos/git_repo.rb', line 78 def self.make_public_url git_url url, protocol = git_url.split("://").reverse url, user = url.split("@").reverse url.gsub!(":", "/") if !protocol "git://#{url}" end |
.valid?(path = ".") ⇒ Boolean
Check if this is an svn repo
23 24 25 |
# File 'lib/sunshine/repos/git_repo.rb', line 23 def self.valid? path="." File.exist? File.join(path, ".git") end |
Instance Method Details
#do_checkout(path, shell) ⇒ Object
96 97 98 99 100 |
# File 'lib/sunshine/repos/git_repo.rb', line 96 def do_checkout path, shell cmd = "cd #{path} && git clone #{@url} #{scm_flags} . && "+ "git checkout #{@tree}" shell.call cmd end |
#name ⇒ Object
105 106 107 108 109 |
# File 'lib/sunshine/repos/git_repo.rb', line 105 def name @url.match(NAME_MATCH)[1] rescue raise RepoError, "Git url must match #{NAME_MATCH.inspect}" end |