Merge branch 'master' of ssh://mjanczarska@git.eclipse.org/gitroot/orion/org.eclipse.orion.client.git
diff --git a/bundles/org.eclipse.orion.client.git/web/git/git-repository.js b/bundles/org.eclipse.orion.client.git/web/git/git-repository.js
index 0d44802..e5c69c2 100644
--- a/bundles/org.eclipse.orion.client.git/web/git/git-repository.js
+++ b/bundles/org.eclipse.orion.client.git/web/git/git-repository.js
@@ -51,7 +51,8 @@
 	commandService.addCommandGroup("eclipse.gitGroup", 100, null, null, "pageActions");
 	commandService.registerCommandContribution("eclipse.cloneGitRepository", 100, "pageActions", "eclipse.gitGroup", false, null, new mCommands.URLBinding("cloneGitRepository", "url"));
 	commandService.registerCommandContribution("eclipse.initGitRepository", 101, "pageActions", "eclipse.gitGroup");
-	commandService.registerCommandContribution("eclipse.orion.git.openCommitCommand", 102, "pageActions", "eclipse.gitGroup", true, new mCommands.CommandKeyBinding('h', true, true));
+	commandService.registerCommandContribution("eclipse.orion.git.openCommitCommand", 102, "pageActions", "eclipse.gitGroup", true, 
+		new mCommands.CommandKeyBinding('h', true, true), new mCommands.URLBinding("openGitCommit", "commitName"));
 	
 	// object contributions
 	commandService.registerCommandContribution("eclipse.openCloneContent", 100);
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 355d9a3..738d2b1 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
@@ -1,6 +1,6 @@
 /******************************************************************************* 
  * @license
- * Copyright (c) 2011 IBM Corporation and others.
+ * Copyright (c) 2011, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials are made 
  * available under the terms of the Eclipse Public License v1.0 
  * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
@@ -491,7 +491,7 @@
 			});
 			return clientDeferred;
 		},
-		doGitLog : function(gitLogURI, onLoad, onError) {
+		doGitLog : function(gitLogURI, onLoad, onError, message) {
 			var service = this;
 			var clientDeferred = new dojo.Deferred();
 			dojo.xhrGet({
@@ -502,7 +502,7 @@
 				handleAs : "json",
 				timeout : 5000,
 				load : function(jsonData, xhrArgs) {
-					dojo.hitch(service, service._getGitServiceResponse)(clientDeferred, jsonData, xhrArgs, "Getting git log", onLoad);
+					dojo.hitch(service, service._getGitServiceResponse)(clientDeferred, jsonData, xhrArgs, message ? message : "Generating git log", onLoad);
 				},
 				error : function(error, ioArgs) {
 					dojo.hitch(service, service._handleGitServiceResponseError)(clientDeferred, this, error, ioArgs, onLoad, onError, dojo.xhrGet);
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 0093494..00c7f34 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
@@ -1827,37 +1827,82 @@
 		});
 		commandService.addCommand(applyPatchCommand, "object");
 		
+		var openCommitParameters = new mCommands.ParametersDescription([new mCommands.CommandParameter("commitName", "text", "Commit name:")], true);
+		
 		var openCommitCommand = new mCommands.Command({
 			name : "Open Commit",
 			tooltip: "Open the commit with the given name",
 			id : "eclipse.orion.git.openCommitCommand",
 			imageClass: "git-sprite-apply_patch",
 			spriteClass: "gitCommandSprite",
+			parameters: openCommitParameters,
 			callback: function(data) {
-				var repository;
+				var findCommitLocation = function (repositories, commitName, deferred) {
+					if (deferred == null)
+						deferred = new dojo.Deferred();
+					
+					if (repositories.length > 0) {
+						serviceRegistry.getService("orion.git.provider").doGitLog(
+							"/gitapi/commit/" + data.parameters.valueFor("commitName") + repositories[0].ContentLocation + "?page=1&pageSize=1", null, null, "Looking for the commit").then(
+							function(resp){
+								deferred.callback(resp.Children[0].Location);
+							},
+							function(error) {
+								findCommitLocation(repositories.slice(1), commitName, deferred);
+							}
+						);
+					} else {
+						deferred.errback();
+					}
+					
+					return deferred;
+				};
+				
+				var openCommit = function(repositories) {
+					if (data.parameters.optionsRequested) {
+						new orion.git.widgets.OpenCommitDialog(
+							{repositories: repositories, serviceRegistry: serviceRegistry, commitName: data.parameters.valueFor("commitName")}
+						).show();
+					} else {
+						serviceRegistry.getService("orion.page.message").setProgressMessage("Looking for the commit");
+						findCommitLocation(repositories, data.parameters.valueFor("commitName")).then(
+							function(commitLocation){
+								if(commitLocation !== null){
+									var commitPageURL = "/git/git-commit.html#" + commitLocation + "?page=1&pageSize=1";
+									window.open(commitPageURL);
+								}
+							}, function () {
+								var display = [];
+								display.Severity = "warning";
+								display.HTML = false;
+								display.Message = "No commits found";
+								serviceRegistry.getService("orion.page.message").setProgressResult(display);
+							}
+						);
+					}	
+				};
+
 				if (data.items.Type === "Clone") {
-					repository = data.items;
-					new orion.git.widgets.OpenCommitDialog(
-						{repository: repository, serviceRegistry: serviceRegistry}
-					).show();
-				} else {
-					var gitService = serviceRegistry.getService("orion.git.provider");
-					gitService.getGitClone(data.items.CloneLocation).then(
+					var repositories = [data.items];
+					openCommit(repositories);
+				} else if (data.items.CloneLocation){
+					serviceRegistry.getService("orion.git.provider").getGitClone(data.items.CloneLocation).then(
 						function(jsonData){
-							repository = jsonData.Children[0];
-							new orion.git.widgets.OpenCommitDialog(
-								{repository: repository, serviceRegistry: serviceRegistry}
-							).show();
+							var repositories = jsonData.Children;
+							openCommit(repositories);
 						}
 					);
+				} else {
+					var repositories = data.items;
+					openCommit(repositories);
 				}
 			},
 			visibleWhen : function(item) {
-				return item.Type === "Clone" || item.CloneLocation;
+				return item.Type === "Clone" || item.CloneLocation || (item.length > 1 && item[0].Type === "Clone") ;
 			}
 		});
 		commandService.addCommand(openCommitCommand, "dom");
-		
+
 		var mapToGithubCommand = new mCommands.Command({
 			name : "Go to github",
 			tooltip: "Go to the associated github repository",
diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/gitRepositoryExplorer.js b/bundles/org.eclipse.orion.client.git/web/orion/git/gitRepositoryExplorer.js
index 2a63daa..d9206e0 100644
--- a/bundles/org.eclipse.orion.client.git/web/orion/git/gitRepositoryExplorer.js
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/gitRepositoryExplorer.js
@@ -82,20 +82,14 @@
 		progressService.setProgressMessage("Loading...");
 		this.registry.getService("orion.git.provider").getGitClone(location).then(
 			function(resp){
-								
-				if (resp.Children.length === 0) {
-					progressService.setProgressMessage("");
-					that.initTitleBar();
-					
-					that.displayRepositories(null, "full");
-					return;
-				} 
 				
-				if (resp.Children.length == 1 && resp.Children[0].Type === "Clone") {
+				if (resp.Children.length === 0) {
+					that.initTitleBar({});
+					that.displayRepositories([], "full");
+				} else if (resp.Children.length == 1 && resp.Children[0].Type === "Clone") {
 					var repositories = resp.Children;
 					
 					that.initTitleBar(repositories[0]);
-	
 					that.displayRepositories(repositories);
 					that.displayStatus(repositories[0]);
 					that.displayCommits(repositories[0]);
@@ -105,8 +99,7 @@
 				} else if (resp.Children[0].Type === "Clone"){
 					var repositories = resp.Children;
 					
-					that.initTitleBar();
-					
+					that.initTitleBar(repositories);
 					that.displayRepositories(repositories, "full", true);
 				} else if (resp.Children[0].Type === "Branch"){
 					var branches = resp.Children;
@@ -148,15 +141,17 @@
 		);
 	};
 	
-	GitRepositoryExplorer.prototype.initTitleBar = function(repository, sectionName){
+	GitRepositoryExplorer.prototype.initTitleBar = function(resource, sectionName){
 		var that = this;
 		var item = {};
 		var pageTitle;		
 		
 		// render commands
-		mGitCommands.updateNavTools(that.registry, that, "pageActions", "selectionTools", (repository ? repository : {}));
+		mGitCommands.updateNavTools(that.registry, that, "pageActions", "selectionTools", resource);
 		
-		if (repository && sectionName){
+		if (resource && resource.Type === "Clone" && sectionName){
+			var repository = resource;
+			
 			item.Name = sectionName;
 			item.Parents = [];
 			item.Parents[0] = {};
@@ -166,7 +161,9 @@
 			item.Parents[1] = {};
 			item.Parents[1].Name = "Repositories";
 			pageTitle = sectionName + " on " + repository.Name + " - Git";
-		} else if (repository) {
+		} else if (resource && resource.Type === "Clone") {
+			var repository = resource;
+			
 			item.Name = repository.Name;
 			item.Parents = [];
 			item.Parents[0] = {};
@@ -281,7 +278,7 @@
 		dojo.create( "div", { id: "repositorySectionTitle", "class":"layoutLeft", innerHTML: (mode === "full" ? "Repositories" : "Repository") }, titleWrapper );
 		dojo.create( "div", { id: "repositorySectionActionsArea", "class":"layoutRight sectionActions"}, titleWrapper );
 				
-		if (!repositories){
+		if (!repositories || repositories.length === 0){
 			dojo.byId("repositorySectionTitle").innerHTML = (mode === "full" ? "No Repositories" : "Repository Not Found");
 			return;
 		}
diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/OpenCommitDialog.js b/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/OpenCommitDialog.js
index 4b47018..4f5430f 100644
--- a/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/OpenCommitDialog.js
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/OpenCommitDialog.js
@@ -43,10 +43,12 @@
 			throw new Error("Missing required argument: serviceRegistry");
 		}
 		
-		this.repository = this.options.repository;
-		if (!this.repository) {
-			throw new Error("Missing required argument: repository");
+		this.repositories = this.options.repositories;
+		if (!this.repositories) {
+			throw new Error("Missing required argument: repositories");
 		}
+		
+		this.commitName = this.options.commitName;
 	},
 	
 	/** @private */
