Class: Blastr::SourceControl::Git
- Inherits:
-
Object
- Object
- Blastr::SourceControl::Git
- Defined in:
- lib/scm/git.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_revision(arg) ⇒ Object
- #commits_since(revision) ⇒ Object
-
#initialize(git_url) ⇒ Git
constructor
A new instance of Git.
- #latest_revision ⇒ Object
- #name ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(git_url) ⇒ Git
Returns a new instance of Git.
56 57 58 |
# File 'lib/scm/git.rb', line 56 def initialize(git_url) @git_url = git_url end |
Class Method Details
.understands_url?(url) ⇒ Boolean
47 48 49 50 51 52 53 54 |
# File 'lib/scm/git.rb', line 47 def self.understands_url?(url) return true if local_repository?(url) patterns = [ /^(git:)(.*)$/, /^(.*)(\.git)(\/?)$/ ] patterns.each do |regex| return true if url =~ regex end false end |
Instance Method Details
#as_revision(arg) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/scm/git.rb', line 64 def as_revision(arg) raise "Invalid revision: #{arg}" unless arg =~ /^(HEAD(~\d+)?)|([\d\w:-]+)$/ revision = nil with_clone do |clone| obj = clone.object(arg.to_s) revision = GitRevision.new(obj.sha, obj.date) end revision end |
#commits_since(revision) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/scm/git.rb', line 80 def commits_since(revision) with_clone do |clone| commits = [] clone.log.between(revision.to_s).each do |commit| commits << GitLogEntry.new(commit) end return commits.reverse end end |
#latest_revision ⇒ Object
74 75 76 77 78 |
# File 'lib/scm/git.rb', line 74 def latest_revision commits = commits_since(as_revision("HEAD~1")) return as_revision("HEAD") unless commits.size > 0 GitRevision.new(commits.last.revision.to_s, commits.last.revision.date) end |
#name ⇒ Object
45 |
# File 'lib/scm/git.rb', line 45 def name; "Git"; end |
#url ⇒ Object
60 61 62 |
# File 'lib/scm/git.rb', line 60 def url @git_url end |