How to use the js-git/lib/modes.isFile function in js-git

To help you get started, we’ve selected a few js-git examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github creationix / wheaty / server.js View on Github external
function* render(load, url) {

  var meta = yield* load(url);
  if (!meta) return;
  // Special rules for tree requests.
  if (meta.mode === modes.tree) {
    // Make sure requests for trees end in trailing slashes.
    if (url[url.length - 1] !== "/") {
      return [301, { Location: url + "/" }];
    }
    // Load the actual tree listing, this should be cached by mem-cache.
    var tree = yield repo.loadAs("tree", meta.hash);
    // Look for a index file
    if (tree["index.html"] && modes.isFile(tree["index.html"].mode)) {
      meta = tree["index.html"];
      url = pathJoin(url, "index.html");
      // Fall through down to static file handler.
    }
    // Otherwise render a index file
    else {
      return [200, {
        "ETag": '"' + meta.hash + '-html"',
        "Content-Type": "text/html",
      }, bodec.fromUnicode(formatTree(tree))];
    }
  }

  if (modes.isFile(meta.mode)) {
    var body = yield repo.loadAs("blob", meta.hash);
github creationix / wheaty / lib / node-vfs.js View on Github external
var subRest = "";
      if (meta.last) {
        meta = meta.last;
        subPath = meta.path;
        subRest = meta.rest;
      }

      if (meta.mode === modes.sym) {
        var target = yield repo.loadAs("text", meta.hash);
        target = pathJoin(base, subPath, '..', target, subRest);
        return yield* pathToEntry(target);
      }

      // Check for .gitmodules file
      var modMeta = yield repo.pathToEntry(root, ".gitmodules");
      if (!(modMeta && modes.isFile(modMeta.mode))) {
        throw new Error("Missing .gitmodules file");
      }

      // Load and parse the .gitmodules file.
      // TODO: cache this in memory by path and hash
      var config = configCodec.decode(yield repo.loadAs("text", modMeta.hash));
      config = config.submodule[subPath];
      if (!config) {
        throw new Error("Missing .gitmodules entry for " + subPath);
      }

      // Iterate the search loop with the new repo and path.
      ref = config.ref || "refs/heads/master";
      repo = yield getRepo(config.url, ref);
      commitHash = meta.hash;
      base = subPath;
github creationix / wheaty / wheaty.js View on Github external
}
      else {
        url = pathJoin(url.substring(0, index), "index.html") + url.substring(index);
      }
      // Fall through down to static file handler.
    }
    // Otherwise render a index file
    else {
      return [200, {
        "ETag": '"' + meta.hash + '-html"',
        "Content-Type": "text/html",
      }, bodec.fromUnicode(formatTree(tree, url))];
    }
  }

  if (modes.isFile(meta.mode)) {
    var body = yield meta.repo.loadAs("blob", meta.hash);

    if (meta.mode === modes.exec) {
      // #! but not #!/
      if (body[0] === 0x23 && body[1] === 0x21 && body[2] !== 0x2f) {
        var i = 2;
        var language = "";
        while (i < body.length && body[i] !== 0x0d && body[i] !== 0x0a) {
          language += String.fromCharCode(body[i++]);
        }
        var runtime = runtimes[language];
        if (!runtime) {
          throw new Error("Invalid runtime specified: " + JSON.stringify(language));
        }
        body = bodec.slice(body, i);
        if (runtime.constructor === Function) {
github creationix / tedit / src / ui / tree-6.js View on Github external
function onGlobalClick(evt) {
  var row = findRow(evt.target);
  if (!row) return;
  nullify(evt);
  if (row.mode === modes.tree || row.mode === modes.commit) {
    if (openPaths[row.path]) closeTree(row);
    else openTree(row);
  }
  else if (modes.isFile(row.mode)) {
    activateDoc(row);
  }
  else if (row.mode === modes.sym) {
    editSymLink(row);
  }
  else {
    console.log("TODO: handle click", row);
  }
}
github creationix / tedit / src / ui / tree.js View on Github external
row.call(fs.prepEntry, newPath, function () {
        if (modes.isFile(row.mode)) activePath = path;
        row.call(copy, path);
        row.call(fs.copyEntry, path);
      });
    });
github creationix / tedit / src / ui / tree.js View on Github external
function activateRow(row, hard) {
  if (row.mode === modes.tree || row.mode === modes.commit) {
    if (openPaths[row.path]) closeTree(row);
    else openTree(row);
  }
  else if (modes.isFile(row.mode)) {
    activateDoc(row, hard);
  }
  else if (row.mode === modes.sym) {
    editSymLink(row);
  }
  else {
    row.fail(new Error("Unknown node mode"));
  }
}
github creationix / wheat / renderers.js View on Github external
function* renderIndex() {
  /*jshint validthis:true*/
  var meta = yield* this.pathToEntry("articles");
  if (!meta || !meta.mode) return;
  var articles = yield* loadArticles.call(this, meta);
  var description = "";
  meta = yield* this.pathToEntry("description.markdown");
  if (meta && modes.isFile(meta.mode)) {
    description = yield meta.repo.loadAs("text", meta.hash);
  }
  yield* render.call(this, "index", {
    articles: articles,
    description: description,
  });

}
github creationix / tedit / src / ui / tree.js View on Github external
function makeMenu(row) {
  row = row || rootRow;
  var actions = [];
  var type = row.mode === modes.tree ? "Folder" :
             modes.isFile(row.mode) ? "File" :
             row.mode === modes.sym ? "SymLink" :
             row.path.indexOf("/") < 0 ? "Repo" : "Submodule";
  if (row.mode === modes.tree || row.mode === modes.commit) {
    if (openPaths[row.path]) {
      actions.push(
        {icon:"doc", label:"Create File", action: createFile},
        {icon:"folder", label:"Create Folder", action: createFolder},
        {icon:"link", label:"Create SymLink", action: createSymLink}
      );
      if (backends.length) {
        actions.push({sep:true});
        backends.forEach(function (backend) {
          if (backend.menuItem) actions.push(backend.menuItem);
        });
      }
      if (!row.path) {
github creationix / tedit / src / ui / tree.js View on Github external
makeUnique(row, name, mode, function (path) {
    if (modes.isFile(mode)) {
      activePath = path;
    }
    openPaths[row.path] = true;
    row.call(path, fs.writeEntry, {
      mode: mode,
      hash: hash
    });
  });
}
github creationix / tedit / src / ui / tree-6.js View on Github external
makeUnique(row, name, mode, function (path) {
    if (modes.isFile(mode)) {
      activePath = path;
    }
    row.call(path, fs.writeEntry, {
      mode: mode,
      hash: hash
    });
  });
}