Module: MultiGit::Ref Abstract
- Extended by:
- Utils::AbstractMethods
- Included in:
- GitBackend::Ref, JGitBackend::Ref, MultiGit::RuggedBackend::Ref
- Defined in:
- lib/multi_git/ref.rb
Overview
Defined Under Namespace
Modules: Locking, OptimisticUpdater, PessimisticUpdater Classes: FileUpdater, OptimisticFileUpdater, PessimisticFileUpdater, RecklessUpdater, Updater
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The full name of this ref e.g.
- #repository ⇒ MultiGit::Repository readonly
-
#target ⇒ MultiGit::Ref, ...
readonly
abstract
The target of this ref.
Treeish methods collapse
- #[](name) ⇒ Object (also: #/)
Utility methods collapse
Writing methods collapse
-
#commit(options = {}) { ... } ⇒ Ref
Shorthand method to directly create a commit and update the given ref.
-
#delete ⇒ Ref
Shorthand for deleting this ref.
-
#update(value_or_lock = :optimistic) ⇒ Object
Updates the target of this reference.
Instance Method Summary collapse
-
#reload ⇒ MultiGit::Ref
Rereads this reference from the repository.
-
#resolve ⇒ MultGit::Ref
Resolves symbolic references and returns the final reference.
Methods included from Utils::AbstractMethods
Instance Attribute Details
#name ⇒ String (readonly)
The full name of this ref e.g. refs/heads/master for the master branch.
251 252 253 |
# File 'lib/multi_git/ref.rb', line 251 def name @name end |
#repository ⇒ MultiGit::Repository (readonly)
260 261 262 |
# File 'lib/multi_git/ref.rb', line 260 def repository @repository end |
#target ⇒ MultiGit::Ref, ... (readonly)
The target of this ref.
257 |
# File 'lib/multi_git/ref.rb', line 257 abstract :target |
Instance Method Details
#[](name) ⇒ Object Also known as: /
290 291 292 293 294 295 |
# File 'lib/multi_git/ref.rb', line 290 def [](name) t = resolve.target if t return t[name] end end |
#commit(options = {}) { ... } ⇒ Ref
Shorthand method to directly create a commit and update the given ref.
404 405 406 407 408 409 |
# File 'lib/multi_git/ref.rb', line 404 def commit( = {}, &block) resolve.update(.fetch(:lock, :optimistic)) do |current| Commit::Builder.new(current, &block) end return reload end |
#delete ⇒ Ref
Shorthand for deleting this ref.
382 383 384 |
# File 'lib/multi_git/ref.rb', line 382 def delete update( nil ) end |
#detached? ⇒ Boolean
311 312 313 |
# File 'lib/multi_git/ref.rb', line 311 def detached? symbolic? && !target.kind_of?(Ref) end |
#direct? ⇒ Boolean
303 304 305 |
# File 'lib/multi_git/ref.rb', line 303 def direct? name.include?('/') end |
#exists? ⇒ Boolean
315 316 317 |
# File 'lib/multi_git/ref.rb', line 315 def exists? !target.nil? end |
#reload ⇒ MultiGit::Ref
Rereads this reference from the repository.
271 272 273 |
# File 'lib/multi_git/ref.rb', line 271 def reload repository.ref(name) end |
#resolve ⇒ MultGit::Ref
Resolves symbolic references and returns the final reference.
278 279 280 281 282 283 284 285 286 |
# File 'lib/multi_git/ref.rb', line 278 def resolve @leaf ||= begin ref = self loop do break ref unless ref.target.kind_of? MultiGit::Ref ref = ref.target end end end |
#symbolic? ⇒ Boolean
307 308 309 |
# File 'lib/multi_git/ref.rb', line 307 def symbolic? !direct? end |
#update(lock = :optimistic) {|current_target| ... } ⇒ MultiGit::Ref #update(value) ⇒ MultiGit::Ref
Updates the target of this reference.
The new target of this reference is the result of the passed block. If you return nil, the ref will be deleted.
372 373 374 375 376 377 378 |
# File 'lib/multi_git/ref.rb', line 372 def update( value_or_lock = :optimistic ) updater = updater_class(block_given?, value_or_lock).new(self) updater.update( block_given? ? yield(updater.target) : value_or_lock ) return reload ensure updater.destroy! if updater end |