Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const ontoFileContents = await readFileAsync(repoPath + FILE_REBASE_ONTO, {encoding: 'utf8'});
// get the rebase command text file which will give us a list of
// the effected commits
const todoFileContents = await readFileAsync(repoPath + FILE_REBASE_TODO, {encoding: 'utf8'});
if (rebaseHeadFileContents.trim() === ontoFileContents.trim()) {
// not sure if you'd get into this state?
console.log('wtf are you even rebasing bro??');
}
// try to figure out what branch the onto commit is part of.
// is it the head of another branch or is the rebase branch
// getting rebased against itself?
const rebaseHeadCommit = await nodegit.Commit.lookup(repo, rebaseHeadFileContents.trim());
const rebaseBranch = await nodegit.Reference.lookup(repo, rebaseHeadNameFileContents.trim());
const ontoCommit = await nodegit.Commit.lookup(repo, ontoFileContents);
// check and see if the commit is in the current branch
const foundIndex = await utils.searchHistoryForCommit(repo, rebaseHeadCommit, ontoCommit.id());
if (foundIndex >= 0) {
let branchHistory = await branches.getNormalizedSingleBranchHistory(repo, rebaseHeadCommit, rebaseBranch, foundIndex + 3, true, settings);
// tag the affected commits
branchHistory.local.history = await setAffectedCommits(repo, todoFileContents, branchHistory.local.history);
// finally, tag the onto commit
branchHistory.local.history[foundIndex].isRebaseOnto = true;
return { isRebase: true, isMultiBranch: false, ...branchHistory };
}
// if the commit isn't in the current branch already,
}
}
}
yield SparseCheckoutUtil.writeMetaIndex(repo, index);
// Use 'TreeUtil' to create a new tree having the required paths.
const baseTree = yield headCommit.getTree();
const tree = yield TreeUtil.writeTree(repo, baseTree, changes);
// Create a commit with this tree.
const sig = repo.defaultSignature();
const parents = [headCommit];
const commitId = yield NodeGit.Commit.create(
repo,
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);
exports.computeChangesBetweenTwoCommits = co.wrap(function *(repo,
index,
srcCommit,
targetCommit) {
assert.instanceOf(repo, NodeGit.Repository);
assert.instanceOf(index, NodeGit.Index);
assert.instanceOf(srcCommit, NodeGit.Commit);
assert.instanceOf(targetCommit, NodeGit.Commit);
const conflicts = {};
const urls = yield SubmoduleConfigUtil.getSubmodulesFromCommit(
repo,
targetCommit);
// Group together all parts of conflicted entries.
const conflictEntries = new Map(); // name -> normal, ours, theirs
const entries = index.entries();
for (const entry of entries) {
const name = entry.path;
const stage = NodeGit.Index.entryStage(entry);
if (STAGE.NORMAL !== stage) {
let subEntry = conflictEntries.get(name);
if (undefined === subEntry) {
subEntry = {};
conflictEntries.set(name, subEntry);
exports.listRebaseCommits = co.wrap(function *(repo, from, onto) {
assert.instanceOf(repo, NodeGit.Repository);
assert.instanceOf(from, NodeGit.Commit);
assert.instanceOf(onto, NodeGit.Commit);
const ontoSha = onto.id().tostrS();
const seen = new Set([ontoSha]); // shas that stop traversal
const result = [];
const todo = []; // { sha: String | null, parents: [Commit]}
// We proceed as follows:
//
// 1. Each item in the `todo` list represents a child commit with
// zero or more parents left to process.
// 2. If the list of parents is empty in the last element of `todo`,
// record the sha of the child commit of this element into `result`
// (unless it was null, which would indicate a skipped merge commit).
// 3. Otherwise, pop the last parent off and "enqueue" it onto the todo
// list.
// 4. The `enqueue` function will skip any commits that have been
// get the corresponding upstream reference for each branch
const branchOneRemote = await utils.getRemote(branchOne);
let branchTwoRemote = await utils.getRemote(branchTwo);
if (branchOneRemote && branchTwoRemote) {
// get the remote branch head
let branchOneRemoteHead = await nodegit.Commit.lookup(repo, branchOneRemote.target());
// get difference in commits local vs. remote for current branch
let branchOneAheadBy = await getDifferenceBetweenLocalRemote(repo, branchOneHead, branchOneRemoteHead);
// update higher-scope variables
branchOneRemoteAheadBy = branchOneAheadBy.remoteAhead;
branchOneLocalAheadBy = branchOneAheadBy.localAhead;
let branchTwoRemoteHead = await nodegit.Commit.lookup(repo, branchTwoRemote.target());
// get difference in commits local vs. remote for master
let branchTwoAheadBy = await getDifferenceBetweenLocalRemote(repo, branchTwoHead, branchTwoRemoteHead);
// update higher-scope variables
branchTwoRemoteAheadBy = branchTwoAheadBy.remoteAhead;
branchTwoLocalAheadBy = branchTwoAheadBy.localAhead;
// get the combined Remote history of branch & master
remoteHistory = await getMultiBranchHistory(repo,
branchOneRemoteHead, branchOneRemote, branchOneRemoteAheadBy,
branchTwoRemoteHead, branchTwoRemote, branchTwoRemoteAheadBy,
false, settings);
}
// now that we know if local is ahead, we can
function getCommitFromReference(reference) {
// on error: If reference target is something else
// message: the requested type does not match the type in ODB
// errno: -3 }
return NodeGit.Commit.lookup(reference.owner(), reference.target());
}
exports.rewriteCommits = co.wrap(function *(repo, branch, upstream) {
assert.instanceOf(repo, NodeGit.Repository);
assert.instanceOf(branch, NodeGit.Commit);
if (null !== upstream) {
assert.instanceOf(upstream, NodeGit.Commit);
}
const head = yield repo.head();
const headSha = head.target().tostrS();
const branchSha = branch.id().tostrS();
const upstreamSha = (upstream && upstream.id().tostrS()) || null;
const result = {
commits: {},
conflictedCommit: null,
ffwd: false,
};
// If we're up-to-date with the commit to be rebased onto, return
// immediately. Detach head as this is the normal behavior.
if (headSha === branchSha ||
exports.rebase = co.wrap(function *(repo, onto) {
assert.instanceOf(repo, NodeGit.Repository);
assert.instanceOf(onto, NodeGit.Commit);
// First, make sure we're in a state in which we can run a rebase.
const status = yield StatusUtil.getRepoStatus(repo);
StatusUtil.ensureReady(status);
if (!status.isDeepClean(false)) {
throw new UserError(`\
The repository has uncommitted changes. Please stash or commit them before
running rebase.`);
}
const result = {
metaCommits: {},
submoduleCommits: {},
errorMessage: null,
};
exports.getSubmoduleNamesForCommit = co.wrap(function *(repo, commit) {
assert.instanceOf(repo, NodeGit.Repository);
assert.instanceOf(commit, NodeGit.Commit);
const map = yield SubmoduleConfigUtil.getSubmodulesFromCommit(repo,
commit);
return Object.keys(map);
});
function* checkSubmodules(repo, commit) {
assert.instanceOf(repo, NodeGit.Repository);
assert.instanceOf(commit, NodeGit.Commit);
const config = yield repo.config();
const urlWhitelistPattern = (
yield ConfigUtil.getConfigString(
config, "gitmeta.skipsyntheticrefpattern")) || "";
const pathWhitelistPattern = (
yield ConfigUtil.getConfigString(
config, "gitmeta.skipsyntheticrefpathpattern")) || "";
const cfg = new SyntheticBranchConfig(urlWhitelistPattern,
pathWhitelistPattern);
const parent = yield GitUtil.getParentCommit(repo, commit);
const names = yield computeChangedSubmodules(repo,
commit,
parent);