How to use the nodegit.Submodule function in nodegit

To help you get started, we’ve selected a few nodegit 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 twosigma / git-meta / test / util / close.js View on Github external
const subRepo = yield sub.open();
        const origin = yield subRepo.getRemote("origin");
        yield origin.connect(NodeGit.Enums.DIRECTION.FETCH,
                             new NodeGit.RemoteCallbacks(),
                             function () {});
                             yield subRepo.fetch("origin", {});
        subRepo.setHeadDetached(subHead.id().tostrS());
        yield sub.addFinalize();

        // Commit the submodule it.

        yield TestUtil.makeCommit(repo, ["x/y", ".gitmodules"]);

        // Verify that the status currently indicates a visible submodule.

        const addedStatus = yield NodeGit.Submodule.status(repo, "x/y", 0);
        const WD_UNINITIALIZED = (1 << 7);  // means "closed"
        assert(!(addedStatus & WD_UNINITIALIZED));

        // Then close it and recheck status.

        yield close.close(repo, "x/y");
        const closedStatus = yield NodeGit.Submodule.status(repo, "x/y", 0);
        assert(closedStatus & WD_UNINITIALIZED);

        // Make sure we can reopen it.

        yield sub.init(1);
        yield sub.repoInit(1);
        const reopenedStat = yield NodeGit.Submodule.status(repo, "x/y", 0);
        assert(!(reopenedStat & WD_UNINITIALIZED));
    }));
github twosigma / git-meta / node / lib / util / read_repo_ast_util.js View on Github external
yield noteIds.map(readNote);
    }

    // Lastly, load up submodules.

    let openSubmodules = {};

    if (!bare) {
        const index = yield repo.index();
        const subs = yield SubmoduleConfigUtil.getSubmodulesFromIndex(repo,
                                                                      index);
        const subNames = Object.keys(subs);
        for (let i = 0; i < subNames.length; ++i) {
            const subName = subNames[i];
            const status = yield NodeGit.Submodule.status(repo, subName, 0);
            if (status & NodeGit.Submodule.STATUS.IN_WD &&
                !(status & NodeGit.Submodule.STATUS.WD_UNINITIALIZED)) {
                const sub = yield NodeGit.Submodule.lookup(repo, subName);
                const subRepo = yield sub.open();
                const subAST = yield exports.readRAST(subRepo);
                openSubmodules[subName] = subAST;
            }
        }
    }

    // In order to put our commit histories into canonical format, we need to
    // adjust merge commits s.t. the set of changes in a merge commit is
    // "against" the left-most parent, that is, the changes for a commit should
    // not contain duplicates from the first parent.

    const renderCache = {};
