Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symlinking git hooks causing unexpected behaviour #627

Open
vimkin opened this issue Mar 1, 2019 · 3 comments
Open

Symlinking git hooks causing unexpected behaviour #627

vimkin opened this issue Mar 1, 2019 · 3 comments

Comments

@vimkin
Copy link

vimkin commented Mar 1, 2019

Thank you for a great repo guys, it helps me really a lot to organise all the dotfiles stuff!

There is a potential implicit issue/risk covers in symlinking hooks.

Description:

Let's say you have such scenario:

  • git clone project-a
  • git clone project-b
  • cd project-a
  • composer install // additionally installs f.e. post-commit hook

This will most probably break project-b by modifying the project hooks and additionally will modify template hooks in the root dotfiles folder.

In such a scenario composer changes post-commit hook in the project-a which following the links chain, leads to the changes in project-b/.git/hooks/post-commit as well as ~/dotfiles/git_template/hooks/post-commit, since post-commit in project-a is just a link to the initial file.

It's quite common that some tool like composer may change hooks, which leads to such implicit scenario if hooks were symlinked.

Possible solution:

git_template/hooks should be copied and not symlinked

@vimkin vimkin changed the title Templates hooks as link causing unexpected behaviour Symlinking git hooks causing unexpected behaviour May 16, 2019
@geoffharcourt
Copy link
Collaborator

geoffharcourt commented Jul 28, 2019

I'm a bit confused. When I clone a git project, the files from git_template are copied, so changes made from that folder don't go back and pollute the hooks in ~/.git_template, which is symlinked to my ~/dotfiles directory. Does composer install go and edit files outside the project such as the home directory's git template? If so, that seems like a risk inherent to composer and not an issue with dotfiles.

@vimkin
Copy link
Author

vimkin commented Jul 30, 2019

@geoffharcourt no, composer install doesn't edit anything outside the project. The issue I have reported at that point is when files are symlinked (default mode when running rcup). At this point if you have lets say post-commit hook then ~/git_template/post-commit -> dotfiles/git_template/post-commit. Afterwards you clone or init any project which has tools like husky or compose-git-hooks that modify git hooks. So you should take in account that when cloning or init git project, it also copied ~/git_template/post-commit -> dotfiles/git_template/post-commit and then when such a git hook tool writes to the hook file it replaces content of each hook which was ever symlinked. Quite dangerous outcome 😳

But you're right, using rcup -C solves this issue.

@croaky
Copy link
Contributor

croaky commented Aug 13, 2019

I ran into the same (or similar) problem while working with Git LFS. I ended up deleting the Git hooks directory from my dotfiles (which were originally based on thoughtbot/dotfiles): croaky/laptop@1c96034

I had previously deleted the majority of what was in the Git hooks directory, which was ctags-related for Vim, because my jump-to-definition etc. is now handled by LSP tools such as tsserver for TypeScript. croaky/laptop@02c439b

sheck added a commit to sheck/dotfiles that referenced this issue Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants