Advertisement
devinteske

git: hooks/post-commit sample for operating on recently committed files

Oct 19th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.08 KB | None | 0 0
  1. #!/bin/sh
  2. # $Title: After `git commit' do "ls -l" on files touched by commit $
  3. # NB: To use, copy to <git_project>/.git/hooks/post-commit
  4. git show --name-only --format= | awk '
  5.        BEGIN {
  6.                c = split("a\ab\bt\tn\nv\vf\fr\r\"\"", cmap, "")
  7.                for (n = 1; n < c; n += 2) map["\\\\" cmap[n]] = cmap[n+1]
  8.        }
  9.        function o2d(oct) {
  10.                dec = 0
  11.                while ((o = substr(oct, 1, 1)) ~ /[0-7]/) {
  12.                        dec = (dec + o) * 8
  13.                        oct = substr(oct, 2)
  14.                }
  15.                return dec / 8
  16.        }
  17.        {
  18.                if (/^".*"$/) $0 = substr($0, 2, length($0) - 2)
  19.                for (m in map) gsub(m, map[m]); gsub(/\\\\/, "\\")
  20.                while (match($0, /\\[[:digit:]]+/))
  21.                        $0 = sprintf("%s%c%s", substr($0, 1, RSTART - 1),
  22.                                o2d(substr($0, RSTART + 1, RLENGTH - 1)),
  23.                                substr($0, RSTART + RLENGTH))
  24.                printf "%s%c", $0, 0
  25.        }
  26. ' | xargs -0 ls -l -- || :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement