-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGit.js
67 lines (53 loc) · 2.07 KB
/
Git.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, require, $, brackets, window, console */
define(function (require, exports, module) {
"use strict";
var NodeConnection = brackets.getModule("utils/NodeConnection"),
ProjectManager = brackets.getModule("project/ProjectManager"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
var nodeConnection = new NodeConnection(), // mind as well share a connection for all Git repos
path = ExtensionUtils.getModulePath(module, "node/GitChildProcess"),
disconnectedGits = [],
connected = false,
LOGGING_ENABLED = true;
function log() {
if (LOGGING_ENABLED) {
console.log(arguments);
}
}
nodeConnection.connect(true).done(function () {
var p = nodeConnection.loadDomains([path], true);
p.done(function () {
connected = true;
while (disconnectedGits.length > 0) {
disconnectedGits.shift().connecting.resolve();
}
});
p.fail(function () {
log("git-integration: Error connecting to Node:");
log(arguments);
});
});
function Git(gitManager) {
this.gitManager = gitManager;
this.connecting = $.Deferred();
if (!connected) {
disconnectedGits.push(this);
} else {
this.connecting.resolve();
}
}
/**
* @throws Error Executing a command that's not a git command throws an error
* @returns {promise} Promise for the Node connection
*/
Git.prototype.execute = function (cmd) {
if (this.connecting.state() !== "resolved") {
throw new Error("Node connection for git not yet established.");
}
var path = ProjectManager.getProjectRoot().fullPath;
var result = nodeConnection.domains.gitManager.runCommand(cmd, path);
return result;
};
module.exports = Git;
});