How to use the nodegit.Branch 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 DefinitelyTyped / DefinitelyTyped / types / nodegit / nodegit-tests.ts View on Github external
let result = Git.Attr.addMacro(repo, "name", "values");

Git.Attr.cacheFlush(repo);

Git.Attr.get(repo, 1, "path", "name").then((string) => {
    // Use string
});

const array = Git.Attr.getMany(repo, 1, "path", 1, "names");

result = Git.Attr.value("attr");

const blameOptions = new Git.BlameOptions();

Git.Branch.lookup(repo, "branch_name", Git.Branch.BRANCH.LOCAL).then((reference) => {
    // Use reference
});

repo.getCommit("0123456789abcdef0123456789abcdef").then((commit) => {
  const sig = Git.Signature.now('John Doe', 'jd@example.com');
  const newCommit: Promise = commit.amend('ref', sig, sig, 'utf8', 'message', tree);
});

const signature = Git.Signature.now("name", "email");
signature.name();
signature.email();
signature.when();

repo.createBlobFromBuffer(Buffer.from("test")).then((oid: Git.Oid) => oid.cpy());
repo.commondir();
github twosigma / git-meta / test / util / read_repo_ast_util.js View on Github external
it("simple detached", co.wrap(function *() {
        const r = yield TestUtil.createSimpleRepository();
        r.detachHead();
        const branch = yield r.getBranch("master");
        NodeGit.Branch.delete(branch);
        const ast = yield ReadRepoASTUtil.readRAST(r);
        const headId = yield r.getHeadCommit();
        const commit = headId.id().tostrS();
        let commits = {};
        commits[commit] = new Commit({
            changes: { "README.md": ""},
            message: "first commit",
        });
        const expected = new RepoAST({
            commits: commits,
            branches: {},
            head: commit,
            currentBranchName: null,
        });
        RepoASTUtil.assertEqualASTs(ast, expected);
    }));
github eclipse / orion.client / modules / orionode / lib / git / branches.js View on Github external
return Promise.all(branches.map(function(branch) {
								return git.Branch.lookup(repo, api.join(remote.name(), branch.Name), git.Branch.BRANCH.REMOTE).then(function(remoteBranch) {
									return repo.getBranchCommit(remoteBranch).then(function(commit) {
										var rJson = mRemotes.remoteJSON(remote, fileDir, [mRemotes.remoteBranchJSON(remoteBranch, commit, remote, fileDir)]);
										var trackingRemote = config.branch && config.branch[branch.Name] && config.branch[branch.Name].remote;
										if (trackingRemote === remote.name() || !trackingRemote) {
											branch["RemoteLocation"].splice(0, 0, rJson);
										} else {
											branch["RemoteLocation"].push(rJson);
										}
									});
								}).catch(function() {
									//No remote tracking branch
									branch["RemoteLocation"].push(mRemotes.remoteJSON(remote, fileDir, [mRemotes.remoteBranchJSON(null, null, remote, fileDir, branch)]));
								});
							}));
						})
github eclipse / orion.client / modules / orionode / lib / git / branches.js View on Github external
.then(function(commit) {
			if (!branchName) {
				branchName = theRef.shorthand().split("/").slice(1).join("/");
			}
			return git.Branch.create(theRepo, branchName, commit, 0);
		})
		.then(function(ref) {
github twosigma / git-meta / node / lib / util / branch.js View on Github external
const deleteBranch = co.wrap(function *(repo) {
        const branch = yield GitUtil.findBranch(repo, branchName);
        if (null !== branch) {
            NodeGit.Branch.delete(branch);
        }
    });
github Yamazaki93 / MetroGit / app / git / repo.js View on Github external
function findMatchingRemote(currentBranch) {
    return NodeGit.Branch.upstream(currentBranch).catch(err => {
        return Promise.reject('UPSTREAM_NOT_FOUND');
    })
}
github eclipse / orion.client / modules / orionode / lib / git / branches.js View on Github external
.then(function(ref) {
			if (git.Branch.delete(ref) === 0) {
				res.status(200).end();
			} else {
				writeError(403, res);
			}
		})
		.catch(function() {
github nicolas-schmitt / multi-git / lib / multi-git.js View on Github external
.then((branch) => {
                    return nodegit.Branch.upstream(repository.currentBranch);
                }, (error) => {
                    repository.status.upstream = 'none';
github twosigma / git-meta / node / lib / util / checkout.js View on Github external
}
    if (null !== newBranch) {
        const name = newBranch.name;
        const branch = yield GitUtil.createBranchFromHead(repo, name);
        const tracking = newBranch.tracking;
        if (null !== tracking) {
            const trackingName = tracking.branchName;
            const remote = tracking.remoteName;
            let trackingBranchName;
            if (null !== remote) {
                trackingBranchName = `${remote}/${trackingName}`;
            }
            else {
                trackingBranchName = trackingName;
            }
            yield NodeGit.Branch.setUpstream(branch, trackingBranchName);
        }
    }
    if (null !== switchBranch) {
        yield repo.setHead(`refs/heads/${switchBranch}`);
    }
});