Bug 395260 - Operations API changes in 2.0 - Git Auth fail doesn't work well
diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/gitClient.js b/bundles/org.eclipse.orion.client.git/web/orion/git/gitClient.js
index fdc07d9..6129925 100644
--- a/bundles/org.eclipse.orion.client.git/web/orion/git/gitClient.js
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/gitClient.js
@@ -915,7 +915,7 @@
 		},
 		_getGitServiceResponse: function(clientDeferred, jsonData, xhrArgs){
 			if(xhrArgs && xhrArgs.xhr.status === 202){
-				operation.handle(jsonData.Location).then(clientDeferred.resolve, clientDeferred.reject, clientDeferred.progress);
+				operation.handle(jsonData.Location).then(clientDeferred.resolve, function(data){data.failedOperation=jsonData.Location; clientDeferred.reject(data);}, clientDeferred.progress);
 				return;
 			}
 			clientDeferred.callback(jsonData);
diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/gitCommands.js b/bundles/org.eclipse.orion.client.git/web/orion/git/gitCommands.js
index cca8b92..ca18d14 100644
--- a/bundles/org.eclipse.orion.client.git/web/orion/git/gitCommands.js
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/gitCommands.js
@@ -104,12 +104,12 @@
 			sshService.addKnownHosts(errorData.Host + " " + errorData.KeyType + " " + errorData.HostKey).then(function(){ //$NON-NLS-1$ //$NON-NLS-0$
 				sshService.getKnownHosts().then(function(knownHosts){
 					options.knownHosts = knownHosts;
+					if(typeof options.failedOperation !== "undefined"){
+						var progress = serviceRegistry.getService("orion.page.progress"); //$NON-NLS-0$
+						dojo.hitch(progress, progress.removeOperation)(options.failedOperation);
+					}
 					func(options);
 				});
-				if(typeof options.failedOperation !== "undefined"){
-					var progress = serviceRegistry.getService("orion.page.progress"); //$NON-NLS-0$
-					dojo.hitch(progress, progress.removeOperation)(options.failedOperation);
-				}
 			});
 		}
 	};
@@ -128,10 +128,6 @@
 				
 			credentialsDialog.startup();
 			credentialsDialog.show();
-			if(typeof options.failedOperation !== "undefined"){
-				var progress = serviceRegistry.getService("orion.page.progress"); //$NON-NLS-0$
-				dojo.hitch(progress, progress.removeOperation)(options.failedOperation);
-			}
 		};
 		
 		if((options.gitSshUsername && options.gitSshUsername!=="") ||
@@ -147,7 +143,6 @@
 							var progress = serviceRegistry.getService("orion.page.progress"); //$NON-NLS-0$
 							dojo.hitch(progress, progress.removeOperation)(options.failedOperation);
 						}
-					
 						func({ knownHosts: options.knownHosts, gitSshUsername: credentials.gitSshUsername, gitSshPassword: credentials.gitSshPassword, gitPrivateKey: credentials.gitPrivateKey, gitPassphrase: credentials.gitPassphrase}); //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
 						return;
 					}
@@ -380,18 +375,10 @@
 			}
 			return;
 		case 401:
-			if (jsonData.failedOperation){
-				var progress = serviceRegistry.getService("orion.page.progress"); //$NON-NLS-0$
-				dojo.hitch(progress, progress.removeOperation)(jsonData.failedOperation);
-			}
 			sshCallback(jsonData);
 			return;
 		case 400:
 			if(jsonData.JsonData && jsonData.JsonData.HostKey){
-				if (jsonData.failedOperation){
-					var progress = serviceRegistry.getService("orion.page.progress"); //$NON-NLS-0$
-					dojo.hitch(progress, progress.removeOperation)(jsonData.failedOperation);
-				}
 				sshCallback(jsonData);
 				return;
 			}
@@ -886,6 +873,7 @@
 					if (jsonData.JsonData.HostKey){
 						commandInvocation.parameters = null;
 						commandInvocation.errorData = jsonData.JsonData;
+						commandInvocation.errorData.failedOperation = jsonData.failedOperation;
 						commandService.collectParameters(commandInvocation);
 					} else if (!commandInvocation.optionsRequested){
 						var gitPreferenceStorage = new GitPreferenceStorage(serviceRegistry);
@@ -904,11 +892,13 @@
 								}
 								
 								commandInvocation.errorData = jsonData.JsonData;
+								commandInvocation.errorData.failedOperation = jsonData.failedOperation;
 								commandService.collectParameters(commandInvocation);
 							}
 						);
 					} else {
 						commandInvocation.errorData = jsonData.JsonData;
+						commandInvocation.errorData.failedOperation = jsonData.failedOperation;
 						commandService.collectParameters(commandInvocation);
 					}
 				};
@@ -922,6 +912,11 @@
 						return;
 					}
 					
