This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
forked from mako-taco/pivotal-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroll.js
138 lines (127 loc) · 2.63 KB
/
roll.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var check = require('./internal/check');
var pivotal = require('pivotal');
var git = require('./internal/git');
var readline = require('readline');
var colors = require('colors');
var exec = require("child_process").exec;
pivotal.updateStory = require('./internal/pivotal-shim').updateStory,
module.exports = function(args){
var fromBranch = undefined;
var msg = undefined;
var preMergeCommand = undefined;
for(var i=0; i<args.length; i++){
var arg = args[i];
if(arg=="-r"){
preMergeCommand = args[i+1];
if(preMergeCommand==undefined){
console.log("bad use of -r".red);
process.exit(1);
}
else{
i++;
}
}
else if(fromBranch==undefined){
fromBranch = arg;
}
else if(msg==undefined){
msg = arg;
}
else{
console.log("Unknown argument: ".red+arg);
process.exit(1);
}
}
if(fromBranch==undefined){
console.log("Must provide branch name".red);
process.exit(1);
}
else{
git.getBranch(function (err, toBranch) {
if(err){
throw err;
}
else{
if(toBranch==fromBranch){
console.log("Can't merge with self!".red);
process.exit(1);
}
else{
check(function (err, pt) {
if(err) {
throw err;
}
pivotal.useToken(pt.apikey);
var msg = args[1];
if(msg==undefined){
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("What comment should we leave for this roll? ", function(a){
rl.close();
msg = a.trim();
runner(toBranch, fromBranch, msg, preMergeCommand);
});
}
else{
runner(toBranch, fromBranch, msg, preMergeCommand);
}
});
}
}
});
}
}
function runner(to, from, msg, command){
if(command){
console.log("Moving to "+from);
git.checkout(from, function(err){
if(err){
throw err;
}
else{
console.log("Running `"+command+"`");
exec(command, function(err){
if(err){
git.checkout(to, function(err, stdout, stderr){
if(err){
throw err;
}
else{
console.log(("Command ("+command+") failed to run").red);
console.log(stderr);
process.exit(1);
}
});
}
else{
console.log("Moving to "+to);
git.checkout(to, function(err){
if(err){
throw err;
}
else{
roll(from, msg);
}
});
}
});
}
});
}
else{
roll(from, msg);
}
}
function roll(branch, msg){
console.log("Lets Roll...");
git.merge(branch, msg, function(err){
if(err){
throw err;
}
else{
console.log("Rolled "+branch+" into current branch!");
}
});
}