google / vimdoc

Helpfile generation for vim
Apache License 2.0
291 stars 29 forks source link

Add .pre-commit-hooks.yaml #123

Closed Freed-Wu closed 2 years ago

Freed-Wu commented 2 years ago

According to https://pre-commit.com/#new-hooks, I write this hook and test it can work for me:

.pre-commit-config.yaml

  - repo: https://github.com/Freed-Wu/vimdoc
    rev: master
    hooks:
      - id: vimdoc

I advice to publish a new version because rev: master is fragile and pre-commit will warn due to it.

❯ git commit
[WARNING] The 'rev' field of repo 'https://github.com/Freed-Wu/vimdoc' appears to be a mutable reference (moving tag / branch).  Mutable references are never updated after first install and are not supported.  See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details.  Hint: `pre-commit autoupdate` often fixes this.
[INFO] Initializing environment for https://github.com/Freed-Wu/vimdoc.
[INFO] Installing environment for https://github.com/Freed-Wu/vimdoc.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
...
Vint Vim script linting.......................................................Passed
vimdoc........................................................................Passed
dbarnett commented 2 years ago

I don't quite follow the problem. Is that for a pre-commit hook you have set up on your local repo? Wouldn't you just use local gitignore if it's to go with a hook that's local only?

Freed-Wu commented 2 years ago

Hey, let me explain something:

  1. add a pre-commit-hook.yaml in the repository of vimdoc.
  2. add a pre-commit-config.yaml in the repository of vim plugin.
  3. After every commit in the repository of vim plugin, pre-commit will let git commit invoke vimdoc . and generate doc/PLUGIN_NAME.txt, which can update document automatically.

use local gitignore if it's to go with a hook that's local only?

I haven't ever understand why it is related to gitignore?

dbarnett commented 2 years ago

So you're saying each plugin repo would have vimdoc hooks to run vimdoc automatically for anyone with the pre-commit tool installed? But then just having vimdoc installed on the machine isn't enough to make it work, it needs to use vimdoc directly from the GitHub repo?

Freed-Wu commented 2 years ago

Like https://github.com/psf/black/blob/main/.pre-commit-hooks.yaml , pre-commit will git clone this repo from GitHub and install it to a virtual env, then run the cmd of .pre-commit-hooks.yaml ,so it is needed.

dbarnett commented 2 years ago

Should it use the latest release tag instead of "master" then? And pre-commit runs on a developer machine, right? If so, is it intentional that it ignores any locally installed vimdoc?

Sorry, not trying to nitpick the approach here, I'm just stuck on why we need to configure something to tell it master is master and if that's really the ideal setup for what you're trying to hook up.

Freed-Wu commented 2 years ago

Should it use the latest release tag instead of "master" then?

Right

And pre-commit runs on a developer machine, right?

Right

If so, is it intentional that it ignores any locally installed vimdoc?

Right

not trying to nitpick the approach here

No serious. I can answer :smile:

dbarnett commented 2 years ago

Alright cool, I think I follow now! Thanks for your patience explaining to me. 😅 I'll go ahead and merge it.

dbarnett commented 2 years ago

I set this up to run vimdoc for the google/vim-maktaba repo in https://github.com/google/vim-maktaba/commit/88ad116. Works nicely! =)