Confirm actions that would overwrite dirty workspace

This commit is contained in:
Nick O'Leary
2017-11-24 23:12:35 +00:00
parent e5ff25b92d
commit 14c48253f6
10 changed files with 244 additions and 123 deletions

View File

@@ -29,14 +29,8 @@ var log;
var projectsDir;
var authCache = {};
var authCache = require("./git/authCache");
function getAuth(project,remote) {
if (authCache.hasOwnProperty(project) && authCache[project].hasOwnProperty(remote)) {
return authCache[project][remote];
}
return null;
}
function Project(name) {
this.name = name;
this.path = fspath.join(projectsDir,name);
@@ -179,10 +173,9 @@ Project.prototype.update = function (data) {
this.package.description = data.summary;
}
if (data.hasOwnProperty('remote')) {
authCache[project.name] = authCache[project.name]||{};
for (var remote in data.remote) {
if (data.remote.hasOwnProperty(remote)) {
authCache[project.name][remote] = data.remote[remote];
authCache.set(project.name,remote,data.remote[remote]);
}
}
}
@@ -255,7 +248,7 @@ Project.prototype.status = function() {
var fetchPromise;
if (this.remote) {
fetchPromise = gitTools.fetch(this.path,getAuth(this.name,'origin'));
fetchPromise = gitTools.fetch(this.path,authCache.get(this.name,'origin'));
} else {
fetchPromise = when.resolve();
}
@@ -281,9 +274,7 @@ Project.prototype.status = function() {
});
}
return fetchPromise.then(completeStatus).catch(function(e) {
if (e.code === 'git_auth_failed') {
console.log("Fetch auth failed");
} else {
if (e.code !== 'git_auth_failed') {
console.log("Fetch failed");
console.log(e);
}
@@ -292,17 +283,17 @@ Project.prototype.status = function() {
};
Project.prototype.push = function (remoteBranchName,setRemote) {
return gitTools.push(this.path, remoteBranchName, setRemote, getAuth(this.name,'origin'));
return gitTools.push(this.path, remoteBranchName, setRemote, authCache.get(this.name,'origin'));
};
Project.prototype.pull = function (remoteBranchName,setRemote) {
var self = this;
if (setRemote) {
return gitTools.setUpstream(this.path, remoteBranchName).then(function() {
return gitTools.pull(self.path, null, getAuth(self.name,'origin'));
return gitTools.pull(self.path, null, authCache.get(self.name,'origin'));
})
} else {
return gitTools.pull(this.path, remoteBranchName, getAuth(this.name,'origin'));
return gitTools.pull(this.path, remoteBranchName, authCache.get(this.name,'origin'));
}
};
@@ -355,7 +346,7 @@ Project.prototype.getBranches = function (remote) {
var self = this;
var fetchPromise;
if (remote) {
fetchPromise = gitTools.fetch(this.path,getAuth(this.name,'origin'))
fetchPromise = gitTools.fetch(this.path,authCache.get(this.name,'origin'))
} else {
fetchPromise = when.resolve();
}
@@ -535,13 +526,12 @@ function createProject(metadata) {
if (metadata.remote) {
var auth;
if (metadata.remote.hasOwnProperty("username") && metadata.remote.hasOwnProperty("password")) {
authCache[project] = {
origin: { // TODO: hardcoded remote name
authCache.set(project,'origin',{ // TODO: hardcoded remote name
username: metadata.remote.username,
password: metadata.remote.password
}
}
auth = authCache[project].origin;
);
auth = authCache.get(project,'origin');
}
return gitTools.clone(metadata.remote,auth,projectPath).then(function(result) {

View File

@@ -0,0 +1,42 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var authCache = {}
module.exports = {
clear: function(project,remote) {
if (remote && authCache.hasOwnProperty(project)) {
delete authCache[project][remote];
return;
}
delete authCache[project];
},
set: function(project,remote,auth) {
if (authCache.hasOwnProperty(project)) {
authCache[project][remote] = auth;
} else {
authCache[project] = {
remote: auth
}
}
},
get: function(project,remote) {
if (authCache.hasOwnProperty(project)) {
return authCache[project][remote];
}
return
}
}

View File

@@ -1,18 +1,18 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var net = require("net");
var fs = require("fs-extra");

View File

@@ -147,7 +147,7 @@ function getFileDiff(project,file,type) {
}
function getCommits(project,options) {
checkActiveProject(project);
return activeProject.getCommits(options);
return activeProject.getCommits(options);
}
function getCommit(project,sha) {
checkActiveProject(project);
@@ -164,7 +164,9 @@ function push(project,remoteBranchName,setRemote) {
}
function pull(project,remoteBranchName,setRemote) {
checkActiveProject(project);
return activeProject.pull(remoteBranchName,setRemote).then(reloadActiveProject);
return activeProject.pull(remoteBranchName,setRemote).then(function() {
return reloadActiveProject("pull");
});
}
function getStatus(project) {
checkActiveProject(project);
@@ -176,7 +178,9 @@ function resolveMerge(project,file,resolution) {
}
function abortMerge(project) {
checkActiveProject(project);
return activeProject.abortMerge().then(reloadActiveProject);
return activeProject.abortMerge().then(function() {
return reloadActiveProject("abort-merge")
});
}
function getBranches(project,remote) {
checkActiveProject(project);
@@ -184,7 +188,9 @@ function getBranches(project,remote) {
}
function setBranch(project,branchName,isCreate) {
checkActiveProject(project);
return activeProject.setBranch(branchName,isCreate).then(reloadActiveProject);
return activeProject.setBranch(branchName,isCreate).then(function() {
return reloadActiveProject("change-branch");
});
}
function getBranchStatus(project,branchName) {
checkActiveProject(project);
@@ -194,14 +200,14 @@ function getActiveProject() {
return activeProject;
}
function reloadActiveProject() {
function reloadActiveProject(action) {
return runtime.nodes.stopFlows().then(function() {
return runtime.nodes.loadFlows(true).then(function() {
runtime.events.emit("runtime-event",{id:"project-change",payload:{ project: activeProject.name}});
runtime.events.emit("runtime-event",{id:"project-update", payload:{ project: activeProject.name, action:action}});
}).catch(function(err) {
// We're committed to the project change now, so notify editors
// that it has changed.
runtime.events.emit("runtime-event",{id:"project-change",payload:{ project: activeProject.name}});
runtime.events.emit("runtime-event",{id:"project-update", payload:{ project: activeProject.name, action:action}});
throw err;
});
});
@@ -224,7 +230,7 @@ function setActiveProject(projectName) {
// console.log("Updated file targets to");
// console.log(flowsFullPath)
// console.log(credentialsFile)
return reloadActiveProject();
return reloadActiveProject("loaded");
})
});
}
@@ -244,7 +250,7 @@ function updateProject(project,data) {
flowsFileBackup = activeProject.getFlowFileBackup();
credentialsFile = activeProject.getCredentialsFile();
credentialsFileBackup = activeProject.getCredentialsFileBackup();
return reloadActiveProject();
return reloadActiveProject("updated");
} else if (result.credentialSecretChanged) {
if (isReset || !wasInvalid) {
if (isReset) {
@@ -255,11 +261,11 @@ function updateProject(project,data) {
.then(runtime.storage.saveCredentials)
.then(function() {
if (wasInvalid) {
return reloadActiveProject();
return reloadActiveProject("updated");
}
});
} else if (wasInvalid) {
return reloadActiveProject();
return reloadActiveProject("updated");
}
}
});
@@ -277,11 +283,11 @@ function setCredentialSecret(data) { //existingSecret,secret) {
.then(runtime.storage.saveCredentials)
.then(function() {
if (wasInvalid) {
return reloadActiveProject();
return reloadActiveProject("updated");
}
});
} else if (wasInvalid) {
return reloadActiveProject();
return reloadActiveProject("updated");
}
})
}