From b6d778450916af85ebc32d63e6099d9df74308eb Mon Sep 17 00:00:00 2001 From: Zhe Yu Date: Thu, 19 Jun 2025 14:38:36 +0800 Subject: [PATCH 1/3] feat(cli): Add conditional checks for git hooks --- src/vectorcode/subcommands/init.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/vectorcode/subcommands/init.py b/src/vectorcode/subcommands/init.py index 84ce4e85..8af90bd7 100644 --- a/src/vectorcode/subcommands/init.py +++ b/src/vectorcode/subcommands/init.py @@ -20,11 +20,19 @@ __HOOK_CONTENTS: dict[str, list[str]] = { "pre-commit": [ "diff_files=$(git diff --cached --name-only)", - '[ -z "$diff_files" ] || vectorcode vectorise $diff_files', + 'if [ -d ".vectorcode" ] && [ ! -z "$diff_files" ]; then', + " vectorcode vectorise $diff_files", + "fi", ], "post-checkout": [ - 'files=$(git diff --name-only "$1" "$2")', - '[ -z "$files" ] || vectorcode vectorise $files', + 'if [ -z "$(echo $1|grep [^0])" ]; then', + ' files=""', + "else", + ' files=$(git diff --name-only "$1" "$2")', + "fi", + 'if [ -d ".vectorcode" ] && [ ! -z "$files" ]; then', + " vectorcode vectorise $files", + "fi", ], } From 982070015607ef5158412573ac1abd5e33601e0a Mon Sep 17 00:00:00 2001 From: Zhe Yu Date: Thu, 19 Jun 2025 14:59:38 +0800 Subject: [PATCH 2/3] feat(cli): Log warning if hook path is a symlink --- src/vectorcode/subcommands/init.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vectorcode/subcommands/init.py b/src/vectorcode/subcommands/init.py index 8af90bd7..f6e98f8d 100644 --- a/src/vectorcode/subcommands/init.py +++ b/src/vectorcode/subcommands/init.py @@ -92,6 +92,8 @@ def inject_hook(self, content: list[str], force: bool = False): self.lines.extend(i if i.endswith("\n") else i + "\n" for i in content) self.lines.append(self.suffix + "\n") with open(self.path, "w") as fin: + if os.path.islink(self.path): # pragma: nocover + logger.warning(f"{self.path} is a symlink.") fin.writelines(self.lines) if platform.system() != "Windows": # for unix systems, set the executable bit. From c4bd65f57a0164c300f6377b712de390bd6b6f1f Mon Sep 17 00:00:00 2001 From: Zhe Yu Date: Thu, 19 Jun 2025 17:38:07 +0800 Subject: [PATCH 3/3] feat(cli): Add vectorise command to post-checkout hook when it's a new clone --- src/vectorcode/subcommands/init.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vectorcode/subcommands/init.py b/src/vectorcode/subcommands/init.py index f6e98f8d..bba9af63 100644 --- a/src/vectorcode/subcommands/init.py +++ b/src/vectorcode/subcommands/init.py @@ -27,6 +27,7 @@ "post-checkout": [ 'if [ -z "$(echo $1|grep [^0])" ]; then', ' files=""', + " ( [ -f .vectorcode/vectorcode.include ] || [ -f ~/.config/vectorcode/vectorcode.include ] ) && vectorcode vectorise || true", "else", ' files=$(git diff --name-only "$1" "$2")', "fi",