-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfed-git.js
More file actions
executable file
·70 lines (65 loc) · 1.71 KB
/
Copy pathfed-git.js
File metadata and controls
executable file
·70 lines (65 loc) · 1.71 KB
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
68
69
70
var commands = {
"init" : "git init",
"clone" : "git clone",
"status" : "git status",
"checkout" : "git checkout",
"branch" : "git branch",
"merge" : "git merge",
"commit" : "git commit",
"push" : "git push",
"add" : "git add",
"stash" : "git stash"
};
/**
* Name of the fed module
* @type {string}
*/
exports.name = "node-fed-git";
/**
* Test if the command start with main git command
*
* @param {String} command Command to run
* @param {Object} dir Directory information
* @returns {boolean}
*/
exports.canDo = function canDoGitCommand(command, dir) {
if (!dir.repository || dir.repository.type !== 'git') {
return false;
}
var key, keys = [], rg;
for (key in commands) {
if (commands.hasOwnProperty(key)) {
keys.push(key);
}
}
rg = new RegExp("^(" + keys.join('|') + ")");
return (rg.test(command));
};
/**
* Return the command to execute
*
* @param {String} command Command to run
* @param {Object} dir Directory information
* @returns {String}
*/
exports.getCommand = function getGitCommand(command,dir) {
var isClone = (/^(clone)/.test(command)), key;
// Prevent fed to browse when trying to clone repository
exports.preventBrowse = isClone;
if (isClone) {
command = command.replace('clone', commands.clone + ' ' + dir.repository.url);
} else {
for (key in commands) {
if (commands.hasOwnProperty(key)) {
command = command.replace(key, commands[key]);
}
}
}
return command;
};
/**
* Prevent browsing (false by default)
* Except for clone
* @type {boolean}
*/
exports.preventBrowse = false;