Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a common git "post-receive" script for several projects, and it needs to perform different actions if an /app/ or /public/ folder exists in the root.

Using:

FOLDERS=`git ls-tree -d --name-only -z master`;

I can see the directory listing, and I would like to use the RegExp support in bash to run something like:

if [[ "$FOLDERS" =~ app ]]; then
    ...
fi

But that won't work if there was something like an "app lication" folder... I specified the "-z" option in the git "ls-tree" command so I could use the \0 (null) character as a separator, but not sure how to test for that in the bash RegExp.

Likewise I know there is support for specifying a particular path in the ls-tree command, and could then pipe that to "wc -l", but I'd have thought it was quicker to get a full directory listing of the root (not recursive) then test for the 2 (or more) folders with the returned output.

Possibly related to: http://stackoverflow.com/questions/7938094/git-how-to-check-which-files-exist-and-their-content-in-a-shared-bare-repos

share|improve this question

1 Answer 1

up vote 0 down vote accepted

It looks like the NULL character is lost (or ignored), as if the listing includes "app" and "httpd", it will match the string "apphttpd".

So I've gone with calling "git ls-tree" multiple times for now to see if each individual file exists.

if [ `git ls-tree -d --name-only master "$F" | wc -l` -eq 1 ]; then
fi
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.