bug 379966 - git-status2 needs a way to change committer/author name and
mail on commit
https://bugs.eclipse.org/bugs/show_bug.cgi?id=379966
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 82346df..89d0f96 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
@@ -13,7 +13,8 @@
 /*jslint browser:true eqeqeq:false laxbreak:true */
 define(['require', 'dojo', 'orion/commands', 'orion/util', 'orion/git/util', 'orion/git/widgets/CloneGitRepositoryDialog', 
         'orion/git/widgets/AddRemoteDialog', 'orion/git/widgets/GitCredentialsDialog', 'orion/widgets/NewItemDialog', 
-        'orion/git/widgets/RemotePrompterDialog', 'orion/git/widgets/ApplyPatchDialog', 'orion/git/widgets/OpenCommitDialog', 'orion/git/widgets/ContentDialog'], 
+        'orion/git/widgets/RemotePrompterDialog', 'orion/git/widgets/ApplyPatchDialog', 'orion/git/widgets/OpenCommitDialog', 
+        'orion/git/widgets/ContentDialog', 'orion/git/widgets/CommitDialog'], 
         function(require, dojo, mCommands, mUtil, mGitUtil) {
 
 /**
@@ -2365,7 +2366,8 @@
 		commandService.addCommand(unstageCommand);
 		
 		var commitMessageParameters = new mCommands.ParametersDescription(
-			[new mCommands.CommandParameter('name', 'text', 'Commit message:'), new mCommands.CommandParameter('amend', 'boolean', 'Amend:', false)]);
+			[new mCommands.CommandParameter('name', 'text', 'Commit message:'), new mCommands.CommandParameter('amend', 'boolean', 'Amend:', false)],
+			 {hasOptionalParameters: true});
 		
 		var commitCommand = new mCommands.Command({
 			name: "Commit",
@@ -2375,18 +2377,44 @@
 			callback: function(data) {
 				var item = data.items;
 				
+				var commitFunction = function(body){		
+					var progressService = serviceRegistry.getService("orion.page.message");
+					progressService.createProgressMonitor(
+						serviceRegistry.getService("orion.git.provider").commitAll(item.CommitLocation, null, dojo.toJson(body)),
+						"Committing changes").deferred.then(
+						function(jsonData){
+							dojo.hitch(explorer, explorer.changedItem)(item);
+						}, displayErrorOnStatus
+					);
+				};
+				
 				var body = {};
 				body.Message = data.parameters.valueFor("name");
 				body.Amend = data.parameters.valueFor("amend");
 				
-				var progressService = serviceRegistry.getService("orion.page.message");
-				progressService.createProgressMonitor(
-					serviceRegistry.getService("orion.git.provider").commitAll(item.CommitLocation, null, dojo.toJson(body)),
-					"Committing changes").deferred.then(
-					function(jsonData){
-						dojo.hitch(explorer, explorer.changedItem)(item);
-					}, displayErrorOnStatus
-				);
+				var config = item.Clone.Config;
+				for (var i=0; i < config.length; i++){
+					if (config[i].Key === "user.name"){
+						body.CommitterName = config[i].Value;
+						body.AuthorName = config[i].Value;
+					} else if (config[i].Key === "user.email"){
+						body.CommitterEmail = config[i].Value;
+						body.AuthorEmail = config[i].Value;
+					}					
+				}
+				
+
+				if (body.Message && body.CommitterName && body.CommitterEmail && !data.parameters.optionsRequested) {
+					commitFunction(body);
+				} else {
+					var dialog = new orion.git.widgets.CommitDialog({
+						body: body,
+						func: commitFunction
+					});
+							
+					dialog.startup();
+					dialog.show();
+				}
 			},
 			visibleWhen: function(item) {
 				return mGitUtil.hasStagedChanges(item);
diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/gitStatusExplorer.js b/bundles/org.eclipse.orion.client.git/web/orion/git/gitStatusExplorer.js
index 8a1c9b8..529ebdd 100644
--- a/bundles/org.eclipse.orion.client.git/web/orion/git/gitStatusExplorer.js
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/gitStatusExplorer.js
@@ -183,24 +183,37 @@
 						

 						that.registry.getService("orion.git.provider").getGitClone(status.CloneLocation).then(

 							function(resp){

-								loadingDeferred.callback();

 								var repositories = resp.Children;

 								

-								// TODO this is a workaround for missing shaping resource feature

-								status.Clone = repositories[0];

-								

-								var tableNode = dojo.byId( 'table' );	

-								dojo.empty( tableNode );

-								

-								that.initTitleBar(status, repositories[0]);

-				

-								that.displayUnstaged(status, repositories[0]);

-								that.displayStaged(status, repositories[0]);

-//								that.displayDiffs(status);

-								that.displayCommits(repositories[0]);

-								

-								// render commands

-								mGitCommands.updateNavTools(that.registry, that, "pageActions", "selectionTools", status);

+								that.registry.getService("orion.git.provider").getGitCloneConfig(repositories[0].ConfigLocation).then(

+									function(resp){

+										loadingDeferred.callback();

+										var config = resp.Children;

+										

+										status.Clone = repositories[0];

+										status.Clone.Config = [];

+										

+										for (var i=0; i < config.length; i++){

+											if (config[i].Key === "user.name" || config[i].Key === "user.email")

+												status.Clone.Config.push(config[i])

+										}

+										

+										var tableNode = dojo.byId( 'table' );	

+										dojo.empty( tableNode );

+										

+										that.initTitleBar(status, repositories[0]);

+						

+										that.displayUnstaged(status, repositories[0]);

+										that.displayStaged(status, repositories[0]);

+										that.displayCommits(repositories[0]);

+										

+										// render commands

+										mGitCommands.updateNavTools(that.registry, that, "pageActions", "selectionTools", status);

+									}, function (error) {

+										loadingDeferred.callback();

+										dojo.hitch(that, that.handleError)(error);

+									}

+								);

 							}, function (error) {

 								loadingDeferred.callback();

 								dojo.hitch(that, that.handleError)(error);

diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/CommitDialog.js b/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/CommitDialog.js
new file mode 100644
index 0000000..92b6483
--- /dev/null
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/CommitDialog.js
@@ -0,0 +1,121 @@
+/******************************************************************************* 

+ * @license

+ * Copyright (c) 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 

+ * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

+ * 

+ * Contributors: IBM Corporation - initial API and implementation

+ ******************************************************************************/

+

+/*global dojo dijit widgets*/

+

+define(['dojo', 'dijit', 'dijit/Dialog', 'orion/widgets/_OrionDialogMixin', 'text!orion/git/widgets/templates/CommitDialog.html'], function(dojo, dijit) {

+

+/**

+ * @param options {{ 

+ *     func: function

+ * }}

+ */

+dojo.declare("orion.git.widgets.CommitDialog", [dijit.Dialog, orion.widgets._OrionDialogMixin], {

+	widgetsInTemplate: true,

+	templateString: dojo.cache('orion', 'git/widgets/templates/CommitDialog.html'),

+	

+	constructor : function() {

+		this.inherited(arguments);

+		this.options = arguments[0] || {};

+	},

+	

+	postMixInProperties : function() {

+		this.inherited(arguments);

+		this.title = "Commit Changes";

+		this.commitMessageLabelText = "Message:";

+		this.amendLabelText = "Amend:";

+		this.committerNameLabelText = "Committer Name:";

+		this.committerEmailLabelText = "Committer Email:";

+		this.authorNameLabelText = "Author Name:";

+		this.authorEmailLabelText = "Author Email:";

+	},

+	

+	postCreate : function(){

+		var that = this;

+		this.inherited(arguments);

+		

+		if (this.options.body.Message) {

+			this.commitMessage.value = this.options.body.Message;

+		}

+		dojo.connect(this.commitMessage, "onkeyup", dojo.hitch(this, this.validate));

+		

+		if (this.options.body.Amend) {

+			this.amend.checked = true;

+		}

+		

+		if (this.options.body.CommitterName) {

+			this.committerName.value = this.options.body.CommitterName;

+		}

+		dojo.connect(this.committerName, "onkeyup", dojo.hitch(this, this.validate));

+		

+		if (this.options.body.CommitterEmail) {

+			this.committerEmail.value = this.options.body.CommitterEmail;

+		}

+		dojo.connect(this.committerEmail, "onkeyup", dojo.hitch(this, this.validate));

+		

+		if (this.options.body.AuthorName) {

+			this.authorName.value = this.options.body.AuthorName;

+		}

+		dojo.connect(this.authorName, "onkeyup", dojo.hitch(this, this.validate));

+		

+		if (this.options.body.AuthorEmail) {

+			this.authorEmail.value = this.options.body.AuthorEmail;

+		}

+		dojo.connect(this.authorEmail, "onkeyup", dojo.hitch(this, this.validate));

+		

+		this.validate();

+	},

+	

+	validate: function() {

+		if (!this.commitMessage.value) {

+			dojo.style(this.commitInfoBar, "display", "block");

+			this.commitChangesButton.disabled = true;

+			this.commitInfo.innerHTML = "The commit message is required.";

+		} else if (!this.committerName.value) {

+			dojo.style(this.commitInfoBar, "display", "block");

+			this.commitChangesButton.disabled = true;

+			this.commitInfo.innerHTML = "The committer name is required.";

+		} else if (!this.committerEmail.value) {

+			dojo.style(this.commitInfoBar, "display", "block");

+			this.commitChangesButton.disabled = true;

+			this.commitInfo.innerHTML = "The committer mail is required.";

+		} else if (!this.authorName.value) {

+			dojo.style(this.commitInfoBar, "display", "block");

+			this.commitChangesButton.disabled = true;

+			this.commitInfo.innerHTML = "The author name is required.";

+		} else if (!this.authorEmail.value) {

+			dojo.style(this.commitInfoBar, "display", "block");

+			this.commitChangesButton.disabled = true;

+			this.commitInfo.innerHTML = "The author mail is required.";

+		} else {

+			dojo.style(this.commitInfoBar, "display", "none");

+			this.commitChangesButton.disabled = false;

+		}

+	},

+	

+	execute: function() {

+		if(this.options.func){

+			var body = {};

+			

+			body.Message = this.commitMessage.value;

+			body.Amend = this.amend.checked ? true : false;

+			body.CommitterName = this.committerName.value;

+			body.CommitterEmail = this.committerEmail.value;

+			body.AuthorName = this.authorName.value;

+			body.AuthorEmail = this.authorEmail.value;

+			

+			this.options.func(body);

+		}

+		delete this.options.func; //prevent performing this action twice (IE)

+	}

+});

+

+});
\ No newline at end of file
diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/templates/CommitDialog.html b/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/templates/CommitDialog.html
new file mode 100644
index 0000000..f248f33
--- /dev/null
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/widgets/templates/CommitDialog.html
@@ -0,0 +1,77 @@
+<div class="dijitDialog" tabindex="-1" waiRole="dialog" waiState="labelledby-${id}_title">

+	<div dojoAttachPoint="titleBar" class="dijitDialogTitleBar">

+		<span dojoAttachPoint="titleNode" class="dijitDialogTitle" id="${id}_title"></span>

+		<span dojoAttachPoint="closeButtonNode" class="dijitDialogCloseIcon" dojoAttachEvent="onclick: onCancel" title="${buttonCancel}">

+			<span dojoAttachPoint="closeText" class="closeText" title="${buttonCancel}">x</span>

+		</span>

+	</div>

+	<div dojoAttachPoint="containerNode" class="dijitDialogPaneContent">

+		<!-- Actual content here -->

+		<div style="display: none; padding-top: 10px; padding-bottom: 10px;" dojoAttachPoint="commitInfoBar"><b dojoAttachPoint="commitInfo"></b></div>

+		

+		<div style="display: table">

+		

+			<div style="display: table-row">

+				<div style="display: table-cell; padding: 5">

+					<label dojoAttachPoint="commitMessageLabel" for="${id}_commitMessage" style="padding-right: 10">${commitMessageLabelText}</label>

+				</div>

+				<div style="display: table-cell; padding: 5; width: 40em; text-align: left;">

+					<input dojoAttachPoint="commitMessage" id="${id}_commitMessage" style="display: inline-block; width: 98%;" value="">

+				</div>

+			</div>

+			

+			<div style="display: table-row">

+				<div style="display: table-cell; padding: 5">

+					<label dojoAttachPoint="amendLabel" for="${id}_amend" style="padding-right: 10">${amendLabelText}</label>

+				</div>

+				<div style="display: table-cell; padding: 5; width: 40em; text-align: left;">

+					<input dojoAttachPoint="amend" id="${id}_amend" type="checkbox" style="display: inline-block;">

+				</div>

+			</div>

+			

+			<div style="display: table-row">

+				<div style="display: table-cell; padding: 5">

+					<label dojoAttachPoint="committerNameLabel" for="${id}_committerName" style="padding-right: 10">${committerNameLabelText}</label>

+				</div>

+				<div style="display: table-cell; padding: 5; width: 40em; text-align: left;">

+					<input dojoAttachPoint="committerName" id="${id}_committerName" style="display: inline-block; width: 98%;" value="">

+				</div>

+			</div>

+			

+			<div style="display: table-row">

+				<div style="display: table-cell; padding: 5">

+					<label dojoAttachPoint="committerEmailLabel" for="${id}_committerEmail" style="padding-right: 10">${committerEmailLabelText}</label>

+				</div>

+				<div style="display: table-cell; padding: 5; width: 40em; text-align: left;">

+					<input dojoAttachPoint="committerEmail" id="${id}_committerEmail" style="display: inline-block; width: 98%;" value="">

+				</div>

+			</div>

+			

+			<div style="display: table-row">

+				<div style="display: table-cell; padding: 5">

+					<label dojoAttachPoint="authorNameLabel" for="${id}_authorName" style="padding-right: 10">${authorNameLabelText}</label>

+				</div>

+				<div style="display: table-cell; padding: 5; width: 40em; text-align: left;">

+					<input dojoAttachPoint="authorName" id="${id}_authorName" style="display: inline-block; width: 98%;" value="">

+				</div>

+			</div>

+			

+			<div style="display: table-row">

+				<div style="display: table-cell; padding: 5">

+					<label dojoAttachPoint="authorEmailLabel" for="${id}_authorEmail" style="padding-right: 10">${authorEmailLabelText}</label>

+				</div>

+				<div style="display: table-cell; padding: 5; width: 40em; text-align: left;">

+					<input dojoAttachPoint="authorEmail" id="${id}_authorEmail" style="display: inline-block; width: 98%;" value="">

+				</div>

+			</div>

+			

+			<div style="display: table-row">

+				<div style="display: table-cell; padding: 5"></div>

+				<div style="display: table-cell; padding: 5">

+					<button dojoAttachPoint="commitChangesButton" dojoType="dijit.form.Button" type="submit" value="OK" style="padding: 20 0 10 0; float: right; clear: both;">OK

+					</button>

+				</div>

+			</div>

+		</div>

+	</div>

+</div>
\ No newline at end of file