2

I want to commit a hook to my PR which automatically update the submodule whenever someone does a git pull

Following is what is did in my git local repo:

touch .git/hooks/post-rewrite
cd .git/hooks
chmod +x post-rewrite

Next, to the post-rewrite I added the code from here

Now if I do a git pull shouldn't it update the submodule withgit pull` as I am expecting it to? But it doesn't. What is the mistake I am doing?

I've looked through many related links which are there but can't get it to work.

Also if I want to commit it the add post-rewrite file in hooks folder does not enlist under git status. How can I get add, commit & push this into my PR?

TheWaterProgrammer
  • 7,055
  • 12
  • 70
  • 159
  • What led you to believe post-rewrite is the correct hook for this? Also, what led you to believe git might inject hooks via pull? Please be concrete. – jthill Jan 26 '17 at 17:27
  • @jthill I read through some links like [here](http://stackoverflow.com/questions/37525188/how-can-i-pull-git-submodule-automatically) & [here](http://stackoverflow.com/questions/427207/can-git-hook-scripts-be-managed-along-with-the-repository) & some more which say that to achieve a automatic `submodule update` with `git pull`, you need to add a `post-rewrite` or `post-receive` in `.git/hooks/`. Hence I did the same. Did not work. Moreover it does not list in `git status` as well. I am confused. Please suggest. All I want is whenever a developer does a git pull, submodule update automatically – TheWaterProgrammer Jan 26 '17 at 17:36
  • Do I need to change or enable some gitAttribute to enable hooks ? – TheWaterProgrammer Jan 26 '17 at 18:28
  • "rewrite" does not appear anywhere in either of those links, nor can I find any suggestion that git might inject hooks via pull. So let me repeat: what led you to believe post-rewrite is the correct hook for this? Also, what led you to believe git might inject hooks via pull? Please be concrete. You enable hooks in exactly the way you've shown in your question. – jthill Jan 26 '17 at 18:34
  • @jthill My objective is "To Ensure `git submodule update` automatically happens for every developer in my team who does a `git pull`"... Now I need to figure out how to do this. I see that `git hooks` is the potential solution to my problem. Now I am trying all kinds of hit & trial things & seeking help in this forum. Please post a solution as answer if you can. I read the official git documentation & now understand that I need to create a hooks directory in my git folder & create a symlink to it? As mentioned at https://www.atlassian.com/git/tutorials/git-hooks ? – TheWaterProgrammer Jan 26 '17 at 18:47
  • 1
    Ok. Now I learnt that I need to create directory called `hooks` in my main repo, create a `post-update` script & somehow simlink it to `.git/hooks/post-update` ? I am still not sure. Would appreciate any solutions posted for this – TheWaterProgrammer Jan 26 '17 at 19:07

0 Answers0