0

I need to write a pre-receive hook script which get the information about the files that are being pushed into the server.

I want to know if the list of files that are being pushed into the remote repository can be obtained by a script present in the remote repository

For information, I need to access these files in order to perform some code style checks on them.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Naveen Dennis
  • 1,223
  • 3
  • 24
  • 39
  • possible duplicate of [Git pre-receive hook](http://stackoverflow.com/questions/2569960/git-pre-receive-hook) – jub0bs Sep 28 '14 at 17:53

1 Answers1

0

On the server for that hook you are passed in a ref and an old sha and a new sha. Just use git diff --name-only old..new to get the file list from within the hook

Andrew C
  • 13,845
  • 6
  • 50
  • 57
  • Note that the hook gets a proposed SHA-1 update which is not the same as saying that there is one commit to be added: the update could remove one commit and add three, for instance. But yes, you can diff any specific pair of commits (including old-SHA1 vs new-SHA1). – torek Sep 28 '14 at 18:12
  • Right - this was obviously way simplified. For instance, if there was no previous SHA (new branch) you would need to diff against the NULL tree. Or if you want it per commit for you would to cycle through output of `git rev-list`, etc. – Andrew C Sep 30 '14 at 15:51