@@ -78,6 +80,8 @@
 			// WebKit focuses <body> after link is clicked; override that
 			e.target.focus();
 		});
+		
+		this.resourceName.set("value", this.commitName);
 	},
 	
 	/** @private */
@@ -92,6 +96,28 @@
 		}
 	},
 	
+	_findCommitLocation: function(repositories, commitName, deferred) {
+		var that = this;
+		if (deferred == null)
+			deferred = new dojo.Deferred();
+		
+		if (repositories.length > 0) {
+			that.serviceRegistry.getService("orion.git.provider").doGitLog(
+				"/gitapi/commit/" + commitName + repositories[0].ContentLocation + "?page=1&pageSize=1", null, null, "Looking for the commit").then(
+				function(resp){
+					deferred.callback(resp.Children[0]);
+				},
+				function(error) {
+					that._findCommitLocation(repositories.slice(1), commitName, deferred);
+				}
+			);
+		} else {
+			deferred.errback();
+		}
+		
+		return deferred;
+	},
+	
 	/** @private */
 	doSearch: function() {
 		var text = this.resourceName && this.resourceName.get("value");
@@ -101,15 +127,16 @@
 			dojo.place("<div>Searching&#x2026;</div>", this.results, "only");
 			var that = this;
 			
-			this.serviceRegistry.getService("orion.git.provider").doGitLog(
-				"/gitapi/commit/" + text + this.repository.ContentLocation + "?page=1&pageSize=1").then(
+			this.serviceRegistry.getService("orion.page.message").setProgressMessage("Looking for the commit");
+			this._findCommitLocation(this.repositories, text).then(
 				function(resp){
-					var commit = resp.Children[0];
+					var commit = resp;
 					dojo.empty(that.results);
 					that.displayCommit(commit, that.results);
 				},
 				function(error) {
-					dojo.place("<div>No matches found</div>", that.results, "only");
+					dojo.place("<div>No commits found</div>", that.results, "only");
+					that.serviceRegistry.getService("orion.page.message").setProgressMessage("");
 				}
 			);
 		}