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

Conversation

dshemin
Copy link

@dshemin dshemin commented Jan 24, 2024

Hi!

I had used this package in my project and found this annoying issue. I have a Remote with specific name and have to provide it again in PushOptions.

remote.go Outdated
@@ -101,7 +101,7 @@ 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 err := o.Validate(); err != nil {
if err := o.Validate(r.c.Name); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of changing PushOptions.Validate why didn't you go for the simpler solution of doing:

Suggested change
if err := o.Validate(r.c.Name); err != nil {
// If the PushOptions don't have a remote name set - just default them to this remote for ease of use
if o.RemoteName == "" {
o.RemoteName = r.c.Name
}
if err := o.Validate(); err != nil {

Then this PR would reduce considerably in size.


One issue with both of these approaches is that the PushOptions are passed in as a pointer so any changes here permanently change the object meaning that if the PushOptions are reused then the result will be different depending on who used them first.

This isn't ideal and perhaps indicates that the Valdate option shouldn't really be changing the struct or it should be returning a duplicate with the default values set, but given that it does it might be that this PR may be inadvisable.

Copy link
Author

Choose a reason for hiding this comment

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

I've got you point. I will change.

Copy link
Author

Choose a reason for hiding this comment

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

Another option: don't use RemoteName from PushOptions at all. Or create RemotePushOption struct without RemoteName field.

Copy link
Author

Choose a reason for hiding this comment

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

Can anyone help me with failed tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants