Skip to content

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

@0x0000001c

Description

@0x0000001c

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is neededno-autocloseIssues/PRs to be ignored by stale bot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions