2

I have many local commits which contains several modified files.

I need to run a specific command on each file modified after pushing to the repository, and this has to be done on the client side itself.

How do I configure git to do the same?

git log --name-only --format="" --author xxxx origin/master..HEAD | sort | uniq

The above command gives me all my committed files but with path relative to my repo. I need either the absolute path from the root or one which is relative to my current directory.

Arun Swaminathan
  • 351
  • 1
  • 3
  • 10

1 Answers1

1

I need to run a specific command on each file modified after pushing to the repository, and this has to be done on the client side itself.

You can use the post-receive hook for this.

The above command gives me all my committed files but with path relative to my repo. I need either the absolute path from the root or one which is relative to my current directory.

You can use the readlink utility to get an absolute path.

readlink -f ./relativePath

In your pipeline, use xargs so the file path is passed to readlink:

git log --name-only --format="" --author xxxx origin/master..HEAD | sort | uniq | xargs readlink -f
Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
  • This only works when I execute it from my repo root (since the path which i get from `git log --name-only --format="" --author xxxx origin/master..HEAD | sort | uniq` is relative to the root. Otherwise readlink give the following error which executed with -v readlink: foo/bar/xxx.py: No such file or directory – Arun Swaminathan Sep 18 '17 at 15:11
  • Where is this being executed from? – Jonathan.Brink Sep 18 '17 at 15:13
  • From a subdirectory inside the repo. For eg. if my repo starts from foo, i execute it from foo/bar – Arun Swaminathan Sep 18 '17 at 15:14
  • The command I pasted above seems to work the same from anywhere within a Git repo, but you can explicitly specify to run a command from a particular git repo with the `--git-dir` option. See: https://stackoverflow.com/questions/3769137/use-git-log-command-in-another-folder – Jonathan.Brink Sep 18 '17 at 15:18
  • BTW, I'm running this on Ubuntu, so perhaps the path situation is different for the platform you are on... – Jonathan.Brink Sep 18 '17 at 15:20
  • I'm running it on a bash shell in redhat linux. Still throwing the `No such file or directory` error. I can probably do a hack to `cd` to the start of the repo and execute this, that should work... – Arun Swaminathan Sep 18 '17 at 15:26