+					if(commandInvocation.errorData && commandInvocation.errorData.failedOperation){
+						var progress = serviceRegistry.getService("orion.page.progress"); //$NON-NLS-0$
+						dojo.hitch(progress, progress.removeOperation)(commandInvocation.errorData.failedOperation);
+					}
+					
 					exports.gatherSshCredentials(serviceRegistry, commandInvocation).then(
 						function(options) {
 							var gitService = serviceRegistry.getService("orion.git.provider"); //$NON-NLS-0$
@@ -1015,6 +1010,7 @@
 					if (jsonData.JsonData.HostKey){
 						commandInvocation.parameters = null;
 						commandInvocation.errorData = jsonData.JsonData;
+						commandInvocation.errorData.failedOperation = jsonData.failedOperation;
 						commandService.collectParameters(commandInvocation);
 					} else if (!commandInvocation.optionsRequested){
 						var gitPreferenceStorage = new GitPreferenceStorage(serviceRegistry);
@@ -1033,6 +1029,7 @@
 								}
 								
 								commandInvocation.errorData = jsonData.JsonData;
+								commandInvocation.errorData.failedOperation = jsonData.failedOperation;
 								commandService.collectParameters(commandInvocation);
 							}
 						);
@@ -1049,6 +1046,12 @@
 						commandService.collectParameters(commandInvocation);
 						return;
 					}
+					
+					
+					if(commandInvocation.errorData && commandInvocation.errorData.failedOperation){
+						var progress = serviceRegistry.getService("orion.page.progress"); //$NON-NLS-0$
+						dojo.hitch(progress, progress.removeOperation)(commandInvocation.errorData.failedOperation);
+					}
 	
 					exports.gatherSshCredentials(serviceRegistry, commandInvocation).then(
 						function(options) {
@@ -1388,6 +1391,7 @@
 					if (jsonData.JsonData.HostKey){
 						commandInvocation.parameters = null;
 						commandInvocation.errorData = jsonData.JsonData;
+						commandInvocation.errorData.failedOperation = jsonData.failedOperation;
 						commandService.collectParameters(commandInvocation);
 					} else if (!commandInvocation.optionsRequested){
 						var gitPreferenceStorage = new GitPreferenceStorage(serviceRegistry);
@@ -1406,11 +1410,13 @@
 								}
 								
 								commandInvocation.errorData = jsonData.JsonData;
+								commandInvocation.errorData.failedOperation = jsonData.failedOperation;
 								commandService.collectParameters(commandInvocation);
 							}
 						);
 					} else {
 						commandInvocation.errorData = jsonData.JsonData;
+						commandInvocation.errorData.failedOperation = jsonData.failedOperation;
 						commandService.collectParameters(commandInvocation);
 					}
 				};
@@ -1424,6 +1430,10 @@
 				var gitService = serviceRegistry.getService("orion.git.provider");
 				var progress = serviceRegistry.getService("orion.page.progress"); //$NON-NLS-0$
 				
+				if(commandInvocation.errorData && commandInvocation.errorData.failedOperation){
+					dojo.hitch(progress, progress.removeOperation)(commandInvocation.errorData.failedOperation);
+				}
+				
 				var handlePush = function(options, location, ref, name, force){
 					var progressService = serviceRegistry.getService("orion.page.message"); //$NON-NLS-0$
 					var deferred = progress.progress(gitService.doPush(location, ref, true, force, //$NON-NLS-0$
diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/GitCredentialsDialog.js b/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/GitCredentialsDialog.js
index 24cf73c..14fdc2f 100644
--- a/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/GitCredentialsDialog.js
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/GitCredentialsDialog.js
@@ -133,6 +133,10 @@
 			if(self._sshService){
 				self._sshService.getKnownHosts().then(function(knownHosts){
 					if(self.options.func) {
+						var failedOperation = typeof self.options.failedOperation === "undefined"? self.options.errordata.failedOperation : self.options.failedOperation;
+						if(failedOperation !== "undefined"){
+							dojo.hitch(self._progressService, self._progressService.removeOperation)(failedOperation);
+						}
 						self.options.func({ gitSshUsername: self.gitSshUsername.value, gitSshPassword: self.isSshPassword.checked ? self.gitSshPassword.value : "",
 							gitPrivateKey: self.isPrivateKey.checked ? pKey : "", gitPassphrase: self.isPrivateKey.checked ? self.gitPassphrase.value: "", //$NON-NLS-0$
 							knownHosts: knownHosts});
@@ -142,6 +146,10 @@
 				
 			}else{
 				if(self.options.func) {
+					var failedOperation = typeof self.options.failedOperation === "undefined"? self.options.errordata.failedOperation : self.options.failedOperation;
+					if(failedOperation !== "undefined"){
+						dojo.hitch(self._progressService, self._progressService.removeOperation)(failedOperation);
+					}
 					self.options.func({ gitSshUsername: self.gitSshUsername.value, gitSshPassword: self.gitSshPassword.value,
 						gitPrivateKey: pKey, gitPassphrase: self.gitPassphrase.value,
 						knownHosts: self.gitSshKnownHosts.value});