-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add ability to configure branch color patterns using regex #4130
Add ability to configure branch color patterns using regex #4130
Conversation
This only seems to support a However, I'm unsure if globbing is the best solution here. I'd rather thought we'd use regular expressions; they are more powerful and flexible, and we already use them for other things in the user config, e.g. commit prefixes. With regular expressions, however, it's a bit harder to maintain backward compatibility transparently. I think for clarity we should add a new config (e.g. |
I'm agree that it would be better to use regular expressions here. On my current place of work we have strict rules about branch naming. So, with power of regular expressions I achieved behavior, when only correctly named branches are highlighted: gui:
branchColorPatterns:
"IDS+-[0-9]+-[^']+$": '#29d1f7' |
Thank you for the feedback @stefanhaller @castlele I'll adjust the pr accordingly. I agree that using regex will give the user a better ability on how to specify the branch rules. |
952535e
to
93bba0a
Compare
pkg/gui/presentation/branches.go
Outdated
var branchPrefixColorCache = make(map[string]style.TextStyle) | ||
type colorMatcher struct { | ||
patterns map[string]style.TextStyle | ||
isRegex bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the new config is replacing the old one I needed a way to know whether a regex pattern was passed or wether I should attempt to match using the old way (by branchType). Once the old method of matching is deprecated this can be removed
pkg/gui/presentation/branches.go
Outdated
} | ||
|
||
// Default colors for common branch types | ||
branchType := strings.Split(name, "/")[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keeping the old default behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jesseduffield How do you feel about removing this default behavior? I find it surprising and annoying. I don't want it, but it's not obvious how to disable it; previously I had to use this to disable it:
gui:
branchColors:
feature: default
bugfix: default
hotfix: default
but if I want to use the new regex patterns now, I have to say
gui:
branchColorPatterns:
"mypattern": "#ff0000"
"^feature/": default
"^bugfix/": default
"^hotfix/": default
This is very non-obvious, and I feel like I shouldn't have to do that.
93bba0a
to
ce827b3
Compare
Had some free time today and updated this pr, let me know if this is closer to what you were imagining @stefanhaller. Given that we have to account for both the new behavior while keeping the old way unchanged it might be a little messy until we deprecate the old behavior. Feel free to suggest any changes, thanks! Here is an image of what it looks like with a sample config: |
For what it's worth, that approach looks good to me (code just needs some more documentation, and to be explicit about the old option being deprecated) |
8f1c64b
to
925e161
Compare
@jesseduffield Added some more documentation and deprecation warnings, let me know if you think anything is missing clarity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @mtrajano. A few thoughts below, looks good to me otherwise.
pkg/gui/presentation/branches.go
Outdated
} | ||
|
||
// Default colors for common branch types | ||
branchType := strings.Split(name, "/")[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jesseduffield How do you feel about removing this default behavior? I find it surprising and annoying. I don't want it, but it's not obvious how to disable it; previously I had to use this to disable it:
gui:
branchColors:
feature: default
bugfix: default
hotfix: default
but if I want to use the new regex patterns now, I have to say
gui:
branchColorPatterns:
"mypattern": "#ff0000"
"^feature/": default
"^bugfix/": default
"^hotfix/": default
This is very non-obvious, and I feel like I shouldn't have to do that.
@stefanhaller Those feature/bugfix/hotfix things are based on 'gitflow' which is now considered legacy by many, so I'm happy to remove those defaults. |
925e161
to
b1620c1
Compare
b1620c1
to
6919b04
Compare
Nice. I took the liberty of separating the removal of the default coloring into a commit of its own, and I added a commit that adds a "breaking changes" popup for the deprecation of the old config and the removal of the default coloring. This looks good to me now; @jesseduffield Any thoughts about deprecation comments? |
I added another fixup (e6fa89c) to fix a test failure. I'm not sure this is the best way to fix it; alternatively we could put an @mtrajano This makes me realize that |
@mtrajano Oh, and could you update the PR description please? It is out of date. |
Yes I also thought the naming choice was weird (nothing to do with caching) but kept it the same since it has the same behavior as before. I can rename this to |
Works for me. |
e6fa89c
to
1834be5
Compare
Updated the PR description and renamed the variable let me know if that looks good |
I'm sorry it's possible I overwrote this commit with my last push, let me see if I can add the same |
Was there anything else you changed or just the test? |
You lost all my work, which is a bit annoying to be honest. I did this to save time, not to waste time. 😉 Maybe it's unexpected for contributors to get stuff pushed to their branch by maintainers, but we actually do this all the time, so you need to be careful not to blindly force-push. I'll recover my things from the reflog and force-push again, hang on a minute... |
1834be5
to
ac71ae4
Compare
Ok, I force-pushed again, please pull. My changes are:
(I mentioned all of these above...) |
Looks good now, thankfully wasn't a huge set of changes but yes reflog always does the trick 🙏 Let me know if there's anything else needed to get this merged, thanks for the helpful comments |
I added another fixup for updating the config schema (CI failed because of this). One thing I'm wondering is whether we should explicitly mention that the regex patterns are not anchored, and that users need to do that themselves if they want an exact match for example. |
Yes I think it's worth mentioning, this behavior felt counter intuitive to me as mentioned here #4130 (comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything here looks good to me except for the tense of 'deprecation': the comments say that the old config will be deprecated in the future but in reality it's deprecated as of right now: it will be removed in the future.
As an aside, I wonder if it would be good to rename BranchColors to DeprecatedBranchColors (and do the same in future for other deprecated config values) so that it's borderline impossible for a contributor to accidentally use the wrong one. Consider that in gui.go in this PR, the comment wouldn't be necessary if it was called DeprecatedBranchColors
@jesseduffield I don't think the config rename is a good idea, it will break a bunch of users configs unexpectedly with a simple commit change. They can keep using the current version until a major version is released in which case the old config value can be just be removed entirely. IMO having the notice as part of a changelog or some sort of upgrade guide is enough and is usually the standard other applications follow. Thoughts @stefanhaller ? |
To be clear I'm not suggesting that we change the name that the user uses (i.e. |
Oh yes in that case it can make sense to serve as a reminder for the maintainers in the future 👍 |
I'm mildly opposed to renaming the field. It's always slightly confusing when a config variable has a name that's different from the user-facing yaml name, and I would only do that if there's a really strong reason for it. In this case, I don't see a big risk that future contributors will continue to use the old field for new code; I'm having a hard time imagining what kind of code that would be. Not a super strong opinion, so if you both think we should rename it, I'd be fine with that. |
I don't have a strong opinion, so happy to leave the code as-is |
fd63d98
to
1114106
Compare
I just rebased this branch again since it was out of date. Anything else I'm missing to get this one merged? |
I was meaning to add a few more documentation tweaks, but didn't get around to it yet. I hope to find some time for this tomorrow. |
We used to automatically color branches starting with "feature/", "bugfix/", or "hotfix/". For those who don't want this, it's a bit non-obvious to turn off, but it's actually pretty easy to configure manually for those who want this, so we just remove this default coloring.
1114106
to
1c4b10a
Compare
I tweaked the documentation again to fix the tense of 'deprecation' as @jesseduffield asked for above, and to make it consistent with other deprecated configs. I also removed the documentation of the old config from Config.md; I don't think we need to document deprecated configs. @jesseduffield Wanna have a final look before I merge? |
@stefanhaller I've pushed another commit updating the tense in a couple other places. LGTM |
9ff5d6c
to
c64a790
Compare
@jesseduffield Thanks, squashed it in |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.44.1` -> `v0.45.2` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary> ### [`v0.45.2`](https://github.com/jesseduffield/lazygit/releases/tag/v0.45.2) [Compare Source](jesseduffield/lazygit@v0.45.0...v0.45.2) <!-- Release notes generated using configuration in .github/release.yml at v0.45.2 --> #### What's Changed ##### Enhancements 🔥 - Add ability to configure branch color patterns using regex by [@​mtrajano](https://github.com/mtrajano) in jesseduffield/lazygit#4130 - Collapse/uncollapse all files in tree by [@​mtrajano](https://github.com/mtrajano) in jesseduffield/lazygit#4131 - Improve undo action to restore files upon undoing a commit by [@​gabriellanata](https://github.com/gabriellanata) in jesseduffield/lazygit#4167 ##### Fixes 🔧 - Bump gocui (and tcell) by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4166 ##### Maintenance ⚙️ - Cut a new release automatically each month by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4146 - Bump tcell to fix broken deployment by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4178 #### New Contributors - [@​mtrajano](https://github.com/mtrajano) made their first contribution in jesseduffield/lazygit#4130 - [@​gabriellanata](https://github.com/gabriellanata) made their first contribution in jesseduffield/lazygit#4167 **Full Changelog**: jesseduffield/lazygit@v0.45.0...v0.45.2 ### [`v0.45.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.45.0) [Compare Source](jesseduffield/lazygit@v0.44.1...v0.45.0) <!-- Release notes generated using configuration in .github/release.yml at v0.45.0 --> Lots of great improvements in this one! Thanks to all the contributors who helped make this release happen. Apologies for the long waits between releases. As of jesseduffield/lazygit#4146 we're now (almost) guaranteed to do monthly releases. #### What's Changed ##### Enhancements 🔥 - Better branch delete confirmation by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3915 - Add a menu item to delete both local and remote branch at once by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3916 - Auto-render hyperlinks by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3914 - Allow pasting commits multiple times by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3983 - Add config option to disable switching tabs with panel jump keys (and disable by default) by [@​hgreenstein](https://github.com/hgreenstein) in jesseduffield/lazygit#3927 - We jumped the gun on this change in the last release: having the number key both select a panel and switch tabs was bad for muscle memory so it's that behaviour is now disabled by default. - Add new filter to only show tracked files in Files panel by [@​veremenko-y](https://github.com/veremenko-y) in jesseduffield/lazygit#4024 - Allow DiffContextSize to be decreased to zero by [@​LuxxxLucy](https://github.com/LuxxxLucy) in jesseduffield/lazygit#4050 - Allow user to select remote and branch when creating a MR by [@​moha-gh](https://github.com/moha-gh) in jesseduffield/lazygit#1889 - Delete range selection of branches by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4073 - Show the number of lines changed per file in working file tree view by [@​johannaschwarz](https://github.com/johannaschwarz) in jesseduffield/lazygit#4015 - Drop merge commits by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4094 - Wrap lines in staging view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4098 - Allow to switch branches in Commit View ([#​4115](jesseduffield/lazygit#4115)) by [@​seflue](https://github.com/seflue) in jesseduffield/lazygit#4117 - Allow on prem Azure DevOps Server pull request by [@​waynebowie99](https://github.com/waynebowie99) in jesseduffield/lazygit#3954 - Add screen-mode command line argument by [@​alewis001](https://github.com/alewis001) in jesseduffield/lazygit#4103 - Default to half-screen mode when opening with certain CLI args by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4141 - Show the alt-enter keybinding at bottom of commit description view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4136 - Add number of commits to cherry-pick confirmation prompt by [@​brandondong](https://github.com/brandondong) in jesseduffield/lazygit#4158 ##### Fixes 🔧 - Fix copying commit author to clipboard by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3936 - Fix merge conflict resolution when file doesn't end with a LF by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3976 - Fix file icons by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3975 - Fix non-sticky range select after clicking in staging view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3998 - Fix scroll position when entering staging view by clicking in the main view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3992 - Fix mouse wheel scrolling of custom patch view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4089 - Improve editing a commit by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4090 - Use custom context size in range diff by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4082 - commits panel: add missing default sort order by [@​phanirithvij](https://github.com/phanirithvij) in jesseduffield/lazygit#4097 - Fix issues with opening links and files using WSL by [@​bottino](https://github.com/bottino) in jesseduffield/lazygit#3850 - Fix moving a commit across a branch boundary in a stack of branches by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4096 - Don't preserve commit message when it's unchanged from initial message by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4110 - Fix hang when returning from shell command by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4126 - Prevent killing of unrelated processes on windows by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4137 - Add worktree option to fast forwarding operation by [@​john-mutuma](https://github.com/john-mutuma) in jesseduffield/lazygit#4051 - Don't show keybindings option in bottom line when panel is open by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4143 - Fix reset/rebase to upstream by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4151 - Avoid blank line at end of view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4152 - Adjust line number for working copy when editing a line by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4119 - Fix `micro` editor preset by [@​kytta](https://github.com/kytta) in jesseduffield/lazygit#4156 - Use interactive shell for running shell commands only if shell is bash or zsh by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4159 ##### Maintenance ⚙️ - Add performance improvements section to release notes by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#3922 - ci: update `upload-artifact` and `download-artifact` actions to v4 by [@​Juneezee](https://github.com/Juneezee) in jesseduffield/lazygit#4063 - Let schema/config.json end with a line feed by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4092 - Saner view geometry by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4085 - Cleanup background fetch by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4084 - remove duplicate secondary MouseWheelUp keybind by [@​samueldominguez](https://github.com/samueldominguez) in jesseduffield/lazygit#4120 - enhancement: Use HEX colors on file icons instead of C256 colors by [@​hasecilu](https://github.com/hasecilu) in jesseduffield/lazygit#4029 - chore: use errors.New to replace fmt.Errorf with no parameters by [@​RiceChuan](https://github.com/RiceChuan) in jesseduffield/lazygit#4107 - Fix typos by [@​NathanBaulch](https://github.com/NathanBaulch) in jesseduffield/lazygit#3920 - Bump crypto and net packages by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4144 - Tweak file icons by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4145 - Standardise on 'screen mode' naming convention by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4142 ##### Docs 📖 - Fix installation for Ubuntu in README.md by [@​shaobosong](https://github.com/shaobosong) in jesseduffield/lazygit#4031 - Fixes to lazygit Ubuntu install instructions in README.md by [@​wrecklass](https://github.com/wrecklass) in jesseduffield/lazygit#3970 - Fix typos by [@​skoch13](https://github.com/skoch13) in jesseduffield/lazygit#4121 - Add vision and design principles doc by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4053 - docs: Stylize and correct the NixOS section in README.md by [@​wadsaek](https://github.com/wadsaek) in jesseduffield/lazygit#4135 - Update chinese translation for pull requests by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4140 - Set repology table to 3 columns by [@​hasecilu](https://github.com/hasecilu) in jesseduffield/lazygit#4138 - Update instructions for using OSC52 with tmux by [@​EliasA5](https://github.com/EliasA5) in jesseduffield/lazygit#3597 - Update docs to describe use of custom commands without keybindings by [@​a-jentleman](https://github.com/a-jentleman) in jesseduffield/lazygit#3846 - documentation - describe os.openLink by [@​smangels](https://github.com/smangels) in jesseduffield/lazygit#3094 - Clarify commit message prefix mechanics by [@​zeromask1337](https://github.com/zeromask1337) in jesseduffield/lazygit#4114 #### New Contributors - [@​shaobosong](https://github.com/shaobosong) made their first contribution in jesseduffield/lazygit#4031 - [@​hgreenstein](https://github.com/hgreenstein) made their first contribution in jesseduffield/lazygit#3927 - [@​wrecklass](https://github.com/wrecklass) made their first contribution in jesseduffield/lazygit#3970 - [@​veremenko-y](https://github.com/veremenko-y) made their first contribution in jesseduffield/lazygit#4024 - [@​LuxxxLucy](https://github.com/LuxxxLucy) made their first contribution in jesseduffield/lazygit#4050 - [@​phanirithvij](https://github.com/phanirithvij) made their first contribution in jesseduffield/lazygit#4097 - [@​bottino](https://github.com/bottino) made their first contribution in jesseduffield/lazygit#3850 - [@​johannaschwarz](https://github.com/johannaschwarz) made their first contribution in jesseduffield/lazygit#4015 - [@​samueldominguez](https://github.com/samueldominguez) made their first contribution in jesseduffield/lazygit#4120 - [@​skoch13](https://github.com/skoch13) made their first contribution in jesseduffield/lazygit#4121 - [@​wadsaek](https://github.com/wadsaek) made their first contribution in jesseduffield/lazygit#4135 - [@​seflue](https://github.com/seflue) made their first contribution in jesseduffield/lazygit#4117 - [@​waynebowie99](https://github.com/waynebowie99) made their first contribution in jesseduffield/lazygit#3954 - [@​EliasA5](https://github.com/EliasA5) made their first contribution in jesseduffield/lazygit#3597 - [@​alewis001](https://github.com/alewis001) made their first contribution in jesseduffield/lazygit#4103 - [@​a-jentleman](https://github.com/a-jentleman) made their first contribution in jesseduffield/lazygit#3846 - [@​john-mutuma](https://github.com/john-mutuma) made their first contribution in jesseduffield/lazygit#4051 - [@​RiceChuan](https://github.com/RiceChuan) made their first contribution in jesseduffield/lazygit#4107 - [@​NathanBaulch](https://github.com/NathanBaulch) made their first contribution in jesseduffield/lazygit#3920 **Full Changelog**: jesseduffield/lazygit@v0.44.1...v0.45.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMzcuMSIsInVwZGF0ZWRJblZlciI6IjM5LjEzNy4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Add ability to specify color patterns in the
branchColorPatterns
config using regex, ex.JIRA-\d+
would match all branch names in the formJIRA-456
.Example config:
go generate ./...
)