diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-15 03:51:04 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-15 03:51:04 +0200 |
commit | bcb49927a3897eadc29960032c70da29e26d6b58 (patch) | |
tree | 60025a0a59d15e49c6027b1bfd5d6fee5d5d2438 | |
parent | f6fe29c80d11662a169806dcf413ecdedcb28fa3 (diff) | |
download | go-git-bcb49927a3897eadc29960032c70da29e26d6b58.tar.gz |
Repository.Clone and Remote.Fetch remote, local branches and client: correct header read
-rw-r--r-- | clients/common/common.go | 5 | ||||
-rw-r--r-- | clients/http/git_upload_pack.go | 20 | ||||
-rw-r--r-- | clients/http/git_upload_pack_test.go | 16 | ||||
-rw-r--r-- | common_test.go | 2 | ||||
-rw-r--r-- | core/reference.go | 2 | ||||
-rw-r--r-- | examples/basic/main.go | 7 | ||||
-rw-r--r-- | formats/pktline/decoder.go | 2 | ||||
-rw-r--r-- | objects_test.go | 2 | ||||
-rw-r--r-- | options.go | 39 | ||||
-rw-r--r-- | remote.go | 25 | ||||
-rw-r--r-- | remote_test.go | 49 | ||||
-rw-r--r-- | repository.go | 125 | ||||
-rw-r--r-- | repository_test.go | 113 |
13 files changed, 323 insertions, 84 deletions
diff --git a/clients/common/common.go b/clients/common/common.go index b1a0fe1..c8dc7de 100644 --- a/clients/common/common.go +++ b/clients/common/common.go @@ -287,6 +287,7 @@ func (r *GitUploadPackInfo) Bytes() []byte { type GitUploadPackRequest struct { Wants []core.Hash Haves []core.Hash + Depth int } func (r *GitUploadPackRequest) Want(h ...core.Hash) { @@ -312,6 +313,10 @@ func (r *GitUploadPackRequest) Reader() *strings.Reader { e.AddLine(fmt.Sprintf("have %s", have)) } + if r.Depth != 0 { + e.AddLine(fmt.Sprintf("deepen %d", r.Depth)) + } + e.AddFlush() e.AddLine("done") diff --git a/clients/http/git_upload_pack.go b/clients/http/git_upload_pack.go index 96535de..68ec238 100644 --- a/clients/http/git_upload_pack.go +++ b/clients/http/git_upload_pack.go @@ -66,14 +66,28 @@ func (s *GitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.ReadClo return nil, err } - h := make([]byte, 8) - if _, err := res.Body.Read(h); err != nil { - return nil, core.NewUnexpectedError(err) + if err := s.discardResponseInfo(res.Body); err != nil { + return nil, err } return res.Body, nil } +func (s *GitUploadPackService) discardResponseInfo(r io.Reader) error { + decoder := pktline.NewDecoder(r) + for { + line, err := decoder.ReadLine() + if err != nil { + break + } + + if line == "NAK\n" { + break + } + } + + return nil +} func (s *GitUploadPackService) doRequest(method, url string, content *strings.Reader) (*http.Response, error) { var body io.Reader if content != nil { diff --git a/clients/http/git_upload_pack_test.go b/clients/http/git_upload_pack_test.go index 7e8cc36..702f1b2 100644 --- a/clients/http/git_upload_pack_test.go +++ b/clients/http/git_upload_pack_test.go @@ -73,3 +73,19 @@ func (s *RemoteSuite) TestFetch(c *C) { c.Assert(err, IsNil) c.Assert(b, HasLen, 85374) } + +func (s *RemoteSuite) TestFetchMulti(c *C) { + r := NewGitUploadPackService(s.Endpoint) + c.Assert(r.Connect(), IsNil) + + req := &common.GitUploadPackRequest{} + req.Want(core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")) + req.Want(core.NewHash("e8d3ffab552895c19b9fcf7aa264d277cde33881")) + + reader, err := r.Fetch(req) + c.Assert(err, IsNil) + + b, err := ioutil.ReadAll(reader) + c.Assert(err, IsNil) + c.Assert(len(b), HasLen, 85585) +} diff --git a/common_test.go b/common_test.go index cd37e75..3c373ec 100644 --- a/common_test.go +++ b/common_test.go @@ -48,6 +48,7 @@ func (p *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) { c.Decode("6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed no-done symref=HEAD:refs/heads/master agent=git/2:2.4.8~dbussink-fix-enterprise-tokens-compilation-1167-gc7006cf") ref := core.ReferenceName("refs/heads/master") + branch := core.ReferenceName("refs/heads/branch") tag := core.ReferenceName("refs/tags/v1.0.0") return &common.GitUploadPackInfo{ Capabilities: c, @@ -55,6 +56,7 @@ func (p *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) { core.HEAD: core.NewSymbolicReference(core.HEAD, ref), ref: core.NewHashReference(ref, h), tag: core.NewHashReference(tag, h), + branch: core.NewHashReference(branch, core.NewHash("e8d3ffab552895c19b9fcf7aa264d277cde33881")), }, }, nil } diff --git a/core/reference.go b/core/reference.go index 3ec95a0..89852da 100644 --- a/core/reference.go +++ b/core/reference.go @@ -114,7 +114,7 @@ func (r *Reference) Target() ReferenceName { // IsBranch check if a reference is a branch func (r *Reference) IsBranch() bool { - return strings.HasPrefix(string(r.n), refHeadPrefix) + return strings.HasPrefix(string(r.n), refHeadPrefix) || r.n == HEAD } // IsNote check if a reference is a note diff --git a/examples/basic/main.go b/examples/basic/main.go index fd7f82e..e13b5d9 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -16,7 +16,7 @@ func main() { panic(err) } - if err = r.Clone(&git.CloneOptions{URL: url}); err != nil { + if err = r.Clone(&git.RepositoryCloneOptions{URL: url, Depth: 1, SingleBranch: false}); err != nil { panic(err) } @@ -24,8 +24,10 @@ func main() { if err != nil { panic(err) } + defer iter.Close() + var count = 0 for { //the commits are not shorted in any special order commit, err := iter.Next() @@ -37,6 +39,9 @@ func main() { panic(err) } + count++ fmt.Println(commit) } + + fmt.Println("total commits:", count) } diff --git a/formats/pktline/decoder.go b/formats/pktline/decoder.go index 34e6f51..789ba7d 100644 --- a/formats/pktline/decoder.go +++ b/formats/pktline/decoder.go @@ -32,7 +32,7 @@ func (d *Decoder) ReadLine() (string, error) { func (d *Decoder) readLine() (string, error) { raw := make([]byte, HeaderLength) - if _, err := d.r.Read(raw); err != nil { + if _, err := io.ReadFull(d.r, raw); err != nil { return "", err } diff --git a/objects_test.go b/objects_test.go index d24aa7b..1ed35f8 100644 --- a/objects_test.go +++ b/objects_test.go @@ -23,7 +23,7 @@ func (s *ObjectsSuite) SetUpTest(c *C) { s.r, err = NewMemoryRepository() c.Assert(err, IsNil) - err = s.r.Clone(&CloneOptions{URL: RepositoryFixture}) + err = s.r.Clone(&RepositoryCloneOptions{URL: RepositoryFixture}) c.Assert(err, IsNil) } @@ -5,30 +5,41 @@ import ( "gopkg.in/src-d/go-git.v4/core" ) -// CloneOptions describe how a clone should be perform -type CloneOptions struct { +const ( + // DefaultRemoteName name of the default Remote, just like git command + DefaultRemoteName = "origin" +) + +// RepositoryCloneOptions describe how a clone should be perform +type RepositoryCloneOptions struct { // The (possibly remote) repository URL to clone from URL string // Auth credentials, if required, to uses with the remote repository Auth common.AuthMethod - // Remote branch to fetch + // Name of the remote to be added, by default `origin` + RemoteName string + // Remote branch to clone ReferenceName core.ReferenceName + // Fetch only ReferenceName if true + SingleBranch bool + // Limit fetching to the specified number of commits + Depth int } -func (o *CloneOptions) Default() { - if o.ReferenceName == "" { - o.ReferenceName = core.HEAD +func (o *RepositoryCloneOptions) Default() { + if o.RemoteName == "" { + o.RemoteName = DefaultRemoteName } -} -// FetchOptions describe how a fetch should be perform -type FetchOptions struct { - // Remote branch to fetch - ReferenceName core.ReferenceName -} - -func (o *FetchOptions) Default() { if o.ReferenceName == "" { o.ReferenceName = core.HEAD } } + +// RemoteFetchOptions describe how a fetch should be perform +type RemoteFetchOptions struct { + // Remote branchs to fetch + References []*core.Reference + // Limit fetching to the specified number of commits + Depth int +} @@ -9,6 +9,7 @@ import ( // Remote represents a connection to a remote repository type Remote struct { + Name string Endpoint common.Endpoint Auth common.AuthMethod @@ -17,13 +18,13 @@ type Remote struct { } // NewRemote returns a new Remote, using as client http.DefaultClient -func NewRemote(url string) (*Remote, error) { - return NewAuthenticatedRemote(url, nil) +func NewRemote(name, url string) (*Remote, error) { + return NewAuthenticatedRemote(name, url, nil) } // NewAuthenticatedRemote returns a new Remote using the given AuthMethod, using as // client http.DefaultClient -func NewAuthenticatedRemote(url string, auth common.AuthMethod) (*Remote, error) { +func NewAuthenticatedRemote(name, url string, auth common.AuthMethod) (*Remote, error) { endpoint, err := common.NewEndpoint(url) if err != nil { return nil, err @@ -36,6 +37,7 @@ func NewAuthenticatedRemote(url string, auth common.AuthMethod) (*Remote, error) return &Remote{ Endpoint: endpoint, + Name: name, Auth: auth, upSrv: upSrv, }, nil @@ -77,16 +79,17 @@ func (r *Remote) Capabilities() *common.Capabilities { } // Fetch returns a reader using the request -func (r *Remote) Fetch(s core.ObjectStorage, o *FetchOptions) (err error) { - o.Default() +func (r *Remote) Fetch(s core.ObjectStorage, o *RemoteFetchOptions) (err error) { + req := &common.GitUploadPackRequest{} + req.Depth = o.Depth - ref, err := r.Ref(o.ReferenceName, true) - if err != nil { - return err - } + for _, ref := range o.References { + if ref.Type() != core.HashReference { + continue + } - req := &common.GitUploadPackRequest{} - req.Want(ref.Hash()) + req.Want(ref.Hash()) + } reader, err := r.upSrv.Fetch(req) if err != nil { diff --git a/remote_test.go b/remote_test.go index 798d75d..c369ab7 100644 --- a/remote_test.go +++ b/remote_test.go @@ -15,39 +15,41 @@ type RemoteSuite struct { var _ = Suite(&RemoteSuite{}) func (s *RemoteSuite) TestNewRemote(c *C) { - r, err := NewRemote(RepositoryFixture) + r, err := NewRemote("foo", RepositoryFixture) c.Assert(err, IsNil) + c.Assert(r.Name, Equals, "foo") c.Assert(r.Endpoint.String(), Equals, RepositoryFixture) } func (s *RemoteSuite) TestNewRemoteInvalidEndpoint(c *C) { - r, err := NewRemote("qux") + r, err := NewRemote("foo", "qux") c.Assert(err, NotNil) c.Assert(r, IsNil) } func (s *RemoteSuite) TestNewRemoteInvalidSchemaEndpoint(c *C) { - r, err := NewRemote("qux://foo") + r, err := NewRemote("foo", "qux://foo") c.Assert(err, NotNil) c.Assert(r, IsNil) } func (s *RemoteSuite) TestNewAuthenticatedRemote(c *C) { a := &http.BasicAuth{} - r, err := NewAuthenticatedRemote(RepositoryFixture, a) + r, err := NewAuthenticatedRemote("foo", RepositoryFixture, a) c.Assert(err, IsNil) + c.Assert(r.Name, Equals, "foo") c.Assert(r.Endpoint.String(), Equals, RepositoryFixture) c.Assert(r.Auth, Equals, a) } func (s *RemoteSuite) TestConnect(c *C) { - r, err := NewRemote(RepositoryFixture) + r, err := NewRemote("foo", RepositoryFixture) c.Assert(err, IsNil) c.Assert(r.Connect(), IsNil) } func (s *RemoteSuite) TestInfo(c *C) { - r, err := NewRemote(RepositoryFixture) + r, err := NewRemote("foo", RepositoryFixture) c.Assert(err, IsNil) c.Assert(r.Info(), IsNil) c.Assert(r.Connect(), IsNil) @@ -56,7 +58,7 @@ func (s *RemoteSuite) TestInfo(c *C) { } func (s *RemoteSuite) TestDefaultBranch(c *C) { - r, err := NewRemote(RepositoryFixture) + r, err := NewRemote("foo", RepositoryFixture) r.upSrv = &MockGitUploadPackService{} c.Assert(err, IsNil) @@ -65,7 +67,7 @@ func (s *RemoteSuite) TestDefaultBranch(c *C) { } func (s *RemoteSuite) TestCapabilities(c *C) { - r, err := NewRemote(RepositoryFixture) + r, err := NewRemote("foo", RepositoryFixture) r.upSrv = &MockGitUploadPackService{} c.Assert(err, IsNil) @@ -74,38 +76,27 @@ func (s *RemoteSuite) TestCapabilities(c *C) { } func (s *RemoteSuite) TestFetch(c *C) { - r, err := NewRemote(RepositoryFixture) + r, err := NewRemote("foo", RepositoryFixture) r.upSrv = &MockGitUploadPackService{} c.Assert(err, IsNil) c.Assert(r.Connect(), IsNil) sto := memory.NewObjectStorage() - err = r.Fetch(sto, &FetchOptions{ - ReferenceName: core.HEAD, + err = r.Fetch(sto, &RemoteFetchOptions{ + References: []*core.Reference{ + core.NewReferenceFromStrings( + "refs/heads/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", + ), + }, }) c.Assert(err, IsNil) c.Assert(sto.Objects, HasLen, 28) } -func (s *RemoteSuite) TestFetchInvalidBranch(c *C) { - r, err := NewRemote(RepositoryFixture) - r.upSrv = &MockGitUploadPackService{} - - c.Assert(err, IsNil) - c.Assert(r.Connect(), IsNil) - - sto := memory.NewObjectStorage() - err = r.Fetch(sto, &FetchOptions{ - ReferenceName: core.ReferenceName("qux"), - }) - - c.Assert(err, NotNil) -} - func (s *RemoteSuite) TestHead(c *C) { - r, err := NewRemote(RepositoryFixture) + r, err := NewRemote("foo", RepositoryFixture) r.upSrv = &MockGitUploadPackService{} c.Assert(err, IsNil) @@ -115,7 +106,7 @@ func (s *RemoteSuite) TestHead(c *C) { } func (s *RemoteSuite) TestRef(c *C) { - r, err := NewRemote(RepositoryFixture) + r, err := NewRemote("foo", RepositoryFixture) r.upSrv = &MockGitUploadPackService{} c.Assert(err, IsNil) @@ -132,7 +123,7 @@ func (s *RemoteSuite) TestRef(c *C) { } func (s *RemoteSuite) TestRefs(c *C) { - r, err := NewRemote(RepositoryFixture) + r, err := NewRemote("foo", RepositoryFixture) r.upSrv = &MockGitUploadPackService{} c.Assert(err, IsNil) diff --git a/repository.go b/repository.go index 9e34dad..b17bbea 100644 --- a/repository.go +++ b/repository.go @@ -2,6 +2,7 @@ package git import ( "errors" + "io" "gopkg.in/src-d/go-git.v4/clients/common" "gopkg.in/src-d/go-git.v4/core" @@ -15,11 +16,6 @@ var ( ErrObjectNotFound = errors.New("object not found") ) -const ( - // DefaultRemoteName name of the default Remote, just like git command - DefaultRemoteName = "origin" -) - // Repository giturl string, auth common.AuthMethod repository struct type Repository struct { Remotes map[string]*Remote @@ -48,10 +44,10 @@ func NewRepository(s core.Storage) (*Repository, error) { } // Clone clones a remote repository -func (r *Repository) Clone(o *CloneOptions) error { +func (r *Repository) Clone(o *RepositoryCloneOptions) error { o.Default() - remote, err := r.createDefaultRemote(o.URL, o.Auth) + remote, err := r.createRemote(o.RemoteName, o.URL, o.Auth) if err != nil { return err } @@ -60,33 +56,98 @@ func (r *Repository) Clone(o *CloneOptions) error { return err } - err = remote.Fetch(r.s.ObjectStorage(), &FetchOptions{ReferenceName: o.ReferenceName}) + var single core.ReferenceName + if o.SingleBranch { + single = o.ReferenceName + } + + head, err := remote.Ref(o.ReferenceName, true) + if err != nil { + return err + } + + refs, err := r.getRemoteRefences(remote, single) if err != nil { return err } - ref, err := remote.Ref(o.ReferenceName, true) + err = remote.Fetch(r.s.ObjectStorage(), &RemoteFetchOptions{ + References: refs, + Depth: o.Depth, + }) + if err != nil { return err } - return r.createDefaultBranch(ref) + if err := r.createLocalReferences(head); err != nil { + return err + } + + return r.createRemoteReferences(remote, refs) } -func (r *Repository) createDefaultRemote(url string, auth common.AuthMethod) (*Remote, error) { - remote, err := NewAuthenticatedRemote(url, auth) +func (r *Repository) createRemote(name, url string, auth common.AuthMethod) (*Remote, error) { + remote, err := NewAuthenticatedRemote(name, url, auth) if err != nil { return nil, err } - r.Remotes = map[string]*Remote{ - DefaultRemoteName: remote, + r.Remotes = map[string]*Remote{name: remote} + return remote, nil +} + +func (r *Repository) getRemoteRefences( + remote *Remote, single core.ReferenceName, +) ([]*core.Reference, error) { + if single == "" { + return r.getAllRemoteRefences(remote) } - return remote, nil + ref, err := remote.Ref(single, true) + if err != nil { + return nil, err + } + + refs := []*core.Reference{ref} + head, err := remote.Ref(core.HEAD, false) + if err != nil { + return nil, err + } + + if head.Target() == ref.Name() { + refs = append(refs, head) + } + + return refs, nil +} + +func (r *Repository) getAllRemoteRefences(remote *Remote) ([]*core.Reference, error) { + var refs []*core.Reference + i := remote.Refs() + defer i.Close() + + for { + ref, err := i.Next() + if err != nil { + if err == io.EOF { + break + } + + return nil, err + } + + if !ref.IsBranch() { + continue + } + + refs = append(refs, ref) + } + + return refs, nil } -func (r *Repository) createDefaultBranch(ref *core.Reference) error { +func (r *Repository) createLocalReferences(ref *core.Reference) error { if !ref.IsBranch() { // detached HEAD mode head := core.NewHashReference(core.HEAD, ref.Hash()) @@ -101,6 +162,38 @@ func (r *Repository) createDefaultBranch(ref *core.Reference) error { return r.s.ReferenceStorage().Set(head) } +func (r *Repository) createRemoteReferences(remote *Remote, remoteRefs []*core.Reference) error { + for _, ref := range remoteRefs { + if err := r.createRemoteReference(remote, ref); err != nil { + return err + } + } + + return nil +} + +func (r *Repository) createRemoteReference(remote *Remote, ref *core.Reference) error { + name := ref.Name().AsRemote(remote.Name) + + var n *core.Reference + switch ref.Type() { + case core.HashReference: + n = core.NewHashReference(name, ref.Hash()) + case core.SymbolicReference: + n = core.NewSymbolicReference(name, ref.Target().AsRemote(remote.Name)) + target, err := remote.Ref(ref.Target(), false) + if err != nil { + return err + } + + if err := r.createRemoteReference(remote, target); err != nil { + return err + } + } + + return r.s.ReferenceStorage().Set(n) +} + // Commit return the commit with the given hash func (r *Repository) Commit(h core.Hash) (*Commit, error) { obj, err := r.s.ObjectStorage().Get(h) diff --git a/repository_test.go b/repository_test.go index 80bd0d1..c2b2ff2 100644 --- a/repository_test.go +++ b/repository_test.go @@ -76,7 +76,7 @@ func (s *RepositorySuite) TestClone(c *C) { c.Assert(err, Equals, core.ErrReferenceNotFound) c.Assert(head, IsNil) - err = r.Clone(&CloneOptions{ + err = r.Clone(&RepositoryCloneOptions{ URL: RepositoryFixture, }) @@ -94,6 +94,105 @@ func (s *RepositorySuite) TestClone(c *C) { c.Assert(err, IsNil) c.Assert(branch, NotNil) c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") + + branch, err = r.Ref("refs/remotes/origin/HEAD", false) + c.Assert(err, IsNil) + c.Assert(branch, NotNil) + c.Assert(branch.Type(), Equals, core.SymbolicReference) + c.Assert(branch.Target().String(), Equals, "refs/remotes/origin/master") + + branch, err = r.Ref("refs/remotes/origin/master", false) + c.Assert(err, IsNil) + c.Assert(branch, NotNil) + c.Assert(branch.Type(), Equals, core.HashReference) + c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") + + branch, err = r.Ref("refs/remotes/origin/branch", false) + c.Assert(err, IsNil) + c.Assert(branch, NotNil) + c.Assert(branch.Type(), Equals, core.HashReference) + c.Assert(branch.Hash().String(), Equals, "e8d3ffab552895c19b9fcf7aa264d277cde33881") +} + +func (s *RepositorySuite) TestCloneSingleBranchAndNonHEAD(c *C) { + r, err := NewMemoryRepository() + c.Assert(err, IsNil) + + c.Assert(r.Remotes, HasLen, 0) + + head, err := r.Head() + c.Assert(err, Equals, core.ErrReferenceNotFound) + c.Assert(head, IsNil) + + err = r.Clone(&RepositoryCloneOptions{ + URL: RepositoryFixture, + ReferenceName: core.ReferenceName("refs/heads/branch"), + SingleBranch: true, + }) + + c.Assert(err, IsNil) + c.Assert(r.Remotes, HasLen, 1) + c.Assert(r.Remotes[DefaultRemoteName], NotNil) + + head, err = r.Ref(core.HEAD, false) + c.Assert(err, IsNil) + c.Assert(head, NotNil) + c.Assert(head.Type(), Equals, core.SymbolicReference) + c.Assert(head.Target().String(), Equals, "refs/heads/branch") + + branch, err := r.Ref(head.Target(), false) + c.Assert(err, IsNil) + c.Assert(branch, NotNil) + c.Assert(branch.Hash().String(), Equals, "e8d3ffab552895c19b9fcf7aa264d277cde33881") + + branch, err = r.Ref("refs/remotes/origin/branch", false) + c.Assert(err, IsNil) + c.Assert(branch, NotNil) + c.Assert(branch.Type(), Equals, core.HashReference) + c.Assert(branch.Hash().String(), Equals, "e8d3ffab552895c19b9fcf7aa264d277cde33881") +} + +func (s *RepositorySuite) TestCloneSingleBranch(c *C) { + r, err := NewMemoryRepository() + c.Assert(err, IsNil) + + c.Assert(r.Remotes, HasLen, 0) + + head, err := r.Head() + c.Assert(err, Equals, core.ErrReferenceNotFound) + c.Assert(head, IsNil) + + err = r.Clone(&RepositoryCloneOptions{ + URL: RepositoryFixture, + SingleBranch: true, + }) + + c.Assert(err, IsNil) + c.Assert(r.Remotes, HasLen, 1) + c.Assert(r.Remotes[DefaultRemoteName], NotNil) + + head, err = r.Ref(core.HEAD, false) + c.Assert(err, IsNil) + c.Assert(head, NotNil) + c.Assert(head.Type(), Equals, core.SymbolicReference) + c.Assert(head.Target().String(), Equals, "refs/heads/master") + + branch, err := r.Ref(head.Target(), false) + c.Assert(err, IsNil) + c.Assert(branch, NotNil) + c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") + + branch, err = r.Ref("refs/remotes/origin/HEAD", false) + c.Assert(err, IsNil) + c.Assert(branch, NotNil) + c.Assert(branch.Type(), Equals, core.SymbolicReference) + c.Assert(branch.Target().String(), Equals, "refs/remotes/origin/master") + + branch, err = r.Ref("refs/remotes/origin/master", false) + c.Assert(err, IsNil) + c.Assert(branch, NotNil) + c.Assert(branch.Type(), Equals, core.HashReference) + c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") } func (s *RepositorySuite) TestCloneDetachedHEAD(c *C) { @@ -101,7 +200,7 @@ func (s *RepositorySuite) TestCloneDetachedHEAD(c *C) { c.Assert(err, IsNil) c.Assert(r.Remotes, HasLen, 0) - err = r.Clone(&CloneOptions{ + err = r.Clone(&RepositoryCloneOptions{ URL: RepositoryFixture, ReferenceName: core.ReferenceName("refs/tags/v1.0.0"), }) @@ -117,7 +216,7 @@ func (s *RepositorySuite) TestCommit(c *C) { r, err := NewMemoryRepository() c.Assert(err, IsNil) - err = r.Clone(&CloneOptions{ + err = r.Clone(&RepositoryCloneOptions{ URL: RepositoryFixture, }) @@ -139,7 +238,7 @@ func (s *RepositorySuite) TestCommits(c *C) { r, err := NewMemoryRepository() c.Assert(err, IsNil) - err = r.Clone(&CloneOptions{URL: RepositoryFixture}) + err = r.Clone(&RepositoryCloneOptions{URL: RepositoryFixture}) c.Assert(err, IsNil) count := 0 @@ -205,7 +304,7 @@ func (s *RepositorySuite) TestCommitIterClosePanic(c *C) { r, err := NewMemoryRepository() c.Assert(err, IsNil) - err = r.Clone(&CloneOptions{URL: RepositoryFixture}) + err = r.Clone(&RepositoryCloneOptions{URL: RepositoryFixture}) c.Assert(err, IsNil) commits, err := r.Commits() @@ -217,7 +316,7 @@ func (s *RepositorySuite) TestRef(c *C) { r, err := NewMemoryRepository() c.Assert(err, IsNil) - err = r.Clone(&CloneOptions{URL: RepositoryFixture}) + err = r.Clone(&RepositoryCloneOptions{URL: RepositoryFixture}) c.Assert(err, IsNil) ref, err := r.Ref(core.HEAD, false) @@ -233,7 +332,7 @@ func (s *RepositorySuite) TestRefs(c *C) { r, err := NewMemoryRepository() c.Assert(err, IsNil) - err = r.Clone(&CloneOptions{URL: RepositoryFixture}) + err = r.Clone(&RepositoryCloneOptions{URL: RepositoryFixture}) c.Assert(err, IsNil) c.Assert(err, IsNil) |