From 91352e855aa4eadbf507b057097aebe02ba65b42 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 5 Dec 2017 16:12:07 +0000 Subject: [PATCH] Handle overwrite warning on local branch change --- editor/js/ui/tab-versionControl.js | 10 +++++++-- .../localfilesystem/projects/git/index.js | 22 ++++++------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/editor/js/ui/tab-versionControl.js b/editor/js/ui/tab-versionControl.js index 1790e5859..d935a14d7 100644 --- a/editor/js/ui/tab-versionControl.js +++ b/editor/js/ui/tab-versionControl.js @@ -604,6 +604,13 @@ RED.sidebar.versionControl = (function() { }); }, 400: { + 'git_local_overwrite': function(error) { + spinner.remove(); + RED.notify("You have local changes that would be overwritten by changing the branch. You must either commit or undo those changes first.",{ + type:'error', + timeout: 8000 + }); + }, 'unexpected_error': function(error) { spinner.remove(); console.log(error); @@ -612,7 +619,6 @@ RED.sidebar.versionControl = (function() { }, } },body).always(function(){ - console.log("switch deployinflight to false") RED.deploy.setDeployInflight(false); }); } @@ -823,7 +829,7 @@ RED.sidebar.versionControl = (function() { closeRemoteBox(); }, 400: { - 'git_pull_overwrite': function(err) { + 'git_local_overwrite': function(err) { RED.notify("Unable to pull remote changes; your unstaged local changes would be overwritten. Commit your changes and try again."+ '

'+'Show unstaged changes'+'

',"error",false,10000000); }, diff --git a/red/runtime/storage/localfilesystem/projects/git/index.js b/red/runtime/storage/localfilesystem/projects/git/index.js index 9bd293e24..2152390e4 100644 --- a/red/runtime/storage/localfilesystem/projects/git/index.js +++ b/red/runtime/storage/localfilesystem/projects/git/index.js @@ -24,19 +24,6 @@ var path = require("path"); var gitCommand = "git"; var log; -// function execCommand(command,args,cwd) { -// return when.promise(function(resolve,reject) { -// var fullCommand = command+" "+args.join(" "); -// child = exec(fullCommand, {cwd: cwd, timeout:3000, killSignal: 'SIGTERM'}, function (error, stdout, stderr) { -// if (error) { -// reject(error); -// } else { -// resolve(stdout); -// } -// }); -// }); -// } - function runGitCommand(args,cwd,env) { log.trace(gitCommand + JSON.stringify(args)); return when.promise(function(resolve,reject) { @@ -64,9 +51,14 @@ function runGitCommand(args,cwd,env) { err.code = "git_auth_failed"; } else if(/Connection refused/.test(stderr)) { err.code = "git_connection_failed"; - } else { - err.code = "git_error"; + } else if (/commit your changes or stash/.test(stderr)) { + err.code = "git_local_overwrite"; + } else if (/CONFLICT/.test(err.stdout)) { + err.code = "git_pull_merge_conflict"; } + + + return reject(err); } resolve(stdout);