mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Better handling of empty projects and lifecycle
This commit is contained in:
@@ -155,7 +155,8 @@ Project.prototype.loadRemotes = function() {
|
||||
return gitTools.getRemotes(project.path).then(function(remotes) {
|
||||
project.remotes = remotes;
|
||||
}).then(function() {
|
||||
return project.loadBranches();
|
||||
project.branches = {};
|
||||
return project.status();
|
||||
}).then(function() {
|
||||
var allRemotes = Object.keys(project.remotes);
|
||||
var match = "";
|
||||
@@ -189,15 +190,6 @@ Project.prototype.parseRemoteBranch = function (remoteBranch) {
|
||||
|
||||
};
|
||||
|
||||
Project.prototype.loadBranches = function() {
|
||||
var project = this;
|
||||
return gitTools.getBranchInfo(project.path).then(function(branches) {
|
||||
project.branches = branches;
|
||||
project.empty = project.branches.empty;
|
||||
delete project.branches.empty;
|
||||
});
|
||||
}
|
||||
|
||||
Project.prototype.isEmpty = function () {
|
||||
return this.empty;
|
||||
};
|
||||
@@ -439,6 +431,37 @@ Project.prototype.status = function(user) {
|
||||
code: fetchError.code
|
||||
}
|
||||
}
|
||||
if (result.commits.total === 0 && Object.keys(result.files).length === 0) {
|
||||
if (!self.empty) {
|
||||
runtime.events.emit("runtime-event",{
|
||||
id:"runtime-state",
|
||||
payload:{
|
||||
type:"warning",
|
||||
error:"project_empty",
|
||||
text:"notification.warnings.project_empty"},
|
||||
retain:true
|
||||
}
|
||||
);
|
||||
}
|
||||
self.empty = true;
|
||||
} else {
|
||||
if (self.empty) {
|
||||
if (self.paths.flowFile) {
|
||||
runtime.events.emit("runtime-event",{id:"runtime-state",retain:true});
|
||||
} else {
|
||||
runtime.events.emit("runtime-event",{
|
||||
id:"runtime-state",
|
||||
payload:{
|
||||
type:"warning",
|
||||
error:"missing_flow_file",
|
||||
text:"notification.warnings.missing_flow_file"},
|
||||
retain:true
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
delete self.empty;
|
||||
}
|
||||
return result;
|
||||
}).catch(function(err) {
|
||||
if (/ambiguous argument/.test(err.message)) {
|
||||
|
@@ -117,25 +117,28 @@ function parseFilenames(name) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function getBranchInfo(localRepo) {
|
||||
return runGitCommand(["status","--porcelain","-b"],localRepo).then(function(output) {
|
||||
var lines = output.split("\n");
|
||||
var unknownDirs = [];
|
||||
var branchLineRE = /^## (No commits yet on )?(.+?)($|\.\.\.(.+?)($| \[(ahead (\d+))?.*?(behind (\d+))?\]))/m;
|
||||
var m = branchLineRE.exec(output);
|
||||
var result = {}; //commits:{}};
|
||||
if (m) {
|
||||
if (m[1]) {
|
||||
result.empty = true;
|
||||
}
|
||||
result.local = m[2];
|
||||
if (m[4]) {
|
||||
result.remote = m[4];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
// function getBranchInfo(localRepo) {
|
||||
// return runGitCommand(["status","--porcelain","-b"],localRepo).then(function(output) {
|
||||
// var lines = output.split("\n");
|
||||
// var unknownDirs = [];
|
||||
// var branchLineRE = /^## (No commits yet on )?(.+?)($|\.\.\.(.+?)($| \[(ahead (\d+))?.*?(behind (\d+))?\]))/m;
|
||||
// console.log(output);
|
||||
// console.log(lines);
|
||||
// var m = branchLineRE.exec(output);
|
||||
// console.log(m);
|
||||
// var result = {}; //commits:{}};
|
||||
// if (m) {
|
||||
// if (m[1]) {
|
||||
// result.empty = true;
|
||||
// }
|
||||
// result.local = m[2];
|
||||
// if (m[4]) {
|
||||
// result.remote = m[4];
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// });
|
||||
// }
|
||||
function getStatus(localRepo) {
|
||||
// parseFilename('"test with space"');
|
||||
// parseFilename('"test with space" -> knownFile.txt');
|
||||
@@ -147,6 +150,12 @@ function getStatus(localRepo) {
|
||||
}
|
||||
return runGitCommand(['rev-list', 'HEAD', '--count'],localRepo).then(function(count) {
|
||||
result.commits.total = parseInt(count);
|
||||
}).catch(function(err) {
|
||||
if (/ambiguous argument/.test(err.message)) {
|
||||
result.commits.total = 0;
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}).then(function() {
|
||||
return runGitCommand(["ls-files","--cached","--others","--exclude-standard"],localRepo).then(function(output) {
|
||||
var lines = output.split("\n");
|
||||
@@ -174,7 +183,7 @@ function getStatus(localRepo) {
|
||||
return runGitCommand(["status","--porcelain","-b"],localRepo).then(function(output) {
|
||||
var lines = output.split("\n");
|
||||
var unknownDirs = [];
|
||||
var branchLineRE = /^## (.+?)(?:$|\.\.\.(.+?)(?:$| \[(?:(?:ahead (\d+)(?:,\s*)?)?(?:behind (\d+))?|(gone))\]))/;
|
||||
var branchLineRE = /^## (?:No commits yet on )?(.+?)(?:$|\.\.\.(.+?)(?:$| \[(?:(?:ahead (\d+)(?:,\s*)?)?(?:behind (\d+))?|(gone))\]))/;
|
||||
lines.forEach(function(line) {
|
||||
if (line==="") {
|
||||
return;
|
||||
@@ -566,7 +575,7 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
getBranches: getBranches,
|
||||
getBranchInfo: getBranchInfo,
|
||||
// getBranchInfo: getBranchInfo,
|
||||
checkoutBranch: function(cwd, branchName, isCreate) {
|
||||
var args = ['checkout'];
|
||||
if (isCreate) {
|
||||
|
Reference in New Issue
Block a user