How to use the js-git/lib/modes.tree 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 / data / repos.js View on Github external
if (!entry) {
      var match = findMatch(tree, name);
      if (match) {
        entry = tree[match.key];
        return repo.loadAs("text", entry.hash, function (err, link) {
          if (err) return callback(err);
          mode = modes.sym;
          hash = entry.hash + "-" + match.value;
          return onSym(null, link.replace(match.variable, match.value));
        });
      }
      return callback();
    }
    mode = entry.mode;
    hash = entry.hash;
    if (mode === modes.tree) {
      path += "/" + name;
      return repo.loadAs("tree", hash, onTree);
    }
    if (entry.mode === modes.sym) {
      return repo.loadAs("text", entry.hash, onSym);
    }
    if (entry.mode === modes.commit) {
      path += "/" + name;
      return loadConfig(path, entry.hash, function (err, pair) {
        if (err) return callback(err);
        // Start over with this repo as the new root.
        rootPath = path;
        repo = pair.repo;
        var config = pair.config;
        return repo.loadAs("commit", config.current, onCommit);
      });
github creationix / tedit / src / runtimes / local-export.js View on Github external
servePath(source, function (err, entry) {
      if (!entry) return callback(err || new Error("Can't find " + source));
      // Always walk trees because there might be symlinks under them that point
      // to changed content without the tree's content actually changing.
      if (entry.mode === modes.tree) {
        return exportTree(source, target, entry, callback);
      }
      // Skip already exported files
      var hash = memory[source];
      if (hash && entry.hash === hash) {
        return callback();
      }
      exportFile(source, target, entry, callback);
    });
  }
github creationix / tedit / src / data / git-tree.js View on Github external
// 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);
          }
          callback(null, result);
        });
      };
      if (entry.mode === modes.tree) {
        return loadOverlays(overlays, function (err) {
          if (err) return callback(err);
          callback(null, entry);
        });
      }
      callback(null, entry);
    }
github creationix / tedit / src / data / repos.js View on Github external
function onCommit(err, commit) {
    if (!commit) return callback(err || new Error("Missing commit " + hash));
    mode = modes.tree;
    hash = commit.tree;
    repo.loadAs("tree", hash, onTree);
  }
github creationix / git-tree / git-tree.js View on Github external
function onTree(err, tree) {
        var hash = entry.hash;
        if (!tree) return callback(err || new Error("Missing tree " + hash));
        entry.mode = modes.tree;
        entry.hash = hash;
        entry.tree = tree;
        callback(null, entry);
      }
    }
github creationix / tedit / src / ui / tree-6.js View on Github external
function onUnique() {
    path = (row.path ? row.path + "/" : "") + parts.join("/");
    var dirParts = mode === modes.tree ? parts : parts.slice(0, parts.length - 1);
    if (dirParts.length) {
      var dirPath = row.path;
      dirParts.forEach(function (name) {
        dirPath = dirPath ? dirPath + "/" + name : name;
        openPaths[dirPath] = true;
      });
      prefs.save();
    }
    callback(path);
  }
}
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);
        });
      }