Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git: remote, fix default remote name #1009

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ func (s *OptionsSuite) TestCreateTagOptionsLoadGlobal(c *C) {
c.Assert(o.Tagger.Email, Equals, "foo@foo.com")
}

func (s *OptionsSuite) TestPushOptionsValidateDefaults(c *C) {
o := &PushOptions{}

err := o.Validate()
c.Assert(err, IsNil)

c.Assert(o.RemoteName, Equals, DefaultRemoteName)
c.Assert(o.RefSpecs, DeepEquals, []config.RefSpec{
config.RefSpec(config.DefaultPushRefSpec),
})
}

func (s *OptionsSuite) writeGlobalConfig(c *C, cfg *config.Config) func() {
fs, clean := s.TemporalFilesystem()

Expand Down
32 changes: 16 additions & 16 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (r *Remote) Push(o *PushOptions) error {
// operation is complete, an error is returned. The context only affects the
// transport operations.
func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
if o.RemoteName == "" {
o.RemoteName = r.c.Name
}

if err := o.Validate(); err != nil {
return err
}
Expand All @@ -109,10 +113,6 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
return fmt.Errorf("remote names don't match: %s != %s", o.RemoteName, r.c.Name)
}

if o.RemoteURL == "" {
o.RemoteURL = r.c.URLs[0]
}

s, err := newSendPackSession(o.RemoteURL, o.Auth, o.InsecureSkipTLS, o.CABundle, o.ProxyOptions)
if err != nil {
return err
Expand Down Expand Up @@ -334,7 +334,6 @@ func (r *Remote) newReferenceUpdateRequest(
}

if err := r.addReferencesToUpdate(o.RefSpecs, localRefs, remoteRefs, req, o.Prune, o.ForceWithLease); err != nil {

return nil, err
}

Expand All @@ -350,7 +349,6 @@ func (r *Remote) newReferenceUpdateRequest(
func (r *Remote) updateRemoteReferenceStorage(
req *packp.ReferenceUpdateRequest,
) error {

for _, spec := range r.c.Fetch {
for _, c := range req.Commands {
if !spec.Match(c.Name) {
Expand Down Expand Up @@ -548,8 +546,8 @@ func newClient(url string, insecure bool, cabundle []byte, proxyOpts transport.P
}

func (r *Remote) fetchPack(ctx context.Context, o *FetchOptions, s transport.UploadPackSession,
req *packp.UploadPackRequest) (err error) {

req *packp.UploadPackRequest,
) (err error) {
reader, err := s.UploadPack(ctx, req)
if err != nil {
if errors.Is(err, transport.ErrEmptyUploadPackRequest) {
Expand Down Expand Up @@ -647,7 +645,8 @@ func (r *Remote) deleteReferences(rs config.RefSpec,
remoteRefs storer.ReferenceStorer,
refsDict map[string]*plumbing.Reference,
req *packp.ReferenceUpdateRequest,
prune bool) error {
prune bool,
) error {
iter, err := remoteRefs.IterReferences()
if err != nil {
return err
Expand Down Expand Up @@ -683,8 +682,8 @@ func (r *Remote) deleteReferences(rs config.RefSpec,

func (r *Remote) addCommit(rs config.RefSpec,
remoteRefs storer.ReferenceStorer, localCommit plumbing.Hash,
req *packp.ReferenceUpdateRequest) error {

req *packp.ReferenceUpdateRequest,
) error {
if rs.IsWildcard() {
return errors.New("can't use wildcard together with hash refspecs")
}
Expand Down Expand Up @@ -720,8 +719,8 @@ func (r *Remote) addCommit(rs config.RefSpec,

func (r *Remote) addReferenceIfRefSpecMatches(rs config.RefSpec,
remoteRefs storer.ReferenceStorer, localRef *plumbing.Reference,
req *packp.ReferenceUpdateRequest, forceWithLease *ForceWithLease) error {

req *packp.ReferenceUpdateRequest, forceWithLease *ForceWithLease,
) error {
if localRef.Type() != plumbing.HashReference {
return nil
}
Expand Down Expand Up @@ -816,7 +815,8 @@ func (r *Remote) references() ([]*plumbing.Reference, error) {
}

func getRemoteRefsFromStorer(remoteRefStorer storer.ReferenceStorer) (
map[plumbing.Hash]bool, error) {
map[plumbing.Hash]bool, error,
) {
remoteRefs := map[plumbing.Hash]bool{}
iter, err := remoteRefStorer.IterReferences()
if err != nil {
Expand Down Expand Up @@ -1116,8 +1116,8 @@ func isFastForward(s storer.EncodedObjectStorer, old, new plumbing.Hash, earlies
}

func (r *Remote) newUploadPackRequest(o *FetchOptions,
ar *packp.AdvRefs) (*packp.UploadPackRequest, error) {

ar *packp.AdvRefs,
) (*packp.UploadPackRequest, error) {
req := packp.NewUploadPackRequestFromCapabilities(ar.Capabilities)

if o.Depth != 0 {
Expand Down
12 changes: 12 additions & 0 deletions remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,18 @@ func (s *RemoteSuite) TestPushWrongRemoteName(c *C) {
c.Assert(err, ErrorMatches, ".*remote names don't match.*")
}

func (s *RemoteSuite) TestPushNonDefaultRemoteName(c *C) {
const remoteName = "foo"

r := NewRemote(nil, &config.RemoteConfig{
Name: remoteName,
URLs: []string{"some-url"},
})

err := r.Push(&PushOptions{})
c.Assert(err, ErrorMatches, "repository not found")
}

func (s *RemoteSuite) TestGetHaves(c *C) {
f := fixtures.Basic().One()
sto := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
Expand Down