Skip to content

Commit 2c7c849

Browse files
Zhe YuDavidyz
authored andcommitted
docs(cli): update documentation for hooks.
1 parent 6b0294c commit 2c7c849

1 file changed

Lines changed: 34 additions & 33 deletions

File tree

docs/cli.md

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
* [If Anything Goes Wrong...](#if-anything-goes-wrong)
1414
* [Advanced Usage](#advanced-usage)
1515
* [Initialising a Project](#initialising-a-project)
16+
* [Git Hooks](#git-hooks)
1617
* [Configuring VectorCode](#configuring-vectorcode)
1718
* [Vectorising Your Code](#vectorising-your-code)
1819
* [File Specs](#file-specs)
19-
* [Git Hooks](#git-hooks)
2020
* [Making a Query](#making-a-query)
2121
* [Listing All Collections](#listing-all-collections)
2222
* [Removing a Collection](#removing-a-collection)
@@ -123,8 +123,7 @@ vectorcode vectorise src/**/*.py
123123
```
124124
> VectorCode doesn't track file changes, so you need to re-vectorise edited
125125
> files. You may automate this by a git pre-commit hook, etc. See the
126-
> [wiki](https://github.com/Davidyz/VectorCode/wiki/Tips-and-Tricks#git-hooks)
127-
> for examples to set them up.
126+
> [advanced usage section](#git-hooks) for examples to set them up.
128127
129128
Ideally, you should try to vectorise all source code in the repo, but for large
130129
repos you may experience slow queries. If that happens, try to `vectorcode drop`
@@ -164,7 +163,7 @@ to refresh the embedding for a particular file, and the CLI provides a
164163
are currently indexed by VectorCode for the current project.
165164

166165
If you want something more automagic, check out
167-
[this section in the wiki](https://github.com/Davidyz/VectorCode/wiki/Tips-and-Tricks#git-hooks)
166+
[the advanced usage section](#git-hooks)
168167
about setting up git hooks to trigger automatic embedding updates when you
169168
commit/checkout to a different tag.
170169

@@ -205,6 +204,37 @@ contains `.git/` subdirectory and use it as the _project root_. In this case, th
205204
default global configuration will be used. If `.git/` does not exist, VectorCode
206205
falls back to using the current working directory as the _project root_.
207206

207+
#### Git Hooks
208+
209+
To keep the embeddings up-to-date, you may find it useful to set up some git
210+
hooks. The `init` subcommand provides a `--hooks` flag which helps you manage
211+
hooks when working with a git repository. You can put some custom hooks in
212+
`~/.config/vectorcode/hooks/` and the `vectorcode init --hooks` command will
213+
pick them up and append them to your existing hooks, or create new hook scripts
214+
if they don't exist yet. The hook files should be named the same as they would
215+
be under the `.git/hooks` directory. For example, a pre-commit hook would be named
216+
`~/.config/vectorcode/hooks/pre-commit`.
217+
218+
By default, there are 2 pre-defined hooks:
219+
```bash
220+
# pre-commit hook that vectorise changed files before you commit.
221+
diff_files=$(git diff --cached --name-only)
222+
[ -z "$diff_files" ] || vectorcode vectorise $diff_files
223+
```
224+
```bash
225+
# post-checkout hook that vectorise changed files when you checkout to a
226+
# different branch/tag/commit
227+
files=$(git diff --name-only "$1" "$2")
228+
[ -z "$files" ] || vectorcode vectorise $files
229+
```
230+
When you run `vectorcode init --hooks` in a git repo, these 2 hooks will be added
231+
to your `.git/hooks/`. Hooks that are managed by VectorCode will be wrapped by
232+
`# VECTORCODE_HOOK_START` and `# VECTORCODE_HOOK_END` comment lines. They help
233+
VectorCode determine whether hooks have been added, so don't delete the markers
234+
unless you know what you're doing. To remove the hooks, simply delete the lines
235+
wrapped by these 2 comment strings.
236+
237+
208238
### Configuring VectorCode
209239
Since 0.6.4, VectorCode adapted a [json5 parser](https://github.com/dpranke/pyjson5)
210240
for loading configuration. VectorCode will now look for `config.json5` in
@@ -366,35 +396,6 @@ on certain conditions. See
366396
[the wiki](https://github.com/Davidyz/VectorCode/wiki/Tips-and-Tricks#git-hooks)
367397
for an example to use it with git hooks.
368398

369-
#### Git Hooks
370-
371-
To keep the embeddings up-to-date, you may find it useful to set up some git
372-
hooks. The CLI provides a subcommand, `vectorcode hooks`, that helps you manage
373-
hooks when working with a git repository. You can put some custom hooks in
374-
`~/.config/vectorcode/hooks/` and the `vectorcode hooks` command will pick them
375-
up and append them to your existing hooks, or create new hook scripts if they
376-
don't exist yet. The hook files should be named the same as they would be under
377-
the `.git/hooks` directory. For example, a pre-commit hook would be named
378-
`~/.config/vectorcode/hooks/pre-commit`. By default, there are 2 pre-defined
379-
hooks:
380-
```bash
381-
# pre-commit hook that vectorise changed files before you commit.
382-
diff_files=$(git diff --cached --name-only)
383-
[ -z "$diff_files" ] || vectorcode vectorise $diff_files
384-
```
385-
```bash
386-
# post-checkout hook that vectorise changed files when you checkout to a
387-
# different branch/tag/commit
388-
files=$(git diff --name-only "$1" "$2")
389-
[ -z "$files" ] || vectorcode vectorise $files
390-
```
391-
When you run `vectorcode hooks` in a git repo, these 2 hooks will be added to
392-
your `.git/hooks/`. Hooks that are managed by VectorCode will be wrapped by
393-
`# VECTORCODE_HOOK_START` and `# VECTORCODE_HOOK_END` comment lines. They help
394-
VectorCode determine whether hooks have been added, so don't delete the markers
395-
unless you know what you're doing. To remove the hooks, simply delete the lines
396-
wrapped by these 2 comment strings.
397-
398399
### Making a Query
399400

400401
To retrieve a list of documents from the database, you can use the following command:

0 commit comments

Comments
 (0)