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

apply insteadof on Remote.{fetch,pull,list} functions -- breaking change(?) #882

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BryanStenson-okta
Copy link

@BryanStenson-okta BryanStenson-okta commented Oct 16, 2023

Fixes #844

This applies insteadOf rules to Remote.{fetch,pull,list} functions. This may be seen as a breaking change, as the current behavior does not honor insteadOf values. I believe not applying insteadOf values is actually a bug (#844)...so I'm not sure if this is a "breaking change", or a "bugfix".

I'm open to a discussion on whether this should be gated via feature flag. For example, adding a CloneOptions.ApplyInsteadOf bool -- defaulting to false (to preserve current behavior).

Thoughts?

@boggyhole
Copy link

I am not super familiar with the codebase, yet. This PR solves the clone() issue where url.insteadOf rules weren't applied. Are there other use-cases where it would make sense to get them applied (thinking of submodules for example: func (s *Submodule) Repository()? So my actual question is: would it make sense to move r.ApplyURLRules() to a deeper level? I.e. func (r *Repository) CreateRemote(c *config.RemoteConfig) (*Remote, error)?

@BryanStenson-okta
Copy link
Author

... would it make sense to move r.ApplyURLRules() to a deeper level? I.e. func (r *Repository) CreateRemote(c *config.RemoteConfig) (*Remote, error)?

yup, good point! i'll update that shortly.

@BryanStenson-okta
Copy link
Author

thinking about this more, i think this applying the insteadof substitution logic should happen on the Remote -- so that all fetch, push, etc operations are using substituted urls.

@BryanStenson-okta BryanStenson-okta force-pushed the apply-insteadofs-on-clone branch 2 times, most recently from 1451ee4 to 542c21c Compare October 20, 2023 21:08
call ensureURLRulesApplied() from all Remote.{fetch,push,list}() functions
supporting tests
@BryanStenson-okta BryanStenson-okta changed the title apply insteadof on clone -- breaking change(?) apply insteadof on Remote.{fetch,pull,list} functions -- breaking change(?) Oct 20, 2023
@BryanStenson-okta
Copy link
Author

I've updated this PR to call ensureURLRulesApplied() on each Remote.{fetch,pull,list} function, to ensure the URLs will always be rewritten, if necessary.

@pjbgf pjbgf added this to the v5.11.0 milestone Oct 28, 2023
@pjbgf
Copy link
Member

pjbgf commented Oct 28, 2023

thinking about this more, i think this applying the insteadof substitution logic should happen on the Remote -- so that all fetch, push, etc operations are using substituted urls.

Good shout! One interesting workflow is when URLs are being set directly at the operation options, which I believe would always overwrite the ones from the Remote. I don't think we need to change the code for this, but I would expand on their comments to highlight that InsteadOf rules does not apply to such fields:

RemoteURL string

URL string

We would need tests to that effect.

@pjbgf
Copy link
Member

pjbgf commented Oct 28, 2023

This may be seen as a breaking change, as the current behavior does not honor insteadOf values.

The main challenge here is that as a library, not always you would want to be influenced by system wide configuration. However, I agree with your suggested approach below which would support the new behaviour while keeping backwards compatibility:

adding a CloneOptions.ApplyInsteadOf bool -- defaulting to false (to preserve current behavior).

@boggyhole
Copy link

One interesting workflow is when URLs are being set directly at the operation options, which I believe would always overwrite the ones from the Remote. I don't think we need to change the code for this, but I would expand on their comments to highlight that InsteadOf rules does not apply to such fields:

@pjbgf So would you say that's desired behavior? For my understanding it wouldn't (as I would expect insteadOf rules to be applied to every operation)

The main challenge here is that as a library, not always you would want to be influenced by system wide configuration.

To my understanding it's not the case? From what I've seen one always needs to manually load system wide configuration and apply it to the Storer? Or is there automatic .gitconfig loading for some scenarios?

gitconfig, err := config.LoadConfig(config.GlobalScope)
if err != nil {
	return nil, err
}

if err := storer.SetConfig(gitconfig); err != nil {
	return nil, err
}

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.

Apply .gitconfig insteadOf rules to Repository.clone()
3 participants