More sanitized branch options#2665
More sanitized branch options#2665Zombiefleischer wants to merge 6 commits intojesseduffield:masterfrom
Conversation
| git *commands.GitCommand, | ||
| contexts *context.ContextTree, | ||
| model *types.Model, | ||
| config *config.UserConfig, |
There was a problem hiding this comment.
no need to pass this in because the config already lives in HelperCommon, so you can use self.c.UserConfig
jesseduffield
left a comment
There was a problem hiding this comment.
left a comment. Also, be sure to update the docs/Config.md doc
jesseduffield
left a comment
There was a problem hiding this comment.
Left another comment. Also, could we add an integration test for this? I.e. start a lazygit session, create a branch, observe that the created branch has the expected name.
| return strings.Replace(input, " ", "-", -1) | ||
| func (self *RefsHelper) sanitizedBranchName(input string) string { | ||
| reg1 := regexp.MustCompile(`^-+`) | ||
| reg2 := regexp.MustCompile(`\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$|\[|\]$`) |
There was a problem hiding this comment.
This regex feels like overkill to me. I would just have a slice of characters that we want to replace with hyphens one-to-one. The .lock thing is too presumptuous so let's remove that.
There was a problem hiding this comment.
I copied this regex from vscode, but I can remove that part.
|
Sorry it's taken me so long to review this. I've taken a closer look and now understand why the original regex had .lock: git's docs explicitly call that out as invalid. I'm happy to use the vscode regex in that case, though the code can be cleaner i.e.: Unfortunately the code has diverged quite a lot from the main branch. Would you still be open to continuing with this @Zombiefleischer ? If not, @raulhammerl offered to pick it up in the issue |
jesseduffield
left a comment
There was a problem hiding this comment.
marking as changes requested for my own bookkeeping
PR Description
Added more sanitizing to branch names:
Please check if the PR fulfills these requirements
go run scripts/cheatsheet/main.go generate)docs/Config.md) have been updated if necessaryCloses #2663