Skip to content

Update default ref to use refs/heads/main#727

Closed
techknowlogick wants to merge 1 commit intogo-git:masterfrom
techknowlogick:main-switch
Closed

Update default ref to use refs/heads/main#727
techknowlogick wants to merge 1 commit intogo-git:masterfrom
techknowlogick:main-switch

Conversation

@techknowlogick
Copy link
Contributor

When creating new repositories, use refs/heads/main as the default ref

Related: charmbracelet/soft-serve#198

@pjbgf
Copy link
Member

pjbgf commented Apr 11, 2023

This is a breaking change, I would rather tackle it in a way that would keep backwards compatibility.

Additionally, I think the behaviour you are trying to achieve could be done using

DefaultBranch string

@techknowlogick
Copy link
Contributor Author

techknowlogick commented Apr 12, 2023

Thanks @pjbgf, yes it is indeed breaking, although it might be considered as breaking to align with changes to git client itself. I understand you have many downstreams you need to consider so I won't advocate for this breaking change past what I have already done.

Sadly, I had also considered the config setting, but the specific issue I am facing can't be set by the default branch config setting. The Init() function: https://github.com/go-git/go-git/blob/master/repository.go#L92 hardcodes master branch when creating a new repo.

I'd be happy to contribute a PR, perhaps to add a similar function, InitWithBranch, where Init would alias to that function but pass in the default of master?

Something like:

func Init(s storage.Storer, worktree billy.Filesystem) (*Repository, error) {
    InitWithBranch(s, worktree, plumbing.Master)
}
func InitWithBranch(s storage.Storer, worktree billy.Filesystem, branch string) (*Repository, error) {
// ...
h := plumbing.NewSymbolicReference(plumbing.HEAD, branch)
// ...

@pjbgf
Copy link
Member

pjbgf commented May 3, 2023

@techknowlogick apologies for the delay. Happy to review a PR on extending Init to support other default branches. I would just make sure you follow the naming convention we use and call it InitWithOptions.

@techknowlogick
Copy link
Contributor Author

Thanks for that suggestion re: existing conventions @pjbgf. I have submitted #764, which is hopefully more suitable :)

@techknowlogick techknowlogick deleted the main-switch branch May 9, 2023 05:02
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.

2 participants