Skip to content

Commit 561fa96

Browse files
committed
fix: remove the hook file before writing
Pre-installed hooks may be symbolic links pointing to a shared binary. Directly overwriting the commit-msg hook could break other dependencies. Therefore, it is safer to remove the hook before writing. Change-Id: If0d26d77f4b7ea061ce1383cfb922a4c5b7eb335 Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
1 parent 10fb892 commit 561fa96

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/commands/install.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ async function install(): Promise<void> {
198198
}
199199

200200
try {
201-
// Write the hook file
201+
// Remove the hook file which may be a symlink to other file.
202+
if (fs.existsSync(hookPath)) {
203+
fs.unlinkSync(hookPath);
204+
}
205+
206+
// Create the hook file
202207
fs.writeFileSync(hookPath, hookContent, { mode: 0o755 });
203208
console.log('Commit-msg hook installed successfully!');
204209
console.log(`Hook installed at: ${hookPath}`);

0 commit comments

Comments
 (0)