|
13 | 13 | * [If Anything Goes Wrong...](#if-anything-goes-wrong) |
14 | 14 | * [Advanced Usage](#advanced-usage) |
15 | 15 | * [Initialising a Project](#initialising-a-project) |
| 16 | + * [Git Hooks](#git-hooks) |
16 | 17 | * [Configuring VectorCode](#configuring-vectorcode) |
17 | 18 | * [Vectorising Your Code](#vectorising-your-code) |
18 | 19 | * [File Specs](#file-specs) |
19 | | - * [Git Hooks](#git-hooks) |
20 | 20 | * [Making a Query](#making-a-query) |
21 | 21 | * [Listing All Collections](#listing-all-collections) |
22 | 22 | * [Removing a Collection](#removing-a-collection) |
@@ -123,8 +123,7 @@ vectorcode vectorise src/**/*.py |
123 | 123 | ``` |
124 | 124 | > VectorCode doesn't track file changes, so you need to re-vectorise edited |
125 | 125 | > 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. |
128 | 127 |
|
129 | 128 | Ideally, you should try to vectorise all source code in the repo, but for large |
130 | 129 | 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 |
164 | 163 | are currently indexed by VectorCode for the current project. |
165 | 164 |
|
166 | 165 | 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) |
168 | 167 | about setting up git hooks to trigger automatic embedding updates when you |
169 | 168 | commit/checkout to a different tag. |
170 | 169 |
|
@@ -205,6 +204,37 @@ contains `.git/` subdirectory and use it as the _project root_. In this case, th |
205 | 204 | default global configuration will be used. If `.git/` does not exist, VectorCode |
206 | 205 | falls back to using the current working directory as the _project root_. |
207 | 206 |
|
| 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 | + |
208 | 238 | ### Configuring VectorCode |
209 | 239 | Since 0.6.4, VectorCode adapted a [json5 parser](https://github.com/dpranke/pyjson5) |
210 | 240 | for loading configuration. VectorCode will now look for `config.json5` in |
@@ -366,35 +396,6 @@ on certain conditions. See |
366 | 396 | [the wiki](https://github.com/Davidyz/VectorCode/wiki/Tips-and-Tricks#git-hooks) |
367 | 397 | for an example to use it with git hooks. |
368 | 398 |
|
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 | | - |
398 | 399 | ### Making a Query |
399 | 400 |
|
400 | 401 | To retrieve a list of documents from the database, you can use the following command: |
|
0 commit comments