mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Use flow-diff to resolve merge conflicts
This commit is contained in:
@@ -80,7 +80,7 @@ module.exports = {
|
||||
}).catch(function(err) {
|
||||
log.warn(log._("api.flows.error-save",{message:err.message}));
|
||||
log.warn(err.stack);
|
||||
res.status(500).json({error:"unexpected_error", message:err.message});
|
||||
res.status(500).json({error:err.code || "unexpected_error", message:err.message});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -93,7 +93,8 @@
|
||||
"credentials_load_failed": "<p>Flows stopped as the credentials could not be decrypted.</p><p>The flow credential file is encrypted, but the project's encryption key is missing or invalid.</p>",
|
||||
"missing_flow_file": "<p>Project flow file not found.</p><p>The project is not configured with a flow file.</p>",
|
||||
"project_empty": "<p>The project is empty.</p><p>Do you want to create a default set of project files?<br/>Otherwise, you will have to manually add files to the project outside of the editor.</p>",
|
||||
"project_not_found": "<p>Project '__project__' not found.</p>"
|
||||
"project_not_found": "<p>Project '__project__' not found.</p>",
|
||||
"git_merge_conflict": "<p>Automatic merging of changes failed.</p><p>Fix the unmerged conflicts then commit the results.</p>"
|
||||
},
|
||||
|
||||
"error": "<strong>Error</strong>: __message__",
|
||||
|
@@ -127,7 +127,7 @@ Project.prototype.load = function () {
|
||||
|
||||
promises.push(project.loadRemotes());
|
||||
|
||||
return when.settle(promises).then(function() {
|
||||
return when.settle(promises).then(function(results) {
|
||||
return project;
|
||||
})
|
||||
});
|
||||
@@ -218,6 +218,9 @@ Project.prototype.parseRemoteBranch = function (remoteBranch) {
|
||||
Project.prototype.isEmpty = function () {
|
||||
return this.empty;
|
||||
};
|
||||
Project.prototype.isMerging = function() {
|
||||
return this.merging;
|
||||
}
|
||||
|
||||
Project.prototype.update = function (user, data) {
|
||||
var username;
|
||||
@@ -374,7 +377,13 @@ Project.prototype.unstageFile = function(file) {
|
||||
return gitTools.unstageFile(this.path,file);
|
||||
}
|
||||
Project.prototype.commit = function(user, options) {
|
||||
return gitTools.commit(this.path,options.message,getGitUser(user));
|
||||
var self = this;
|
||||
return gitTools.commit(this.path,options.message,getGitUser(user)).then(function() {
|
||||
if (self.merging) {
|
||||
self.merging = false;
|
||||
return
|
||||
}
|
||||
});
|
||||
}
|
||||
Project.prototype.getFileDiff = function(file,type) {
|
||||
return gitTools.getFileDiff(this.path,file,type);
|
||||
@@ -440,6 +449,21 @@ Project.prototype.status = function(user, includeRemote) {
|
||||
var result = results[0];
|
||||
if (results[1]) {
|
||||
result.merging = true;
|
||||
if (!self.merging) {
|
||||
self.merging = true;
|
||||
runtime.events.emit("runtime-event",{
|
||||
id:"runtime-state",
|
||||
payload:{
|
||||
type:"warning",
|
||||
error:"git_merge_conflict",
|
||||
project:self.name,
|
||||
text:"notification.warnings.git_merge_conflict"
|
||||
},
|
||||
retain:true}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
self.merging = false;
|
||||
}
|
||||
self.branches.local = result.branches.local;
|
||||
self.branches.remote = result.branches.remote;
|
||||
@@ -534,6 +558,11 @@ Project.prototype.pull = function (user,remoteBranchName,setRemote,allowUnrelate
|
||||
Project.prototype.resolveMerge = function (file,resolutions) {
|
||||
var filePath = fspath.join(this.path,file);
|
||||
var self = this;
|
||||
if (typeof resolutions === 'string') {
|
||||
return util.writeFile(filePath, resolutions).then(function() {
|
||||
return self.stageFile(file);
|
||||
})
|
||||
}
|
||||
return fs.readFile(filePath,"utf8").then(function(content) {
|
||||
var lines = content.split("\n");
|
||||
var result = [];
|
||||
@@ -573,7 +602,10 @@ Project.prototype.resolveMerge = function (file,resolutions) {
|
||||
});
|
||||
};
|
||||
Project.prototype.abortMerge = function () {
|
||||
return gitTools.abortMerge(this.path);
|
||||
var self = this;
|
||||
return gitTools.abortMerge(this.path).then(function() {
|
||||
self.merging = false;
|
||||
})
|
||||
};
|
||||
|
||||
Project.prototype.getBranches = function (user, isRemote) {
|
||||
|
@@ -454,18 +454,19 @@ module.exports = {
|
||||
} else {
|
||||
promise = runGitCommand(args,cwd)
|
||||
}
|
||||
return promise.catch(function(err) {
|
||||
if (/CONFLICT/.test(err.stdout)) {
|
||||
var e = new Error("NLS: pull failed - merge conflict");
|
||||
e.code = "git_pull_merge_conflict";
|
||||
throw e;
|
||||
} else if (/Please commit your changes or stash/i.test(err.message)) {
|
||||
var e = new Error("NLS: Pull failed - local changes would be overwritten");
|
||||
e.code = "git_pull_overwrite";
|
||||
throw e;
|
||||
}
|
||||
throw err;
|
||||
});
|
||||
return promise;
|
||||
// .catch(function(err) {
|
||||
// if (/CONFLICT/.test(err.stdout)) {
|
||||
// var e = new Error("pull failed - merge conflict");
|
||||
// e.code = "git_pull_merge_conflict";
|
||||
// throw e;
|
||||
// } else if (/Please commit your changes or stash/i.test(err.message)) {
|
||||
// var e = new Error("Pull failed - local changes would be overwritten");
|
||||
// e.code = "git_pull_overwrite";
|
||||
// throw e;
|
||||
// }
|
||||
// throw err;
|
||||
// });
|
||||
},
|
||||
push: function(cwd,remote,branch,setUpstream, auth) {
|
||||
var args = ["push"];
|
||||
|
@@ -212,7 +212,13 @@ function unstageFile(user, project,file) {
|
||||
}
|
||||
function commit(user, project,options) {
|
||||
checkActiveProject(project);
|
||||
return activeProject.commit(user, options);
|
||||
var isMerging = activeProject.isMerging();
|
||||
return activeProject.commit(user, options).then(function() {
|
||||
// The project was merging, now it isn't. Lets reload.
|
||||
if (isMerging && !activeProject.isMerging()) {
|
||||
return reloadActiveProject("merge-complete");
|
||||
}
|
||||
})
|
||||
}
|
||||
function getFileDiff(user, project,file,type) {
|
||||
checkActiveProject(project);
|
||||
@@ -258,7 +264,7 @@ function resolveMerge(user, project,file,resolution) {
|
||||
function abortMerge(user, project) {
|
||||
checkActiveProject(project);
|
||||
return activeProject.abortMerge().then(function() {
|
||||
return reloadActiveProject("abort-merge")
|
||||
return reloadActiveProject("merge-abort")
|
||||
});
|
||||
}
|
||||
function getBranches(user, project,isRemote) {
|
||||
@@ -478,6 +484,13 @@ function getFlows() {
|
||||
error.code = "missing_flow_file";
|
||||
return when.reject(error);
|
||||
}
|
||||
if (activeProject.isMerging()) {
|
||||
log.warn("Project has unmerged changes");
|
||||
error = new Error("Project has unmerged changes. Cannot load flows");
|
||||
error.code = "git_merge_conflict";
|
||||
return when.reject(error);
|
||||
}
|
||||
|
||||
}
|
||||
return util.readFile(flowsFullPath,flowsFileBackup,[],'flow');
|
||||
}
|
||||
@@ -486,6 +499,11 @@ function saveFlows(flows) {
|
||||
if (settings.readOnly) {
|
||||
return when.resolve();
|
||||
}
|
||||
if (activeProject && activeProject.isMerging()) {
|
||||
var error = new Error("Project has unmerged changes. Cannot deploy new flows");
|
||||
error.code = "git_merge_conflict";
|
||||
return when.reject(error);
|
||||
}
|
||||
|
||||
try {
|
||||
fs.renameSync(flowsFullPath,flowsFileBackup);
|
||||
|
Reference in New Issue
Block a user