Skip to content

Instantly share code, notes, and snippets.

@scorredoira
Created July 2, 2017 16:42
Show Gist options
  • Save scorredoira/f0a76dbf3a25cf438365d51ff864a065 to your computer and use it in GitHub Desktop.
Save scorredoira/f0a76dbf3a25cf438365d51ff864a065 to your computer and use it in GitHub Desktop.
/**
* ------------------------------------------------------------------ *
* Recursively enable/disable git repos
* Poor man's submodules
* ------------------------------------------------------------------
*/
export function main(enabled: string) {
let b = convert.toBool(enabled);
processDir(".", b, true, os.fileSystem)
}
function processDir(dir: string, enabled: boolean, isTopDir: boolean, fs: io.FileSystem) {
for (let fi of fs.readDir(dir)) {
if (fi.isDir) {
switch (fi.name) {
case ".git":
if (isTopDir) {
continue; // don't process the top .git
}
if (!enabled) {
fs.rename(filepath.join(dir, ".git"), filepath.join(dir, ".git_disabled"))
}
break;
case ".git_disabled":
if (isTopDir) {
continue; // don't process the top .git
}
if (enabled) {
fs.rename(filepath.join(dir, ".git_disabled"), filepath.join(dir, ".git"))
}
break;
default:
processDir(filepath.join(dir, fi.name), enabled, false, fs)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment