How to use the js-git/lib/modes.js.commit 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 / 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 / git-tree.js View on Github external
var entry = { root: root };
      // In raw mode, simply send the result back
      if (!bake) {
        if (found) {
          entry.hash = hash;
          entry.mode = mode;
        }
        if (callback) return callback(null, entry);
        return entry;
      }

      // In bake mode
      if (!found) return callback();

      // Resolve commits to be trees
      if (mode === modes.commit) {
        if (!check("commit", hash)) return;
        mode = modes.tree;
        hash = storage.get(hash).tree;
      }

      // Serve the static blob or tree
      var type = modes.toType(mode);
      entry.hash = hash;
      entry.mode = mode;
      var overlays = [];
      entry.fetch = function (callback) {
        return storage.loadAs(root, type, hash, function (err, result) {
          if (err) return callback(err);
          if (entry.mode === modes.tree) {
            return applyOverlays(result, overlays, callback);
          }
github creationix / tedit / src / git-tree.js View on Github external
function writeEntry(path, entry, callback) {
    if (!callback) return writeEntry.bind(null, path, entry);
    if (!pendingWrites) {
      // Start recording writes to be written
      pendingWrites = {};
      writeCallbacks = [];
      // Defer starting the write to collect more writes this tick.
      defer(writeEntries);
    }
    if (!path) {
      if (!entry.hash) {
        return callback(new Error("Root cannot be deleted"));
      }
      if (entry.mode !== modes.commit) {
        return callback(new Error("Only commits can be written to root"));
      }
    }
    pendingWrites[path] = entry;
    if (callback) writeCallbacks.push(callback);
  }
github creationix / tedit / src / ui / tree.js View on Github external
function onChange(hash) {
  renderChild("", modes.commit, hash);
  // Run any hooks
  Object.keys(hooks).forEach(function (root) {
    hooks[root](hash);
  });
}
github creationix / tedit / src / ui / tree.js View on Github external
function init() {
    if ((mode === modes.tree || mode === modes.commit) && openPaths[path]) openTree(row);
    if (activePath && activePath === path) activateDoc(row, !selected);
  }
github creationix / tedit / src / ui / tree.js View on Github external
fs.init(onChange, function (err, hash) {
  if (err) throw err;
  openPaths[""] = true;
  rootRow = renderChild("", modes.commit, hash);
  rootEl.appendChild(rootRow.el);
});
github creationix / tedit / src / ui / tree.js View on Github external
defer(function () {
    if (mode === modes.commit) row.call(fs.readCommit, onCommit);
    else init();
  });
github creationix / tedit / src / git-tree.js View on Github external
function deepCopy(source, dest, entry, callback) {
    if (!callback) return deepCopy.bind(null, source, dest, entry);
    if (entry.mode === modes.commit) return callback();
    var type = modes.toType(entry.mode);
    source.loadAs(type, entry.hash, function (err, value) {
      if (!value) return callback(err || new Error("Missing " + type + " " + entry.hash));
      dest.saveAs(type, value, function (err) {
        if (err) return callback(err);
        if (type !== "tree") return callback();
        carallel(Object.keys(value).map(function (name) {
          return deepCopy(source, dest, value[name]);
        }), callback);
      }, entry.hash);
    });
  }
github creationix / tedit / src / ui / row.js View on Github external
function updateIcon() {
    var value =
      (errorMessage ? "icon-attention" :
      busy ? "icon-spin1 animate-spin" :
      mode === modes.sym ? "icon-link" :
      mode === modes.file ? "icon-doc" :
      mode === modes.exec ? "icon-cog" :
      mode === modes.commit ? "icon-fork" :
      open ? "icon-folder-open" : "icon-folder") +
        (mode === modes.commit ? " tight" : "");
    $.icon.setAttribute("class", value);
    var title = modes.toType(mode) + " " + hash;
    if (errorMessage) title += "\n" + errorMessage;
    $.icon.setAttribute("title", title);
    if (mode !== modes.commit) {
      if ($.folder) {
        $.row.removeChild($.folder);
        delete $.folder;
      }
    }
    else {
      if (!$.folder) {
        $.row.insertBefore(domBuilder(["i$folder"], $), $.icon);
      }
      $.folder.setAttribute("class", "icon-folder" + (open ? "-open" : ""));
      $.folder.setAttribute("title", "tree " + treeHash);
    }
    if (ahead) {
      if (!$.ahead) {
        $.row.appendChild(domBuilder(["i$ahead"], $));
        $.ahead.setAttribute("class", "icon-upload-cloud");