How to use js-git - 10 common examples

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 / tedit / src / data / git-tree.js View on Github external
function resolvePath(path, bake, callback) {
    var mode = modes.commit;
    var hash = storage.getRootHash();
    var root = "";

    var parts = path.split("/").filter(Boolean);
    path = parts.join("/");
    var index = 0;
    var partial = "";

    // In baked mode, we need to remember tree rules.
    var rules = bake ? [] : null;

    // Start the walk loop.
    return walk();

    function walk() {
      while (index < parts.length) {
github creationix / tedit / src / ui / tree-6.js View on Github external
], function (result) {
    if (!result) return;
    var url = result.url;
    // Assume github if user/name combo is given
    if (/^[^\/:@]+\/[^\/:@]+$/.test(url)) {
      url = "git@github.com:" + url + ".git";
    }
    var name = result.name || result.url.substring(result.url.lastIndexOf("/") + 1);
    var ref = result.ref || "refs/heads/master";
    makeUnique(row, name, modes.commit, function (path) {
      row.call(path, fs.addRepo, { url: url, ref: ref });
    });
  });
}
github creationix / git-tree / git-tree.js View on Github external
Object.keys(tree).forEach(function (key) {
        var entry = tree[key];

        // Copy non-rules as-is
        if (entry.mode !== modes.exec || !/\.rule$/.test(key)) {
          newTree[key] = entry;
          return;
        }

        var childPath = path ? path + "/" + key : key;
        var childRule = {
          path: childPath,
          root: root,
          hash: entry.hash
        };
        key = key.substring(0, key.length - 5);
        local[key] = loadRule(childPath, childRule);
      });
github creationix / tedit / src / git-tree.js View on Github external
function resolvePath(path, bake, callback) {
    var mode = modes.commit;
    var hash = storage.getRootHash();
    var root = "";

    var parts = path.split("/").filter(Boolean);
    path = parts.join("/");
    var index = 0;
    var partial = "";

    // In baked mode, we need to remember tree rules.
    var rules = bake ? [] : null;

    // Start the walk loop.
    return walk();

    function walk() {
      while (index < parts.length) {
github creationix / tedit / src / data / publisher.js View on Github external
function bake(req, callback) {
    req.ruleHash = sha1(JSON.stringify(req));
    // console.log("BAKE", {
    //   req: req,
    //   settings: settings
    // });
    if (!settings.filters) {
      // TODO: serve rule file as static file.
      return callback(null, {mode:modes.file,hash:"TODO:servefile",fetch:function (callback) {
        callback(null, binary.fromUnicode("TODO:servefile"));
      }});
    }

    var codeHash;
    var codePath = pathJoin(settings.filters, req.program + ".js");
    return servePath(codePath, onCodeEntry);

    function onCodeEntry(err, entry) {
      if (err) return callback(err);
      if (!entry.hash) return callback(new Error("Missing filter " + req.name));
      req.codeHash = codeHash = entry.hash;
      // If the code hasn't changed, reuse the existing compiled worker.
      if (codeHashes[req.program] === codeHash) {
        return filters[req.program](servePath, req, callback);
      }
github creationix / tedit / src / git-tree.js View on Github external
Object.keys(tree).forEach(function (key) {
        var entry = tree[key];

        // Copy non-rules as-is
        if (entry.mode !== modes.exec || !/\.rule$/.test(key)) {
          newTree[key] = entry;
          return;
        }

        var childPath = path ? path + "/" + key : key;
        var childRule = {
          path: childPath,
          root: root,
          hash: entry.hash
        };
        key = key.substring(0, key.length - 5);
        local[key] = loadRule(childPath, childRule);
      });
github creationix / tedit / src / data / publisher.js View on Github external
function bake(req, callback) {
    req.ruleHash = sha1(JSON.stringify(req));
    // console.log("BAKE", {
    //   req: req,
    //   settings: settings
    // });
    if (!settings.filters) {
      // TODO: serve rule file as static file.
      return callback(null, {mode:modes.file,hash:"TODO:servefile",fetch:function (callback) {
        callback(null, binary.fromUnicode("TODO:servefile"));
      }});
    }

    var codeHash;
    var codePath = pathJoin(settings.filters, req.program + ".js");
    return servePath(codePath, onCodeEntry);

    function onCodeEntry(err, entry) {
      if (err) return callback(err);
      if (!entry.hash) return callback(new Error("Missing filter " + req.name));
      req.codeHash = codeHash = entry.hash;
      // If the code hasn't changed, reuse the existing compiled worker.
      if (codeHashes[req.program] === codeHash) {
        return filters[req.program](servePath, req, callback);
      }
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) {