 	s.replace /\$([\w_])+/g, (match, name) ->
 		process.env[name] || name
 
-isGitRepo = (dir) -> fs.existsSync path.join dir, '.git'
-isHgRepo = (dir) -> fs.existsSync path.join dir, '.hg'
-isRepoDir = (dir) -> isGitRepo dir || isHgRepo dir
+dirExists = (dir) ->
+	fs.existsSync(dir) and fs.lstatSync(dir).isDirectory()
+
+isGitRepo = (dir) ->
+	dirExists path.join dir, '.git'
+isHgRepo = (dir) ->
+	dirExists path.join dir, '.hg'
+isRepoDir = (dir) ->
+	isGitRepo dir or isHgRepo dir
 
 # find repo dirs from given root dir
 findDirs = (root, cb) ->

# bootstrap script
Meteor.startup ->

	findDirs Meteor.settings.public.root, (dirs)->
		items = dirs.map (dir) -> makeRepoItem dir
		# meteor requires fibers

	walker = walk.walk root, opts

	walker.on 'directories', (dir, stats, next)->
		dirs.push dir if isRepoDir dir
		next()

	walker.on 'end', -> cb dirs

repoType = (dir) ->
	switch
		when isGitRepo dir then 'git'
		when isHgRepo dir then 'hg'
		else 'unknown'

# converts repo dir to repo info object
makeRepoItem = (dir) ->
	return {
		type: repoType dir
		name: path.basename dir
