Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

remote: add support for ls-remote #609

Merged
merged 3 commits into from
Oct 4, 2017
Merged

Conversation

darkowlzz
Copy link
Contributor

@darkowlzz darkowlzz commented Oct 2, 2017

Adds support for ls-remote in Remote.

Found this in #601-comment, so maybe fixes #601 .

Need some guidance in the test with relevant existing examples. Not sure if this test is enough.

remote.go Outdated
@@ -728,6 +728,39 @@ func (r *Remote) buildFetchedTags(refs memory.ReferenceStorage) (updated bool, e
return
}

// LSRemote performs ls-remote on the remote.
func (r *Remote) LSRemote(auth transport.AuthMethod) ([]*plumbing.Reference, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should call this method List?

// List the references on the remote repository

Thoughts @mcuadros?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, does it make sense to generalize the parameters so that it accepts an Options-style struct instead of just transport.AuthMethod to help ease future changes without breaking API compatibility?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, a Options will be the best

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, makes sense. I created an Option at first, but then dropped it thinking it would be simpler to just pass the AuthMethod directly 😅. Adding it back...

@codecov
Copy link

codecov bot commented Oct 3, 2017

Codecov Report

Merging #609 into master will decrease coverage by 0.61%.
The diff coverage is 64.7%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #609      +/-   ##
=========================================
- Coverage   78.32%   77.7%   -0.62%     
=========================================
  Files         130     130              
  Lines       10140   10160      +20     
=========================================
- Hits         7942    7895      -47     
- Misses       1347    1423      +76     
+ Partials      851     842       -9
Impacted Files Coverage Δ
options.go 85.48% <ø> (ø) ⬆️
remote.go 73.63% <64.7%> (-0.65%) ⬇️
plumbing/transport/ssh/common.go 20.54% <0%> (-45.21%) ⬇️
plumbing/transport/ssh/auth_method.go 31.57% <0%> (-22.81%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30a99a2...b8eac90. Read the comment docs.

remote_test.go Outdated
})

rs := config.RefSpec("refs/heads/*:refs/heads/*")
err = remote.Push(&PushOptions{
Copy link
Contributor

@orirawlings orirawlings Oct 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Push and List will basically use the same code under the hood, we are sort of asserting this code's behavior against itself.

Maybe it makes for sense to explicitly define the expected references for this fixture repository? Also this gives us a chance to assert that symbolic references are handled properly rather than ignoring them.

func (s *RemoteSuite) TestList(c *C) {
        repo := fixtures.Basic().One()
        remote := newRemote(memory.NewStorage(), &config.RemoteConfig{
                Name: DefaultRemoteName,
                URLs: []string{repo.URL},
        })

        refs, err := remote.List(&ListOptions{})
        c.Assert(err, IsNil)

        expected := []*plumbing.Reference{
                plumbing.NewSymbolicReference("HEAD", "refs/heads/master"),
                plumbing.NewReferenceFromStrings("refs/heads/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
                plumbing.NewReferenceFromStrings("refs/heads/branch", "e8d3ffab552895c19b9fcf7aa264d277cde33881"),
                plumbing.NewReferenceFromStrings("refs/pull/1/head", "b8e471f58bcbca63b07bda20e428190409c2db47"),
                plumbing.NewReferenceFromStrings("refs/pull/2/head", "9632f02833b2f9613afb5e75682132b0b22e4a31"),
                plumbing.NewReferenceFromStrings("refs/pull/2/merge", "c37f58a130ca555e42ff96a071cb9ccb3f437504"),
        }
        c.Assert(len(refs), Equals, len(expected))
        for _, e := range expected {
                found := false
                for _, r := range refs {
                        if r.Name() == e.Name() {
                                found = true
                                c.Assert(r, DeepEquals, e)
                        }
                }
                c.Assert(found, Equals, true)
        }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Makes sense. 🙂

@mcuadros mcuadros merged commit a99c129 into src-d:master Oct 4, 2017
@smola smola mentioned this pull request Dec 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get all remote branches
3 participants