0

I have a requirement where I want to symlink git hooks after the clone is successfully completed. I tried creating post-checkout hook in mylocalrepo/hooks directory. I want symlink of hooks in mylocalrepo/hooks to be automatically created under mylocalrepo/.git/hooks after clone is successful.

But how will git get to know about the existence of the original hooks under mylocalrepo/hooks directory when initially no symlink relation exists between mylocalrepo/hooks and .git/hooks, when we clone the repo.

Is there a way I can implement a hook that would trigger after the clone?

If at all there is a post-clone-like-hook, which I haven't found till now, then how does one go about making git aware of it, as hooks are not inherited during clone,and a cloned repo has only sample hooks, and for custom org-enforced hooks(hooks under mylocalrepo/hooks directory) to work, we need to get the symlink relation established first.

Creating symlinks can be done manually by each developer after the clone is successful, but is there any way to automate this process as well so that the symlinks are created(or any other task which is required to be performed on successful clone) gets executed after the clone is successful.

Found below OPs, but none seem to solve my issue:

git hooks : is there a clone hook? : here it is suggested to use the clone --template option and that the template should already exist on the filesystem beforehand and as I'm on windows, I have not been able to figure out where this template directory resides on Windows filesystem.

git-clone and post-checkout hook : This also doesn't help.I just am not able to see the solution there, though the OP has accepted answer. how the symlink relation is established, when there are only sample hooks when someone clones a repo.

Automatically run tasks after Git Clone without using git hooks : This also doesn't help, as what I want is to have a standard way of performing the post -clone action, where the user/developer doesnot have to bother about setting up thesmlinks. He will just clone the GitHUb repo and everything else will be taken care of.

Possible solution : to have a script distributed among developers or included in teh GitHub repo and ask the devs to execute the script after the clone. But, as I said I want to make this an automatic process.

Please let me know if I missed out on anything.

EDIT 1 : START

Some might say that this is a possible duplicate of the other posts that I mentioned in my post. This might sound duplicate but isn't. If I'm not able to apply what has been suggested in the other OPs(dating back to 2010), then what good it does to me if someone marks my question as duplicate, moresoever when I post my questions against each of the OPs link asking for clarifications as to why those already existing posts couldn't/didn't help me.

I haven't received any response to my question, apart from just a "mark as duplicate" vote. My OP comes with several other concerns. Still this is marked as duplicate. Its like telling me to just keep staring at the questions they believe it to be a duplicate of, keep thinking and thinking until I somehow get the explanations(which seems very unlikely).

I too believe marking a question as duplicate is great way to keep the site clean and clutter-free.I encourage this. But there should be a proper explanation for the action, just saying "its a duplicate" doesn't help.

EDIT 2 : END

Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47
  • This post is a duplicate of the very posts you mention. Your possible solution is the solution or use some framework for it like this [project](https://stackoverflow.com/questions/2141492/git-clone-and-post-checkout-hook). – Adam Mar 23 '20 at 07:29
  • @Adam Your link takes me back to the SO OP, not my project. Please confirm. Also, I will edit my post to explain why its different and could be answered by those who know.The amount of detail in my question should well explain the fact that I have spent a great amount of time researching the topic and scraping the web. Its only after having spent several hours ,that I turned to StackOverflow and posted my question. – Asif Kamran Malick Mar 23 '20 at 08:03
  • For git template folder, see https://stackoverflow.com/questions/16363460/set-up-a-default-directory-structure-on-git-init – Lasse V. Karlsen Mar 23 '20 at 08:22
  • 3
    Git does not support a local installation free way of doing what you want. You **will** have to do something locally, either having templates already configured, using aliases or bash/batch scripts, or other tools that will do what you want. It would be **extremely** dangerous if Joe Random on github could create a git repository that when I clone would be allowed to run arbitrary code on my machine as part of the cloning process. You **will** need to make concious choices locally to make this happen. – Lasse V. Karlsen Mar 23 '20 at 08:24
  • @LasseV.Karlsen This makes sense.I see there's serious security issue.And I believe now, this should never be allowed in any of the future git releases. Thanks again. I will still look into the template folder thing – Asif Kamran Malick Mar 23 '20 at 10:50
  • I am not that familiar with all the git hooks you can make, but if you can make a global git hook that runs after cloning, you could make it look for a script with a special name in the script, and then run this. This would allow you to get the best from both worlds, less configuration locally, and let the actual repository control what to do. – Lasse V. Karlsen Mar 23 '20 at 12:17
  • Thanks@LasseV.Karlsen But this directs me to my original question. How does one tell git to run a particular hook after clone. I mean I have tried searching literally hundreds of times, as this is something I needed badly (earlier not considering the security issue you pointed out). Git doesn't seem to offer anything that could help us handle post-clone actions. Once I am able to discover any way to hook with the post-clone event, I think I would be able to solve this. – Asif Kamran Malick Mar 23 '20 at 12:30

0 Answers0