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 .gitconfig insteadOf rules to Repository.clone() #844

Open
boggyhole opened this issue Sep 22, 2023 · 1 comment · May be fixed by #882
Open

Apply .gitconfig insteadOf rules to Repository.clone() #844

boggyhole opened this issue Sep 22, 2023 · 1 comment · May be fixed by #882
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@boggyhole
Copy link

First of all: Thanks for this project! It's been a very good experience so far!

I took me some time to understand why my url insteadOf rules are not applied to higher level Clone()/PlainClone() commands. As far as I understood insteadOf rules are only applied to existing repositories on .git/config remotes. On my journey through the project I didn't find any reason to not apply global url insteadOf rules (i.e. defined in .gitconfig) to higher level Clone()/PlainClone() functions. I am using something like this:

cloneOpts := &git.CloneOptions{
	URL: repoURL,
}

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

// URL replacements would need to be done manually here

storer := memory.NewStorage()
err = storer.SetConfig(conf)
if err != nil {
	return err
}

fs := memfs.New()
repo, err := git.Clone(storer, fs, cloneOpts)
if err != nil {
	return errors.Wrapf(err, "clone repository '%s'", repoURL)
}

This code won't apply any insteadOf rules from my global config. Am I overlooking something or could url replacement be added to something like: func (r *Repository) CreateRemote(c *config.RemoteConfig) (*Remote, error)?

Thanks for suggestions and hints.

@jazanne
Copy link

jazanne commented Oct 2, 2023

It seems like I may be running into this issue too

I have a script that uses go-git and is run from github actions. However, even verifying that the actions/checkout step uses the github token with correct permissions and persists them to git config, i get this message while trying to fetch remote branches i get a authentication required error.

@pjbgf pjbgf added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed labels Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants