11var git = require ( '../' ) ,
22 util = require ( './util.js' ) ,
33 Repo = git . Repo ,
4+ Tree = git . Tree ,
45 Reference = git . Reference ;
56
67/**
@@ -146,20 +147,52 @@ Repo.prototype.getMaster = function(callback) {
146147
147148/**
148149 * Create a commit
149- *
150- * @param {String|Oid } String sha or Oid
151- * @param {Blob~lookupCallback } callback
150+ * @param {String } updateRef
151+ * @param {Signature } author
152+ * @param {Signature } commiter
153+ * @param {String } message
154+ * @param {Tree|Oid|String } Tree
155+ * @param {Array } parents
156+ * @param {Function } callback
152157 */
153158var oldCreateCommit = Repo . prototype . createCommit ;
154159Repo . prototype . createCommit = function ( updateRef , author , committer , message , tree , parents , callback ) {
155- oldCreateCommit . call (
156- this ,
157- updateRef ,
158- author ,
159- committer ,
160- null /* use default message encoding */ ,
161- message ,
162- tree ,
163- parents . length , parents ,
164- callback ) ;
160+ if ( tree instanceof Tree ) {
161+ oldCreateCommit . call (
162+ this ,
163+ updateRef ,
164+ author ,
165+ committer ,
166+ null /* use default message encoding */ ,
167+ message ,
168+ tree ,
169+ parents . length , parents ,
170+ callback ) ;
171+ } else {
172+ var self = this ;
173+ this . getTree ( tree , function ( error , tree ) {
174+ if ( error ) return callback ( error ) ;
175+ oldCreateCommit . call (
176+ self ,
177+ updateRef ,
178+ author ,
179+ committer ,
180+ null /* use default message encoding */ ,
181+ message ,
182+ tree ,
183+ parents . length , parents ,
184+ callback ) ;
185+ } ) ;
186+ }
165187} ;
188+
189+ /**
190+ * Create a blob from a buffer
191+ *
192+ * @param {Buffer } buffer
193+ * @param {Function } callback
194+ */
195+ var oldCreateBlobFromBuffer = Repo . prototype . createBlobFromBuffer ;
196+ Repo . prototype . createBlobFromBuffer = function ( buffer , callback ) {
197+ oldCreateBlobFromBuffer . call ( this , buffer , buffer . length , callback ) ;
198+ } ;
0 commit comments