di-sukharev / opencommit

Generate conventional git commit messages with AI in 1 second πŸ€―πŸ”«
https://www.npmjs.com/package/opencommit
MIT License
5.98k stars 318 forks source link

[Bug]: `oc hook set` creating symlink at "root" on Windows #111

Closed hufuhufu closed 1 year ago

hufuhufu commented 1 year ago

Opencommit Version

1.1.39

Node Version

v18.13.0

NPM Version

9.6.3

What OS are you seeing the problem on?

Windows

What happened?

Running oc hook set will create the hook symlink file prepare-commit-msg at "root". I'm running at oc version 1.1.39 and dev branch.

Expected Behavior

The hook symlink file should be created in the current git repo hook directory.

Current Behavior

Running oc hook set will create the hook symlink file prepare-commit-msg at C:\.git\hooks\prepare-commit-msg. image

This can also be seen in the log output. Though it looks fine because the hook file is created, but it is created in the wrong place.

From what I could tell from the code, it's because there is a path separator at the start of SYMLINK_URL. So when creating the symlink, it creates \.git\hooks\prepare-commit-msg instead of .git\hooks\prepare-commit-msg.

Possible Solution

Remove the separator variable, because path.join already ensures the correct path separator is used. I already tested this with the separator variable removed, npm run dev --hook set worked as expected, prepare-commit-msg is created at .git\hooks, and git commit also calls the hook.

Steps to Reproduce

Run oc hook set.

Relevant log output

β”Œ  setting opencommit as 'prepare-commit-msg' hook at \.git\hooks\prepare-commit-msg
β”‚
β””  βœ” Hook set
di-sukharev commented 1 year ago

thanks, removed the separator