0

Is there a way to check if a file in git commit is a symbolic link without checking out the commit content?

Background:
There is a hook which is used to check C++ code formatting in each git commit that is pushed.
So far the algorithm is:
Get a list of files in a commit with git diff-tree --no-commit-id --name-only --diff-filter=d -r ${commit}.
Processes each file (content) in git commit, selected based on a file extension, using git show ${commit}:${file}.

Problem:
A file with .cpp extension may be a symbolic link, in which case it shall not be processed.

NOTE: I know that having source files as a symbolic link is not a good idea.

  • If you run the command "file" on the list of files, it will return details as whether the file is symbolically linked or not. – Raman Sailopal Oct 27 '20 at 15:25
  • 1
    @RamanSailopal You cannot run `file` on an object in a non-checked out commit. – phd Oct 27 '20 at 15:27
  • 4
    https://stackoverflow.com/a/18791647/7976758: `git ls-tree COMMIT-ID path-to/file` and look for the 1st column (mode); symbolic links have mode `120000`. See modes: https://stackoverflow.com/a/737877/7976758 – phd Oct 27 '20 at 15:30

0 Answers0