How to use the nodegit.Reset 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 / node / lib / util / commit.js View on Github external
0,
                                          sig,
                                          sig,
                                          0,
                                          exports.ensureEolOnLastLine(message),
                                          tree,
                                          parents.length,
                                          parents);

    // Now we need to put the commit on head.  We need to unstage the changes
    // we've just committed, otherwise we see conflicts with the workdir.  We
    // do a SOFT reset because we don't want to affect index changes for paths
    // you didn't touch.

    const commit = yield repo.getCommit(commitId);
    yield NodeGit.Reset.reset(repo, commit, NodeGit.Reset.TYPE.SOFT);
    return commitId.tostrS();
});
github twosigma / git-meta / node / lib / util / commit.js View on Github external
const subRepo = yield SubmoduleUtil.getRepo(repo, subName);

        // If the submodule is to be amended, we don't do the normal commit
        // process.

        if (doAmend) {
            // First, we check to see if this submodule needs to have its last
            // commit stripped.  That will be the case if we have no files
            // staged indicated as staged.

            assert.isNotNull(repoStatus);
            if (0 === numStaged) {
                const head = yield subRepo.getHeadCommit();
                const parent = yield GitUtil.getParentCommit(subRepo, head);
                const TYPE = NodeGit.Reset.TYPE;
                const type = all ? TYPE.HARD : TYPE.MIXED;
                yield NodeGit.Reset.reset(subRepo, parent, type);
                return;                                               // RETURN

            }
            const subIndex = yield subRepo.index();
            if (all) {
                const actualStatus = yield StatusUtil.getRepoStatus(subRepo, {
                    showMetaChanges: true,
                });

                // TODO: factor this out.  We cannot use `repoStatus` to
                // determine what to stage as it shows the status vs. HEAD^
                // and so some things that should be changed will not be in it.
                //  We cannot call `Index.addAll` because it will stage
                //  untracked files.  Therefore, we need to use our normal
github facebook / react / scripts / bench / build.js View on Github external
if (clean) {
      //clear remote-repo folder
      await cleanDir(remoteRepoDir);
    }
    // check if remote-repo directory already exists
    if (existsSync(join(__dirname, 'remote-repo'))) {
      repo = await Git.Repository.open(remoteRepoDir);
      // fetch all the latest remote changes
      await repo.fetchAll();
    } else {
      // if not, clone the repo to remote-repo folder
      repo = await Git.Clone(url, remoteRepoDir);
    }
    let commit = await repo.getBranchCommit('master');
    // reset hard to this remote head
    await Git.Reset.reset(repo, commit, Git.Reset.TYPE.HARD);
    // then we checkout the latest master head
    await repo.checkoutBranch('master');
    // make sure we pull in the latest changes
    await repo.mergeBranches('master', 'origin/master');
    // then we check if we need to move the HEAD to the merge base
    if (commitId && commitId !== 'master') {
      // as the commitId probably came from our local repo
      // we use it to lookup the right commit in our remote repo
      commit = await Git.Commit.lookup(repo, commitId);
      // then we checkout the merge base
      await Git.Checkout.tree(repo, commit);
    }
    await buildReactBundles();
  }
}
github twosigma / git-meta / node / lib / util / commit.js View on Github external
0,
                                          sig,
                                          sig,
                                          0,
                                          exports.ensureEolOnLastLine(message),
                                          tree,
                                          parents.length,
                                          parents);

    // Now we need to put the commit on head.  We need to unstage the changes
    // we've just committed, otherwise we see conflicts with the workdir.  We
    // do a SOFT reset because we don't want to affect index changes for paths
    // you didn't touch.

    const commit = yield repo.getCommit(commitId);
    yield NodeGit.Reset.reset(repo, commit, NodeGit.Reset.TYPE.SOFT);
    return commitId.tostrS();
});
github twosigma / git-meta / node / lib / util / reset.js View on Github external
function getType(type) {
    assert.property(TYPE, type);
    switch (type) {
        case TYPE.SOFT : return NodeGit.Reset.TYPE.SOFT;
        case TYPE.MIXED: return NodeGit.Reset.TYPE.MIXED;
        case TYPE.HARD : return NodeGit.Reset.TYPE.HARD;

        // TODO: real implementation of `reset --merge`.  For now, this behaves
        // just like `HARD` except that we ignore the check for modified open
        // submodules.

        case TYPE.MERGE: return NodeGit.Reset.TYPE.HARD;
    }
}
github Soluto / tweek / services / management / src / rules-cache.js View on Github external
async function syncRepo(repo) {
  await repo.fetchAll(fetchOpts);
  await repo.mergeBranches('master', 'origin/master');

  const remoteCommit = await repo.getBranchCommit('remotes/origin/master');
  const localCommit = await repo.getBranchCommit('master');

  if (remoteCommit.id().equal(localCommit.id()) === 1) return;

  console.warn('Repo is not synced after pull');
  await Git.Reset.reset(repo, remoteCommit, Git.Reset.TYPE.HARD);
}
github empiricalci / emp / lib / git-clone.js View on Github external
return repo.getCommit(Git.Oid.fromString(sha)).then(function (commit) {
        return Git.Reset.reset(repo, commit, Git.Reset.TYPE.HARD).then(function () {
          return repo
        })
      })
    }
github eclipse / orion.client / modules / orionode / lib / git / index.js View on Github external
.then(function(commit) {
		if (req.body.Path) {
			var paths = req.body.Path;
			if (typeof paths === "string") {
				paths = [paths];
			}
			return git.Reset.default(repo, commit, paths);
		} else if (resetType) {
			var reset_type = git.Reset.TYPE.HARD;
			switch (resetType) {
				case "HARD":
					reset_type = git.Reset.TYPE.HARD;
					break;
				case "MIXED":
					reset_type = git.Reset.TYPE.MIXED;
					break;
				case "SOFT":
					reset_type = git.Reset.TYPE.SOFT;
					break;
			}
			return git.Reset.reset(repo, commit, reset_type, {});
		}
github eclipse / orion.client / modules / orionode / lib / git / index.js View on Github external
}
			return git.Reset.default(repo, commit, paths);
		} else if (resetType) {
			var reset_type = git.Reset.TYPE.HARD;
			switch (resetType) {
				case "HARD":
					reset_type = git.Reset.TYPE.HARD;
					break;
				case "MIXED":
					reset_type = git.Reset.TYPE.MIXED;
					break;
				case "SOFT":
					reset_type = git.Reset.TYPE.SOFT;
					break;
			}
			return git.Reset.reset(repo, commit, reset_type, {});
		} 
			
		return git.Reset.default(repo, commit, [filePath]);
	})
	.then(function() {
github eclipse / orion.client / modules / orionode / lib / git / index.js View on Github external
.then(function(commit) {
		if (req.body.Path) {
			var paths = req.body.Path;
			if (typeof paths === "string") {
				paths = [paths];
			}
			return git.Reset.default(repo, commit, paths);
		} else if (resetType) {
			var reset_type = git.Reset.TYPE.HARD;
			switch (resetType) {
				case "HARD":
					reset_type = git.Reset.TYPE.HARD;
					break;
				case "MIXED":
					reset_type = git.Reset.TYPE.MIXED;
					break;
				case "SOFT":
					reset_type = git.Reset.TYPE.SOFT;
					break;
			}
			return git.Reset.reset(repo, commit, reset_type, {});
		} 
			
		return git.Reset.default(repo, commit, [filePath]);
	})
	.then(function() {