This repository was archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 534
remote: add support for ls-remote #609
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"gopkg.in/src-d/go-git.v4/config" | ||
"gopkg.in/src-d/go-git.v4/plumbing" | ||
"gopkg.in/src-d/go-git.v4/plumbing/storer" | ||
"gopkg.in/src-d/go-git.v4/plumbing/transport" | ||
"gopkg.in/src-d/go-git.v4/storage" | ||
"gopkg.in/src-d/go-git.v4/storage/filesystem" | ||
"gopkg.in/src-d/go-git.v4/storage/memory" | ||
|
@@ -642,3 +643,41 @@ func (s *RemoteSuite) TestGetHaves(c *C) { | |
c.Assert(err, IsNil) | ||
c.Assert(l, HasLen, 2) | ||
} | ||
|
||
func (s *RemoteSuite) TestLSRemote(c *C) { | ||
url := c.MkDir() | ||
server, err := PlainInit(url, true) | ||
c.Assert(err, IsNil) | ||
|
||
srcFs := fixtures.Basic().One().DotGit() | ||
sto, err := filesystem.NewStorage(srcFs) | ||
c.Assert(err, IsNil) | ||
|
||
remote := newRemote(sto, &config.RemoteConfig{ | ||
Name: DefaultRemoteName, | ||
URLs: []string{url}, | ||
}) | ||
|
||
rs := config.RefSpec("refs/heads/*:refs/heads/*") | ||
err = remote.Push(&PushOptions{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Makes sense. 🙂 |
||
RefSpecs: []config.RefSpec{rs}, | ||
}) | ||
c.Assert(err, IsNil) | ||
|
||
// Perform ls-remote. | ||
var authMethod transport.AuthMethod | ||
refs, err := remote.LSRemote(authMethod) | ||
c.Assert(err, IsNil) | ||
|
||
// Create a map of remote name and their hash. | ||
refsMap := map[string]string{} | ||
for _, rf := range refs { | ||
// Skip the symbolically linked HEAD. | ||
if string(rf.Name()) == "HEAD" { | ||
continue | ||
} | ||
refsMap[string(rf.Name())] = rf.Hash().String() | ||
} | ||
|
||
AssertReferences(c, server, refsMap) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
?Thoughts @mcuadros?
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...