jesseduffield / lazygit

simple terminal UI for git commands
MIT License
47.94k stars 1.72k forks source link

Support regex or globs for MainBranches config #3659

Open a-jentleman opened 2 weeks ago

a-jentleman commented 2 weeks ago

Is your feature request related to a problem? Please describe. My organization's upstream branches change somewhat frequency as different ones are created for each major version of our product we release. It is tedious to update the lazygit configuration to add each new version with each new release.

Describe the solution you'd like I would like to be able to express main branches in configuration via a glob pattern or regular expression.

Describe alternatives you've considered A scheduled job to update the configuration file periodically - seems like overkill

Additional context I would like to develop and submit this PR assuming the overall idea is considered okay to add to this project.

stefanhaller commented 2 weeks ago

I understand the wish, but it's tricky to implement, and I'm concerned about performance and correctness.

To elaborate: we have code that takes the configured main branches and determines which of these actually exist, and what their full refs are. It is important to get this right, because:

The code for this is here, and the logic currently depends on being able to loop over the configured main branches; this would no longer be possible if it's a pattern, so you would have to turn the logic around and loop over the existing branches to see which ones match the pattern. (Probably first over the local branches, and then over the ones in the origin remote to see if there are any there that you didn't come across yet. Or something along those lines, I'd have to think about this longer.)

And the whole thing needs to be as fast as possible. This is tricky because we can't just use the model information about branches that we have in memory, because that's refreshed independently in another background thread and might not be available yet. So we'd have to make our own call to git for-each-ref here, which I'm not sure we can afford just for this.

To sum it up: it might be possible to do, but feels really tricky to me. If you do want to give it a try, I'd suggest to discuss the approach here first and hash out all the details before you start coding.

(Maybe the scheduled job to update the configuration file periodically would be easier after all? 😉)

a-jentleman commented 2 weeks ago

Thank you for the helpful pointers and background. I've done a cursory scan through the code you referenced and cross-referenced it with the background/advice you've provided. I think I've come to a similar appreciation of the potential complexities at play here.

I may circle back and look at this, but think I'll probably look for a different (safer) way to contribute to this project to start and perhaps re-consider after I'm more familiar with the code base. So, if anyone else reads this and has an idea, consider the issue available for the taking :)