1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Check the global git config to ensure its setup

This commit is contained in:
Nick O'Leary 2018-01-24 21:05:48 +00:00
parent 64607df929
commit 7a89e3cf33
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
4 changed files with 54 additions and 12 deletions

View File

@ -67,6 +67,22 @@ RED.projects = (function() {
var gitEmailInput;
return {
content: function(options) {
var isGlobalConfig = false;
var existingGitSettings = RED.settings.get('git');
if (existingGitSettings && existingGitSettings.user) {
existingGitSettings = existingGitSettings.user;
} else if (RED.settings.git && RED.settings.git.globalUser) {
isGlobalConfig = true;
existingGitSettings = RED.settings.git.globalUser;
}
var validateForm = function() {
var name = gitUsernameInput.val().trim();
var email = gitEmailInput.val().trim();
var valid = name.length > 0 && email.length > 0;
$("#projects-dialog-git-config").prop('disabled',!valid).toggleClass('disabled ui-button-disabled ui-state-disabled',!valid);
}
var container = $('<div class="projects-dialog-screen-start"></div>');
migrateProjectHeader.appendTo(container);
@ -75,23 +91,26 @@ RED.projects = (function() {
$('<p>').text("Setup your version control client").appendTo(body);
$('<p>').text("Node-RED uses the open source tool Git for version control. It tracks changes to your project files and lets you push them to remote repositories.").appendTo(body);
$('<p>').text("When you commit a set of changes, Git records who made the changes with a username and email address. The Username can be anything you want - it does not need to be your real name.").appendTo(body);
$('<p>').text("If your Git client is already configured, you can skip this step.").appendTo(body);
var currentGitSettings = RED.settings.get('git') || {};
currentGitSettings.user = currentGitSettings.user || {};
if (isGlobalConfig) {
$('<p>').text("Your Git client is already configured with the details below.").appendTo(body);
}
$('<p>').text("You can change these settings later under the 'Git config' tab of the settings dialog.").appendTo(body);
var row = $('<div class="form-row"></div>').appendTo(body);
$('<label for="">Username</label>').appendTo(row);
gitUsernameInput = $('<input type="text">').val(currentGitSettings.user.name||"").appendTo(row);
gitUsernameInput = $('<input type="text">').val(existingGitSettings.name||"").appendTo(row);
// $('<div style="position:relative;"></div>').text("This does not need to be your real name").appendTo(row);
gitUsernameInput.on("change keyup paste",validateForm);
row = $('<div class="form-row"></div>').appendTo(body);
$('<label for="">Email</label>').appendTo(row);
gitEmailInput = $('<input type="text">').val(currentGitSettings.user.email||"").appendTo(row);
gitEmailInput = $('<input type="text">').val(existingGitSettings.email||"").appendTo(row);
gitEmailInput.on("change keyup paste",validateForm);
// $('<div style="position:relative;"></div>').text("Something something email").appendTo(row);
setTimeout(function() {
gitUsernameInput.focus();
validateForm();
},50);
return container;
},
@ -104,6 +123,7 @@ RED.projects = (function() {
}
},
{
id: "projects-dialog-git-config",
text: "Next", // TODO: nls
class: "primary",
click: function() {

View File

@ -59,6 +59,9 @@ module.exports = {
flow: runtime.storage.projects.getFlowFilename(),
credentials: runtime.storage.projects.getCredentialsFilename()
}
safeSettings.git = {
globalUser: runtime.storage.projects.getGlobalGitUser()
}
}
safeSettings.flowEncryptionType = runtime.nodes.getCredentialKeyType();

View File

@ -369,11 +369,27 @@ module.exports = {
init: function(_settings,_runtime) {
log = _runtime.log
return new Promise(function(resolve,reject) {
runGitCommand(["--version"]).then(function(output) {
var m = / (\d\S+)/.exec(output);
Promise.all([
runGitCommand(["--version"]),
runGitCommand(["config","--global","user.name"]).catch(err=>""),
runGitCommand(["config","--global","user.email"]).catch(err=>"")
]).then(function(output) {
var m = / (\d\S+)/.exec(output[0]);
gitVersion = m[1];
resolve(gitVersion);
var globalUserName = output[1].trim();
var globalUserEmail = output[2].trim();
var result = {
version: gitVersion
};
if (globalUserName && globalUserEmail) {
result.user = {
name: globalUserName,
email: globalUserEmail
}
}
resolve(result);
}).catch(function(err) {
console.log(err);
resolve(null);
});
});

View File

@ -37,6 +37,8 @@ var projectLogMessages = [];
var projectsDir;
var activeProject
var globalGitUser = false;
function init(_settings, _runtime) {
settings = _settings;
runtime = _runtime;
@ -89,11 +91,12 @@ function init(_settings, _runtime) {
if (projectsEnabled) {
return sshTools.init(settings,runtime).then(function() {
gitTools.init(_settings, _runtime).then(function(gitVersion) {
if (!gitVersion) {
gitTools.init(_settings, _runtime).then(function(gitConfig) {
if (!gitConfig) {
projectLogMessages.push(log._("storage.localfilesystem.projects.git-not-found"))
projectsEnabled = false;
} else {
globalGitUser = gitConfig.user;
Projects.init(settings,runtime);
sshTools.init(settings,runtime);
projectsDir = fspath.join(settings.userDir,"projects");
@ -553,7 +556,7 @@ module.exports = {
updateRemote: updateRemote,
getFlowFilename: getFlowFilename,
getCredentialsFilename: getCredentialsFilename,
getGlobalGitUser: function() { return globalGitUser },
getFlows: getFlows,
saveFlows: saveFlows,
getCredentials: getCredentials,