本篇内容主要讲解“Rugged::Reference和Rugged::Branch类怎么用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Rugged::Reference和Rugged::Branch类怎么用”吧!
Rugged::Reference类
Reference可以是Branch,Remote Branch, Tag, AnnotationTag或者指向其他Reference, 每个Reference都指向一个target,该target可以是一个Reference,或者AnnotationTag,此时Reference.type=:symbolic, 如果target是一个Commit,则Reference.type = :direct
a)获取Rugged::Reference对象
refs = repo.references#Rugged::ReferenceCollection
ref = refs["ref_name"]
refs.each#迭代
refs.each_name#按名字迭代
refs.exist?(name)#是否存在
refs.exists?(name)#是否存在
b)基本方法
valid_name?(ref_name) -> true or false
检查reference name 是否well-formed(良构)
peel -> oid
??
name
canonical_name
获取reference的名称
type -> :symbolic or :direct
获取reference的类型
target
ref1.type #=> :symbolic
ref.1.target => #<Rugged::Reference ...>
ref1.target_id #=> "refs/heads/master"
ref2.type #=> :direct
ref2.target #=> #<Rugged::Commit ...>
ref2.target_id #=> "de5ba987198bcf2518885f0fc1350e5172cded78"
获获取指向的target和target_id。如果reference是一个symbolic reference,则返回target reference对象。如果reference是一个直接的reference,则target对象。
resolve -> peeled_ref
r1.type #=> :symbolic
r1.name #=> 'HEAD'
r1.target #=> 'refs/heads/master'
r2 = r1.resolve #=> #<Rugged::Reference:0x401b3948>
r2.target #=> '9d09060c850defbc7711d08b57def0d14e742f4e'
获取symbolic reference指向的target reference
branch?-> true or false
判断当前reference是否为本地的分支
remote? -> true or false
判断当前reference是否是远程分支
tag? -> true or false
判断当前reference是否为标签
log
log? -> true or false --是否有reflog
reference.log #=> [
# {
# :id_old => nil, --改变之前的oid
# :id_new => '9d09060c850defbc7711d08b57def0d14e742f4e', --新oid
# :committer => {:name => 'Vicent Marti', :email => {'vicent@github.com'}},
# :message => 'created reference'
# }, ... ]
2. Rugged::Branch类(继承Rugged::Reference)
a)获取Rugged::Branch对象
branches = repo.branches #Rugged::BranchCollection
branch = branches["branch_name"]
branch.each
brach.each_name
b)基本方法
==(other)
判断两个分支是否相等
head? → true or false
是否HEAD指向当前分支
name → string
获取分支名
remote_name → string
获取分支所属的远程名
remote()
获取当前分支的所属远程
upstream → branch
upstream = branch
获取和设置远程的跟踪branch, 参数branch为Rugged::Branch或这Rugged::Reference
3. Rugged::Tag类(继承Rugged::Reference)
a)获取Rugged::Tag对象
tags = repo.tags #Rugged::TagCollection
tag = tags["tag_name"]
tags.each
tags.each_name
b)基本方法
message #=> "Release v0.16.0, codename 'broken stuff'"
获取tag的message
name #=> "v0.16.0"
获取tag名
tagger #=> {:email=>"tanoku@gmail.com", :time=>Tue Jan 24 05:42:45 UTC 2012, :name=>"Vicent Mart\303\255"}
获取tag的author signature(签名)
target_oid #=> "2cb831a8aea28b2c1b9c63385585b864e4d3bad1"
target_id #=> "2cb831a8aea28b2c1b9c63385585b864e4d3bad1"
获取指向对象的oid
type #=>:blob,:commit,:tree,:tag
获取指向对象的类型
target -> git_object
获取tag指向的target
到此,相信大家对“Rugged::Reference和Rugged::Branch类怎么用”有了更深的了解,不妨来实际操作一番吧!这里是天达云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!