Skip to content

Commit cc6bdfa

Browse files
committed
Add git cat-file command support.
1 parent 1fc7aa5 commit cc6bdfa

File tree

1 file changed

+37
-1
lines changed
  • coder-apps/common/vcs/app

1 file changed

+37
-1
lines changed

coder-apps/common/vcs/app/git.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Git.prototype.git = function(/* command, args, options, callback */)
3333
var child = spawn("git", gitargs, { cwd: options.cwd, env: options.env});
3434

3535
child.stderr.setEncoding('utf8');
36-
child.stdout.setEncoding(options.encoding);
36+
if (options.encoding)
37+
child.stdout.setEncoding(options.encoding);
3738

3839
if (callback) {
3940
var called = false;
@@ -219,3 +220,38 @@ Git.prototype.commit = function(/* message, options, callback */) {
219220
], callback);
220221
};
221222

223+
Git.prototype._cat_file = function(/* sha, type, options, callback */) {
224+
var object, type = "-p", options = {}, callback;
225+
var args = Array.prototype.slice.call(arguments);
226+
227+
object = args.shift();
228+
if (typeof args[0] === "string")
229+
type = args.shift();
230+
if (typeof args[0] === "object")
231+
options = args.shift();
232+
233+
callback = args.shift();
234+
235+
var bufs = [];
236+
237+
var child = this.git("cat-file", type, object, {encoding: options.encoding}, callback);
238+
return child.stdout;
239+
};
240+
241+
Git.prototype.cat_file = function(/* sha, type, options, callback */) {
242+
var data = [];
243+
244+
var callback = arguments[arguments.length - 1];
245+
arguments[arguments.length - 1] = function(err) {
246+
callback(err, err ? null : data.join(""));
247+
};
248+
249+
var stdout = this._cat_file.apply(this, arguments)
250+
251+
stdout.on('data', function(d) {
252+
data.push(d);
253+
});
254+
}
255+
256+
module.exports = Git;
257+

0 commit comments

Comments
 (0)