Reputation: 33
We want to move our version control from svn to git. Everything was quite easy, except one small part.
In our release process we have a smoke test to ensure, that any shell script has its executable flag set on disk and in the repository as well.
In svn this was quite easy. We just needed to check the list returned by our wrapper function.
function vc_has_executable_flag() {
svn propget svn:executable $* | awk '{ print $1 }'
}
Even after an extended search, I didn't find any git solution for this.
The following function returns the same result.
function vc_has_executable_flag() {
git update-index --chmod=-x $*
git reset $* | awk '{ print $2 }'
}
The question is, if there is a better method to do it. If not, is this approach stable?
Of course we can have a race condition here, but as its intended use is on a dedicated build machine, this is not an issue for us.
Upvotes: 3
Views: 614
Reputation: 14374
git ls-tree
shows file mode. For executables it should be 100755
.
So with simple grep you could check whether file in git is executable or not.
The checking function then looks like this:
function vc_has_executable_flag() {
git ls-tree HEAD $* | grep '^100755 ' | awk '{ print $4 }'
}
Upvotes: 1
Reputation: 142612
As you said the right way of doing it is git update-index --chmod=-x
.
Another option is to capture the files which are being committed inside git hook and then execute this command. but it will have the same effect as the function you have just created.
Also make sure that git will track the file mode changes git config core.filemode true
Upvotes: 0