How to use the nodegit.Merge 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 / read_repo_ast_util.js View on Github external
const whamCommit = yield TestUtil.makeCommit(repo, ["s"]);
        const whamSha = whamCommit.id().tostrS();

        // Go back to master and put a different submodule change on it.

        yield repo.checkoutBranch("master");
        const localFoo = yield subRepo.getCommit(fooSha);
        yield NodeGit.Reset.reset(subRepo,
                                  localFoo,
                                  NodeGit.Reset.TYPE.HARD);
        const masterCommit = yield TestUtil.makeCommit(repo, ["s"]);
        const masterSha = masterCommit.id().tostrS();

        // Now make the merge commit.

        let index = yield NodeGit.Merge.commits(repo,
                                                masterCommit,
                                                whamCommit,
                                                null);

        // We're going to ignore the 'bar' commit.

        yield index.conflictCleanup();
        yield index.writeTreeTo(repo);
        yield NodeGit.Checkout.index(repo, index, {
            checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE,
        });
        index = yield repo.index();
        yield index.write();
        const id = yield index.writeTreeTo(repo);
        const mergeCommit = yield repo.createCommit(
                                                 "HEAD",
github twosigma / git-meta / node / lib / util / merge_bare_util.js View on Github external
yield fetcher.fetchSha(subRepo, name, theirSha);
        yield fetcher.fetchSha(subRepo, name, ourSha);
        const theirCommit = yield subRepo.getCommit(theirSha);
        const ourCommit = yield subRepo.getCommit(ourSha);

        // Commit forwards or backwards are handled at meta repo level.
        if ((yield NodeGit.Graph.descendantOf(subRepo, ourSha, theirSha)) ||
            (yield NodeGit.Graph.descendantOf(subRepo, theirSha, ourSha))) {
            return result;                                            // RETURN
        }

        console.log(`Submodule ${colors.blue(name)}: merging commit ` +
            `${colors.green(theirSha)}.`);

        // Start the merge.
        let subIndex = yield NodeGit.Merge.commits(subRepo,
                                                   ourCommit,
                                                   theirCommit,
                                                   null);

        // Abort if conflicted.
        if (subIndex.hasConflicts()) {
            result.conflicts[name] = theirSha;
            return;                                                   // RETURN
        }

        // Otherwise, finish off the merge.
        const treeId = yield subIndex.writeTreeTo(subRepo);
        const mergeCommit 
            = yield subRepo.createCommit(null,
                                         sig,
                                         sig,
github twosigma / git-meta / node / lib / util / merge_util.js View on Github external
if (isHalfOpened) {
            yield CherryPickUtil.addSubmoduleCommit(metaIndex,
                                                    subName,
                                                    theirSha);
        } else {
            yield GitUtil.setHeadHard(subRepo, theirCommit);
            yield metaIndex.addByPath(subName);    
        }
        return result;                                                // RETURN
    }

    console.log(`Submodule ${colors.blue(subName)}: merging commit \
${colors.green(theirSha)}.`);

    // Start the merge.
    let subIndex = yield NodeGit.Merge.commits(subRepo,
                                               ourCommit,
                                               theirCommit,
                                               null);
    if (!isHalfOpened) {
        yield NodeGit.Checkout.index(subRepo, subIndex, {
            checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE,
        });  
    }

    // handle conflicts:
    // 1. if force bare, bubble up conflicts and direct return
    // 2. if this is interactive merge and bare is allowed, open submodule,
    //    record conflicts and then bubble up the conflicts.
    // 3. if bare is not allowed, record conflicts and bubble up conflicts
    if (subIndex.hasConflicts()) {
        if (forceBare) {
github twosigma / git-meta / node / lib / util / git_util.js View on Github external
exports.getMergeBase = co.wrap(function *(repo, x, y) {
    assert.instanceOf(repo, NodeGit.Repository);
    assert.instanceOf(x, NodeGit.Commit);
    assert.instanceOf(y, NodeGit.Commit);

    let baseId;
    try {
        baseId = yield NodeGit.Merge.base(repo, x.id(), y.id());
    } catch (e) {
        // only way to detect lack of base
        return null;
    }
    return yield repo.getCommit(baseId);
});
github twosigma / git-meta / node / lib / util / git_util.js View on Github external
exports.getMergeBase = co.wrap(function *(repo, x, y) {
    assert.instanceOf(repo, NodeGit.Repository);
    assert.instanceOf(x, NodeGit.Commit);
    assert.instanceOf(y, NodeGit.Commit);

    let baseId;
    try {
        baseId = yield NodeGit.Merge.base(repo, x.id(), y.id());
    } catch (e) {
        // only way to detect lack of base
        return null;
    }
    return yield repo.getCommit(baseId);
});
github eclipse / orion.client / modules / orionode / lib / git / commit.js View on Github external
function resolveAncestor(parents) {
		var tree = parents.pop();
		var tree2 = parents.pop();
		return git.Merge.base(repo, tree, tree2).then(function(base) {
			if (parents.length === 0) {
				return base;
			} else {
				parents.push(base);
				return resolveAncestor(parents);
			}
		})
		.catch(function(err) {
			if (err.message === "no merge base found") {
				// two commits in unrelated histories
				return null;
			}
			throw err;
		});
	}
	var commits = [];
github eclipse / orion.client / modules / orionode / lib / git / commit.js View on Github external
return git.Merge.base(repo, head, commit.id()).then(function(base) {
				// the common ancestor is the commit we're trying to merge
				if (base.equal(commit.id())) {
					// already up-to-date, nothing to do
					oid = head;
					return;
				}

				var mergeIndex;
				// try to merge
				return git.Merge.commits(repo, head, commit)
				.then(function(index) {
					mergeIndex = index;
					return repo.getStatus();
				})
				.then(function(statuses) {
					paths = {};
					// see what's in the index/wd
					statuses = statuses.map(function(status) {
						return status.path();
					});
					// compare it with what's in the index
					var entries = mergeIndex.entries();
					entries.forEach(function(entry) {
						if (statuses.indexOf(entry.path) !== -1) {
							paths[entry.path] = "";
						}
github eclipse / orion.client / modules / orionode / lib / git / commit.js View on Github external
.then(function(annotated) {
		return git.Merge.merge(repo, annotated, null, null).then(function() {
			if (repo.state() !== git.Repository.STATE.MERGE) {
				throw new Error("Internal merge failure ");
			}
	
			if (createMergeCommit) {
				var signature = repo.defaultSignature();
				var message = "Merged branch '" + branchToMerge + "'"; 
				return createCommit(repo,
					signature.name(), signature.email(),
					signature.name(), signature.email(),
					message, false, false);
			}
		}).catch (function(err) {
			return getConflictingPaths(repo, head, commit).then(conflictingPathsCallback);
		});
	});
github facebook / react / scripts / bench / build.js View on Github external
async function getMergeBaseFromLocalGitRepo(localRepo) {
  const repo = await Git.Repository.open(localRepo);
  return await Git.Merge.base(
    repo,
    await repo.getHeadCommit(),
    await repo.getBranchCommit('master')
  );
}
github Yamazaki93 / MetroGit / app / git / repo.js View on Github external
return NodeGit.Graph.aheadBehind(Repo, currentBranch.target(), remoteBranch.target()).then(result => {
        if (result.ahead && result.behind) {
            return Promise.reject('LOCAL_AHEAD');
        } else if (!result.behind) {
            return Promise.resolve('UP_TO_DATE')
        } else {
            return Repo.mergeBranches(currentBranch, remoteBranch, getCurrentSignature(), NodeGit.Merge.PREFERENCE.FASTFORWARD_ONLY);
        }
    });
}