@@ -18,16 +18,71 @@ Object.defineProperty(Repository.prototype, "openIndex", {
1818} ) ;
1919
2020/**
21- * Look up a branch"s most recent commit.
21+ * Creates a branch with the passed in name pointing to the commit
22+ *
23+ * @param {String } name Branch name, e.g. "master"
24+ * @param {Commit|String|Oid } commit The commit the branch will point to
25+ * @param {bool } force Overwrite branch if it exists
26+ * @param {Signature } signature Identity to use to populate reflog
27+ * @param {String } logMessage One line message to be appended to the reflog
28+ * @return {Ref }
29+ */
30+ Repository . prototype . createBranch =
31+ function ( name , commit , force , signature , logMessage ) {
32+ var repo = this ;
33+
34+ if ( commit instanceof Commit ) {
35+ return NodeGit . Branch . create (
36+ repo ,
37+ name ,
38+ commit ,
39+ force ? 1 : 0 ,
40+ signature ,
41+ logMessage ) ;
42+ }
43+ else {
44+ return repo . getCommit ( commit ) . then ( function ( commit ) {
45+ return NodeGit . Branch . create (
46+ repo ,
47+ name ,
48+ commit ,
49+ force ? 1 : 0 ,
50+ signature ,
51+ logMessage ) ;
52+ } ) ;
53+ }
54+ } ;
55+
56+ /**
57+ * Look up a branch
2258 *
2359 * @param {String } name Branch name, e.g. "master"
2460 * @param {Function } callback
25- * @return {Branch }
61+ * @return {Ref }
2662 */
2763Repository . prototype . getBranch = function ( name , callback ) {
64+ name = ~ name . indexOf ( "refs/heads/" ) ? name : "refs/heads/" + name ;
65+
66+ return this . getReference ( name ) . then ( function ( reference ) {
67+ if ( typeof callback === "function" ) {
68+ callback ( null , reference ) ;
69+ }
70+
71+ return reference ;
72+ } , callback ) ;
73+ } ;
74+
75+ /**
76+ * Look up a branch's most recent commit.
77+ *
78+ * @param {String } name Branch name, e.g. "master"
79+ * @param {Function } callback
80+ * @return {Commit }
81+ */
82+ Repository . prototype . getBranchCommit = function ( name , callback ) {
2883 var repository = this ;
2984
30- return this . getReference ( "refs/heads/" + name ) . then ( function ( reference ) {
85+ return this . getBranch ( name ) . then ( function ( reference ) {
3186 return repository . getCommit ( reference . target ( ) ) . then ( function ( commit ) {
3287 if ( typeof callback === "function" ) {
3388 callback ( null , commit ) ;
@@ -262,13 +317,13 @@ Repository.prototype.createRevWalk = function() {
262317} ;
263318
264319/**
265- * Retrieve the master branch.
320+ * Retrieve the master branch commit .
266321 *
267322 * @param {Function } callback
268- * @return {Branch }
323+ * @return {Commit }
269324 */
270- Repository . prototype . getMaster = function ( callback ) {
271- return this . getBranch ( "master" , callback ) ;
325+ Repository . prototype . getMasterCommit = function ( callback ) {
326+ return this . getBranchCommit ( "master" , callback ) ;
272327} ;
273328
274329/**
0 commit comments