Last active
April 19, 2016 18:54
-
-
Save smellymonk/a77b391fe7e8850ca7cc51a3b57d63a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createBranch(repo, newBranchName, remoteName, remoteBranch) { | |
var remoteRefBase = 'refs/remotes/' + remoteName; | |
var remoteRefName = remoteRefBase + '/' + remoteBranch; | |
var remoteRefHead = remoteRefBase + '/' + 'HEAD'; | |
return NodeGit.Reference.symbolicCreate(repo, remoteRefHead, remoteRefName, 1, 'Setting HEAD') | |
.then(function () { | |
return repo.getReference(remoteRefName); | |
}) | |
.then(function (remoteRef) { | |
// Create new branch based on the remote ref | |
return repo.createBranch(newBranchName, remoteRef.target()); | |
}) | |
.then(function (branchRef) { | |
// checkout branch to update working directory | |
return repo.checkoutBranch(branchRef); | |
}); | |
}); | |
} | |
// example | |
repo.fetchAll().then(function () { | |
return createBranch(repo, 'new', 'new', 'master'); | |
}).then(function () { | |
return repo.mergeBranches('new', 'new/master'); | |
}).then(function () { | |
return repo.checkoutBranch('master'); | |
}).then(function () { | |
return repo.mergeBranches('master', 'new'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment