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

Support regex or globs for MainBranches config #3659

Open
a-jentleman opened this issue Jun 12, 2024 · 2 comments
Open

Support regex or globs for MainBranches config #3659

a-jentleman opened this issue Jun 12, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@a-jentleman
Copy link
Sponsor

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.

@a-jentleman a-jentleman added the enhancement New feature or request label Jun 12, 2024
@stefanhaller
Copy link
Collaborator

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:

  • if both origin/main and main exist, then origin/main is the result, and we disregard main. This is important because you should be able to rebase onto main by pressing r b without having to bring your local main up to date.
  • the local main branch might track a remote branch on a remote other than origin (e.g. upstream/main), and in that case that's the one we should use.
  • a local main might not even exist, in which case we need to use origin/main if it exists.
  • a local main might exist, but doesn't have an upstream configured (maybe the repo doesn't have any remotes at all); in this case we use the local main.

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
Copy link
Sponsor Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants