Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine whether a file in git is executable?

Tags:

git

If I have a file in a git repository, how can I determine whether a given revision of the file is executable or not?

I know that git keeps track of whether files are executable or not, and git show will show changes in execute permissions. For example, the output of git show on a given revision might include:

diff --git file file
old mode 100644
new mode 100755

which indicates that the file acquired execute permission.

I want to determine whether the current revision, or any specified revision, of a specified file has execute permission.

(Background: I have a wrapper script that extracts a specified version of a file using

git show $commit:./$filename > ./$filename.$commit

I want to run chmod +x on the new file if and only if that version of the file executable in the repository.)

like image 822
Keith Thompson Avatar asked Apr 26 '18 00:04

Keith Thompson


1 Answers

Use git ls-tree, passing in the ref and file path you want to inspect.

For example, git ls-tree HEAD foo.txt will give something like

100644 blob 3e1d68d0714fd3d46ec22a685e317f0cf47f5e83    foo.txt

The 644 in the first column indicates a non-executable file. 755 would indicate an executable file.

like image 146
Chris Avatar answered Oct 08 '22 16:10

Chris