Skip to content

Commit 9744867

Browse files
Zhe YuDavidyz
authored andcommitted
fix(cli): allow injecting hooks on a initialised project.
1 parent 2c7c849 commit 9744867

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

src/vectorcode/subcommands/init.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,27 @@ def inject_hook(self, content: list[str], force: bool = False):
9494
async def init(configs: Config) -> int:
9595
assert configs.project_root is not None
9696
project_config_dir = os.path.join(str(configs.project_root), ".vectorcode")
97+
is_initialised = 0
9798
if os.path.isdir(project_config_dir) and not configs.force:
9899
logger.warning(
99100
f"{configs.project_root} is already initialised for VectorCode.",
100101
)
101-
return 1
102-
103-
os.makedirs(project_config_dir, exist_ok=True)
104-
for item in ("config.json", "vectorcode.include", "vectorcode.exclude"):
105-
local_file_path = os.path.join(project_config_dir, item)
106-
global_file_path = os.path.join(
107-
os.path.expanduser("~"), ".config", "vectorcode", item
102+
is_initialised = 1
103+
else:
104+
os.makedirs(project_config_dir, exist_ok=True)
105+
for item in ("config.json", "vectorcode.include", "vectorcode.exclude"):
106+
local_file_path = os.path.join(project_config_dir, item)
107+
global_file_path = os.path.join(
108+
os.path.expanduser("~"), ".config", "vectorcode", item
109+
)
110+
if os.path.isfile(global_file_path):
111+
logger.debug(f"Copying global {item} to {project_config_dir}")
112+
shutil.copyfile(global_file_path, local_file_path)
113+
114+
print(f"VectorCode project root has been initialised at {configs.project_root}")
115+
print(
116+
"Note: The collection in the database will not be created until you vectorise a file."
108117
)
109-
if os.path.isfile(global_file_path):
110-
logger.debug(f"Copying global {item} to {project_config_dir}")
111-
shutil.copyfile(global_file_path, local_file_path)
112118

113119
git_root = find_project_root(configs.project_root, ".git")
114120
if git_root:
@@ -120,8 +126,4 @@ async def init(configs: Config) -> int:
120126
hook_obj = HookFile(hook_file_path, git_dir=git_root)
121127
hook_obj.inject_hook(__HOOK_CONTENTS[hook], configs.force)
122128

123-
print(f"VectorCode project root has been initialised at {configs.project_root}")
124-
print(
125-
"Note: The collection in the database will not be created until you vectorise a file."
126-
)
127-
return 0
129+
return is_initialised

tests/subcommands/test_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def test_init_already_initialized(capsys):
3131

3232
# Try to initialize again without force
3333
return_code = await init(configs)
34-
assert return_code == 1
34+
assert return_code != 0
3535

3636

3737
@pytest.mark.asyncio

0 commit comments

Comments
 (0)