diff --git a/editor/js/ui/projects/projects.js b/editor/js/ui/projects/projects.js index 6a0309883..be3324873 100644 --- a/editor/js/ui/projects/projects.js +++ b/editor/js/ui/projects/projects.js @@ -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 = $('
'); migrateProjectHeader.appendTo(container); @@ -75,23 +91,26 @@ RED.projects = (function() { $('').text("Setup your version control client").appendTo(body); $('
').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); $('
').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); - $('
').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) { + $('
').text("Your Git client is already configured with the details below.").appendTo(body); + } + $('
').text("You can change these settings later under the 'Git config' tab of the settings dialog.").appendTo(body); var row = $('
').appendTo(body); $('').appendTo(row); - gitUsernameInput = $('').val(currentGitSettings.user.name||"").appendTo(row); + gitUsernameInput = $('').val(existingGitSettings.name||"").appendTo(row); // $('').text("This does not need to be your real name").appendTo(row); + gitUsernameInput.on("change keyup paste",validateForm); row = $('').appendTo(body); $('').appendTo(row); - gitEmailInput = $('').val(currentGitSettings.user.email||"").appendTo(row); + gitEmailInput = $('').val(existingGitSettings.email||"").appendTo(row); + gitEmailInput.on("change keyup paste",validateForm); // $('').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() { diff --git a/red/api/editor/settings.js b/red/api/editor/settings.js index 9aeafb1ca..c22f8ea31 100644 --- a/red/api/editor/settings.js +++ b/red/api/editor/settings.js @@ -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(); diff --git a/red/runtime/storage/localfilesystem/projects/git/index.js b/red/runtime/storage/localfilesystem/projects/git/index.js index 071ede76a..076fe8293 100644 --- a/red/runtime/storage/localfilesystem/projects/git/index.js +++ b/red/runtime/storage/localfilesystem/projects/git/index.js @@ -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); }); }); diff --git a/red/runtime/storage/localfilesystem/projects/index.js b/red/runtime/storage/localfilesystem/projects/index.js index 3f0ff806b..c9edfe884 100644 --- a/red/runtime/storage/localfilesystem/projects/index.js +++ b/red/runtime/storage/localfilesystem/projects/index.js @@ -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,