Skip to content

Commit 8aafb8d

Browse files
committed
Make passing args to git more flexible.
1 parent 935beab commit 8aafb8d

File tree

1 file changed

+16
-14
lines changed
  • coder-apps/common/vcs/app

1 file changed

+16
-14
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ var Git = function(p)
1212

1313
Git.prototype.git = function(/* command, args, options, callback */)
1414
{
15-
var command, gitargs = [], options = {}, callback = null;
15+
var gitargs = [], options = {}, callback = null;
1616
var args = Array.prototype.slice.call(arguments);
1717

18-
command = args.shift();
18+
gitargs.push(args.shift());
19+
while (typeof args[0] === "string")
20+
gitargs.push(args.shift());
1921
if (util.isArray(args[0]))
20-
gitargs = args.shift();
22+
gitargs = gitargs.concat(args.shift());
23+
2124
if (typeof args[0] === "object")
2225
options = args.shift();
2326
if (typeof args[0] === "function")
@@ -27,7 +30,6 @@ Git.prototype.git = function(/* command, args, options, callback */)
2730
options.env = options.env || {};
2831
options.cwd = options.cwd || this.path;
2932

30-
gitargs.unshift(command);
3133
var child = spawn("git", gitargs, { cwd: options.cwd, env: options.env});
3234

3335
child.stderr.setEncoding('utf8');
@@ -68,7 +70,7 @@ Git.prototype.git = function(/* command, args, options, callback */)
6870
Git.prototype.status = function(callback) {
6971
var result = Object.create(null);
7072

71-
var child = this.git("status", ["--porcelain"], function(err) {
73+
var child = this.git("status", "--porcelain", function(err) {
7274
if (err) callback(err, null);
7375
else callback(null, result);
7476
});
@@ -81,23 +83,23 @@ Git.prototype.status = function(callback) {
8183
};
8284

8385
Git.prototype.addAll = function(callback) {
84-
this.git("add", ["--all", ":/"], callback);
86+
this.git("add", "--all", ":/", callback);
8587
};
8688

8789
Git.prototype.update_ref = function(/* ref, value, oldvalue, callback */) {
88-
var ref, value, oldvalue, callback;
90+
var ref, value, oldvalue = null, callback;
8991
var args = Array.prototype.slice.call(arguments);
9092

9193
ref = args.shift();
9294
value = args.shift();
93-
if (typeof args[0] === "string")
95+
if (typeof args[0] === "string" || args[0] === null)
9496
oldvalue = args.shift();
9597
callback = args.shift();
9698

9799
if (oldvalue !== null)
98-
this.git("update-ref", [ref, value, oldvalue], callback);
100+
this.git("update-ref", ref, value, oldvalue, callback);
99101
else
100-
this.git("update-ref", [ref, value], callback);
102+
this.git("update-ref", ref, value, callback);
101103
};
102104

103105

@@ -134,10 +136,10 @@ Git.prototype.commit_tree = function(/* tree, message, parents, options, callbac
134136

135137
var result = null;
136138

137-
var gitargs = [tree];
139+
var parentFlags = [];
138140
for (var k in parents) {
139-
gitargs.push("-p");
140-
gitargs.push(parents[k]);
141+
parentFlags.push("-p");
142+
parentFlags.push(parents[k]);
141143
}
142144

143145
var env = {};
@@ -150,7 +152,7 @@ Git.prototype.commit_tree = function(/* tree, message, parents, options, callbac
150152
env.GIT_COMMITTER_EMAIL = options.committer.email;
151153
}
152154

153-
var child = this.git("commit-tree", gitargs, {env: env}, function(err) {
155+
var child = this.git("commit-tree", tree, parentFlags, {env: env}, function(err) {
154156
if (err) callback(err, null);
155157
else callback(null, result);
156158
});

0 commit comments

Comments
 (0)