| 1 |
"use strict"; |
| 2 |
|
| 3 |
var deferred = require("deferred") |
| 4 |
, resolve = require("path").resolve |
| 5 |
, lstat = require("fs").lstat |
| 6 |
, WatchPath = require("../../watch-path").WatchPath |
| 7 |
, isRoot; |
| 8 |
|
| 9 |
exports.filename = ".gitignore"; |
| 10 |
exports.globalRules = [".git"]; |
| 11 |
exports.isRoot = isRoot = function (path) { |
| 12 |
var def, gPath; |
| 13 |
|
| 14 |
gPath = resolve(path, ".git"); |
| 15 |
def = deferred(); |
| 16 |
lstat(gPath, function (err, stats) { def.resolve(err ? false : stats.isDirectory()); }); |
| 17 |
def.promise.gitPath = gPath; |
| 18 |
def.promise.path = path; |
| 19 |
return def.promise; |
| 20 |
}; |
| 21 |
exports.isRoot.returnsPromise = true; |
| 22 |
|
| 23 |
exports.isRootWatcher = function (path) { |
| 24 |
var promise, watcher; |
| 25 |
promise = isRoot(path); |
| 26 |
watcher = new WatchPath(promise.gitPath); |
| 27 |
watcher.on("change", function (event) { |
| 28 |
if (event.type === "create") { |
| 29 |
promise.value = true; |
| 30 |
} else if (event.type === "remove") { |
| 31 |
promise.value = false; |
| 32 |
} else { |
| 33 |
return; |
| 34 |
} |
| 35 |
promise.emit("change", promise.value, path); |
| 36 |
}); |
| 37 |
promise.close = watcher.close; |
| 38 |
return promise; |
| 39 |
}; |
| 40 |
exports.isRootWatcher.returnsPromise = true; |