1

I just started playing around with git hooks using Ruby(as am more comfortable with ruby).

Can anyone tell me how to print all the staged file names? and can anyone tell me or give me a good resource where I can understand how will git search through the staged files and search for a particular text?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Kranthi
  • 1,377
  • 1
  • 17
  • 34

1 Answers1

1

One possible command is (from "Git pre-commit hook : changed/added files"):

git diff --cached --name-only --diff-filter=ACM

That is what I recommended for that other ruby pre-commit hook"

And you could use it with "jish/pre-commit".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I like to learn myself instead of depending on gems at beginning as it gives more knowledge to me. Is there any way to know what options gives staged files and committed files and all? Can you tell me please – Kranthi Nov 16 '14 at 10:39
  • @Kranthi the command i gave you doesn't require any gem and can be used independently. That command is detailed in http://stackoverflow.com/a/3068990/6309. And you can see more at https://try.github.io/levels/1/challenges/1 – VonC Nov 16 '14 at 10:44
  • I was speaking about the "jish/pre-commit" gem not about the command. :) – Kranthi Nov 16 '14 at 10:45
  • @Kranthi Oh, ok :) I was mentioning `jish/pre-commit` as an example of a pre-commit done in ruby. – VonC Nov 16 '14 at 10:49
  • @ VonC can you tell me what --diff-filter=ACM means. – Kranthi Nov 16 '14 at 10:55
  • 1
    @Kranthi: see http://git-scm.com/docs/git-diff: Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), – VonC Nov 16 '14 at 10:56
  • How can I get the whole path of a file instead of a file name? Sorry I checked in git diff options but couldnt find that. – Kranthi Nov 16 '14 at 11:34
  • @Kranthi the files listed whould be with their path relative to the base repo folder (as seen in http://stackoverflow.com/q/5605347/6309). All you would need to do is to prepend that path with the root folder of that repo: http://stackoverflow.com/a/957978/6309 `git rev-parse --show-toplevel` – VonC Nov 16 '14 at 11:37