Class: Treet::Gitrepo
- Extended by:
- Forwardable
- Defined in:
- lib/treet/gitrepo.rb
Instance Attribute Summary
Attributes inherited from Repo
Instance Method Summary collapse
-
#branch(name) ⇒ Object
always branch from tip of master (private representation).
- #branches(branchname = nil) ⇒ Object
- #current?(tagname) ⇒ Boolean
- #detag(tagname) ⇒ Object
- #entries ⇒ Object
-
#initialize(path, opts = {}) ⇒ Gitrepo
constructor
A new instance of Gitrepo.
- #patch(patchdef) ⇒ Object
- #remote(name) ⇒ Object
- #tag(tagname, opts = {}) ⇒ Object
- #tagged?(tagname) ⇒ Boolean
- #tags ⇒ Object
- #to_hash(opts = {}) ⇒ Object
- #version(opts = {}) ⇒ Object
Methods inherited from Repo
Constructor Details
#initialize(path, opts = {}) ⇒ Gitrepo
Returns a new instance of Gitrepo.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/treet/gitrepo.rb', line 8 def initialize(path, opts = {}) raise ArgumentError, "author required for updates" unless opts[:author] super @author = opts[:author] begin @gitrepo = Rugged::Repository.new(root) rescue Rugged::RepositoryError @gitrepo = initialize_gitrepo add_and_commit! end end |
Instance Method Details
#branch(name) ⇒ Object
always branch from tip of master (private representation)
78 79 80 |
# File 'lib/treet/gitrepo.rb', line 78 def branch(name) gitrepo.create_branch(name) end |
#branches(branchname = nil) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/treet/gitrepo.rb', line 69 def branches(branchname = nil) if branchname Rugged::Branch.lookup(gitrepo, branchname) else gitrepo.branches.map(&:name) - ['master'] end end |
#current?(tagname) ⇒ Boolean
94 95 96 |
# File 'lib/treet/gitrepo.rb', line 94 def current?(tagname) commit_id_for(tagname) == head.target end |
#detag(tagname) ⇒ Object
42 43 44 45 46 |
# File 'lib/treet/gitrepo.rb', line 42 def detag(tagname) if tag_ref = Rugged::Reference.lookup(gitrepo, "refs/tags/#{tagname}") tag_ref.delete! end end |
#entries ⇒ Object
65 66 67 |
# File 'lib/treet/gitrepo.rb', line 65 def entries index.entries.map{|e| e[:path]} end |
#patch(patchdef) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/treet/gitrepo.rb', line 48 def patch(patchdef) super if git_changes?(patchdef) add_and_commit! end end |
#remote(name) ⇒ Object
98 99 100 |
# File 'lib/treet/gitrepo.rb', line 98 def remote(name) Rugged::Remote.lookup(gitrepo, name) end |
#tag(tagname, opts = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/treet/gitrepo.rb', line 26 def tag(tagname, opts = {}) refname = "refs/tags/#{tagname}" commit = opts[:commit] || head.target if tag_ref = Rugged::Reference.lookup(gitrepo, refname) # move an existing tag tag_ref.set_target(commit) else # new tag Rugged::Reference.create(gitrepo, refname, commit) end rescue Rugged::ReferenceError, Rugged::InvalidError => e # invalid string for source, e.g. blank or illegal punctuation (colons) # or opts[:commit] is invalid raise ArgumentError, "unable to tag '#{tagname}' on repo: #{e.}" end |
#tagged?(tagname) ⇒ Boolean
82 83 84 |
# File 'lib/treet/gitrepo.rb', line 82 def tagged?(tagname) ! commit_id_for(tagname).nil? end |
#tags ⇒ Object
22 23 24 |
# File 'lib/treet/gitrepo.rb', line 22 def gitrepo.refs.select {|ref| ref.name =~ %r{/tags/}} end |
#to_hash(opts = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/treet/gitrepo.rb', line 55 def to_hash(opts = {}) if opts[:commit] snapshot(opts[:commit]) elsif opts[:tag] tag_snapshot(opts[:tag]) else super() end.merge(augmentation) end |
#version(opts = {}) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/treet/gitrepo.rb', line 86 def version(opts = {}) if tagname = opts[:tag] commit_id_for(tagname) else head.target end end |