2

Here is my post-receive hook:

#!/bin/bash

while read oldrev newrev ref; do
        git diff --name-only oldrev..newrev
        git --work-tree=/tmp checkout HEAD -- plugin.yml
        echo -e "Test complete maybe..." | tee >(exec logger)
done

And here is the output:

enter image description here

And if I replace oldrev..newrev by oldrev -- newrev, the output is: enter image description here

I need to get folder in which this file(plugin.yml) was modified. Thanks.

Andrew Gorpenko
  • 187
  • 1
  • 1
  • 10
  • Yes, this should be $oldrev and $newrev within the loop. See more example at https://www.cyberciti.biz/faq/unix-linux-iterate-over-a-variable-range-of-numbers-in-bash/ or https://www.cyberciti.biz/faq/bash-for-loop/ – VonC Jul 25 '17 at 07:28
  • YES, It shows it :D And the FINAL question: how can I put this path into the variable? Maybe test=${git diff --name-only oldrev..newrev}? – Andrew Gorpenko Jul 25 '17 at 07:36
  • Yes, except it is test=$(), not ${}. See "command substitution" at https://unix.stackexchange.com/a/4570/7490 – VonC Jul 25 '17 at 07:38
  • @VonC I adore you so much! :3 No one else would help me for so long time and tolerate me. 1.000.000 thanks again, you are awesome!!! I don`t know even basics of Linux, shame on me. Will do my best to study it and not to ask stupid questions.. Thanks again! – Andrew Gorpenko Jul 25 '17 at 07:43

1 Answers1

1

First, each hook can simply check its execution path: that will give you the name of the repo.

Second, the git diff --name-only I mentioned in your previous question will give you the relative path of the file being pushed (including mod1/2).

git diff --name-only $1..$2

since the post-receive hook receives oldrev, newrev and ref on standard input.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250