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

Predefined commit messages #760

Closed
kristijanhusak opened this issue Mar 27, 2020 · 4 comments
Closed

Predefined commit messages #760

kristijanhusak opened this issue Mar 27, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@kristijanhusak
Copy link
Contributor

kristijanhusak commented Mar 27, 2020

Is your feature request related to a problem? Please describe.
It would be good to have an option to set predefined commit messages per repository. For example, at work, we use Jira, and we prefix all the commits with ticket number, and also all branch names contains the ticket number, for example:

  • Branch name - feature/AB-123
  • Commit name - [AB-123] Adding a feature.
    Sometime it happens that i mistype the ticket number in the commit. It can be fixed of course, but why not fix the cause if possible :)

Describe the solution you'd like
I assume this could be part of the global configuration, or maybe to introduce project local configuration (.lazygitrc maybe?) If there's better idea, let me know.
For example, configuration could have something like a defined parser that would know how to extract AB-123 and set it as default value for commit message when opened. This is a bit tricky because parsing needs to be done using some language.

Describe alternatives you've considered
Since i'm a vim user, I set up an VimEnter autocommand that checks if i'm editing a commit message, and then parse the value from the branch and append it. It works fairly well, but i mostly use lazygit commit messages.
Here's link to vim code if you are interested: https://github.com/kristijanhusak/neovim-config/blob/master/nvim/partials/filetype/gitcommit.vim

This is maybe too big of a hassle for such a small feature, but i'm open for suggestions.

@kristijanhusak kristijanhusak added the enhancement New feature or request label Mar 27, 2020
@jesseduffield
Copy link
Owner

though I don't personally do this, there are people at my work who do and it's quite possible I'll have to start doing it as well so I'm very open to this :)

I think the solution is for the user to specify on a per-repo basis a regex replace, so something like:

pattern: "^\w+\/(\w+-\w+)"
replace: "$1: "

and if the pattern doesn't match the user can specify fallback patterns as well. As for where to put it, I think it's find to just put it in the config.yml file we already have. What are your thoughts?

@kristijanhusak
Copy link
Contributor Author

Yeah, that looks good. I totally forgot about regex placeholders :-)
Config.yml is fine, but it would be great to have it project specific, or maybe a different commit mapping that will execute the pattern.

@lordlycastle
Copy link

lordlycastle commented Jun 10, 2020

According to docs:

git:
    commitPrefixes:
      my_project: # This is repository folder name
        pattern: "^\\w+\\/(\\w+-\\w+)"
        replace: "[$1] "

How do we specify regex for project name? Otherwise we need to repeat for every repo? Or does it look at full path of folder; in that case I could use path till root repos folder?

But would prefer to use regex for project folder names so something like this would be cool.

git:
    commitPrefixes:
      GitHub: # A category
        name: ".*"
        path: ".*/github/.*".  # so for all repos that have 'github' in their path
        pattern: "^\\w+\\/(\\w+-\\w+)"
        replace: "[$1] "
      Azure: # A category
        name: "ESH.*"  # for all repos that start with 'ESH' prefix
        path: ".*".  # so for all repos paths
        pattern: "^feature/(#\d+)-.*"   # all branches that start with 'feature/#123-...'
        replace: "[$1] "

Should I create a new issues if this isn't supported, otherwise can we please update config.md?


@jesseduffield
Copy link
Owner

@lordlycastle please raise a separate issue for this. If you're interested, the current code is in handleCommitPress in pkg/gui/files_panel.go

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

3 participants