Check if folders exist in Git repository... testing if a sub-string exists in bash with NULL as a separator

Posted by Craig Francis on Server Fault See other posts from Server Fault or by Craig Francis
Published on 2012-06-19T15:00:47Z Indexed on 2012/06/19 15:18 UTC
Read the original article Hit count: 263

Filed under:
|
|

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

© Server Fault or respective owner

Related posts about bash

Related posts about git