github twosigma / git-meta / test / util / read_repo_ast_util.js View on Github external
const addSubmodule = co.wrap(function *(repo, url, path, sha) {
    assert.instanceOf(repo, NodeGit.Repository);
    assert.isString(url);
    assert.isString(path);
    assert.isString(sha);
    const submodule = yield NodeGit.Submodule.addSetup(repo, url, path, 1);
    const subRepo = yield submodule.open();
    const origin = yield subRepo.getRemote("origin");
    yield origin.connect(NodeGit.Enums.DIRECTION.FETCH,
                         new NodeGit.RemoteCallbacks(),
                         function () {});
    yield subRepo.fetch("origin", {});
    subRepo.setHeadDetached(sha);
    const commit = yield subRepo.getCommit(sha);
    yield NodeGit.Reset.reset(subRepo, commit, NodeGit.Reset.TYPE.HARD);
    yield submodule.addFinalize();
    return submodule;
});
github twosigma / git-meta / test / util / submodule_config_util.js View on Github external
const runTest = co.wrap(function *(repo, subRootRepo, url, subName) {
            const subHead = yield subRootRepo.getHeadCommit();
            const submodule   = yield NodeGit.Submodule.addSetup(repo,
                                                                 url,
                                                                 subName,
                                                                 1);
            const subRepo = yield submodule.open();
            yield subRepo.fetchAll();
            subRepo.setHeadDetached(subHead.id());
            const newHead = yield subRepo.getCommit(subHead.id().tostrS());
            yield NodeGit.Reset.reset(subRepo,
                                      newHead,
                                      NodeGit.Reset.TYPE.HARD);
            yield submodule.addFinalize();
            const sig = repo.defaultSignature();
            yield repo.createCommitOnHead([".gitmodules", subName],
                                          sig,
                                          sig,
                                          "my message");
github eclipse / orion.client / modules / orionode / lib / git / submodule.js View on Github external
.then(function(_repo) {
		repo = _repo;
		var path = req.body.Name;
		if (!path) {
			if (req.body.Path) {
				var contextPathSegCount = req.contextPath.split("/").length - 1;
				rest = req.body.Path.split("/").slice(2 + contextPathSegCount).join("/");
				path = fileUtil.getFile(req, rest).path;
			} else if (req.body.Location) {
				path = clone.getUniqueFileName(req.file.path, url.substring(url.lastIndexOf("/") + 1).replace(".git", ""));
			}
			path = path.substring(repo.workdir().length);
		}
		return git.Submodule.addSetup(repo, url, path, 1)
		.then(function() {
			return git.Submodule.lookup(repo, path);
		})
		.then(function(_submodule) {
			submodule = _submodule;
			return submodule.open();
		})
		.then(function(_subrepo) {
			subrepo = _subrepo;
			return subrepo.fetchAll({});
		})
		.then(function() {
			return subrepo.getReferenceCommit("origin/master");
		})
		.then(function(commit) {
			var branch = "master";
github eclipse / orion.client / modules / orionode / lib / git / clone.js View on Github external
freeRepo(theSubmodule);
							return callback();
						}
						var status, subrepo;
						var sublocation = api.join(location, submodule.path());
						function done(json, unitialized) {
							json.SubmoduleStatus = {
								Type: unitialized || status & git.Submodule.STATUS.WD_UNINITIALIZED || subrepo.isEmpty() ?
									"UNINITIALIZED" : "INITIALIZED",
								HeadSHA: submodule.headId() ? submodule.headId().toString() : "",
								Path: submodule.path()
							};
							freeRepo(theSubmodule);
							callback();
						}
						return git.Submodule.status(repo, submodule.name(), -1)
						.then(function(_status) {
							status = _status;
							return submodule.open();
						})
						.then(function(_subrepo) {
							subrepo = _subrepo;
							return pushRepo(modules, subrepo, name, sublocation, submodule.url(), parents, done);
						}).catch(function() {
							var json = cloneJSON(name, sublocation, submodule.url(), parents);
							modules.push(json);
							done(json, true || subrepo.isEmpty());
						})
						.finally(function() {
							freeRepo(subrepo);
						});
					}).catch(function() {
github eclipse / orion.client / modules / orionode / lib / git / submodule.js View on Github external
.then(function() {
			return git.Submodule.lookup(repo, path);
		})
		.then(function(_submodule) {
github elementary / houston / src / lib / service / github.ts View on Github external
protected async recursiveClone (clonePath) {
    const repo = await Git.Repository.open(clonePath)

    await Git.Submodule.foreach(repo, async (submodule) => {
      await submodule.update(1, new Git.SubmoduleUpdateOptions())
      await this.recursiveClone(path.join(clonePath, submodule.path()))
    })
  }
}
github elementary / houston / src / flightcheck / pipeline.js View on Github external
const recursiveClone = async (clonePath) => {
          const subRepo = await git.Repository.open(clonePath)
          await git.Submodule.foreach(subRepo, async (submodule) => {
            await submodule.update(1, new git.SubmoduleUpdateOptions())
            await recursiveClone(path.join(clonePath, submodule.path()))
          })
        }
github eclipse / orion.client / modules / orionode / lib / git / clone.js View on Github external
function done(json, unitialized) {
							json.SubmoduleStatus = {
								Type: unitialized || status & git.Submodule.STATUS.WD_UNINITIALIZED || subrepo.isEmpty() ?
									"UNINITIALIZED" : "INITIALIZED",
								HeadSHA: submodule.headId() ? submodule.headId().toString() : "",
								Path: submodule.path()
							};
							freeRepo(theSubmodule);
							callback();
						}
						return git.Submodule.status(repo, submodule.name(), -1)