401 changes: 257 additions & 144 deletions bundles/org.eclipse.orion.client.git/web/orion/git/gitCommands.js
Expand Up @@ -13,7 +13,7 @@
/*jslint browser:true eqeqeq:false laxbreak:true */
define(['i18n!git/nls/gitmessages', 'require', 'dojo', 'orion/commands', 'orion/util', 'orion/git/util', 'orion/compare/compareUtils', '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/RemotePrompterDialog', 'orion/git/widgets/ApplyPatchDialog', 'orion/git/widgets/OpenCommitDialog', 'orion/git/widgets/ConfirmPushDialog',
'orion/git/widgets/ContentDialog', 'orion/git/widgets/CommitDialog'],
function(messages, require, dojo, mCommands, mUtil, mGitUtil, mCompareUtils) {

Expand Down Expand Up @@ -1183,23 +1183,24 @@ var exports = {};
}
});
commandService.addCommand(rebaseCommand);

var pushCommand = new mCommands.Command({
name : messages["Push All"],
tooltip: messages["Push commits and tags from your local branch into the remote branch"],
imageClass: "git-sprite-push", //$NON-NLS-0$
spriteClass: "gitCommandSprite", //$NON-NLS-0$
id : "eclipse.orion.git.push", //$NON-NLS-0$
callback: function(data) {

var target;
var item = data.items;
var path = dojo.hash();
if (item.toRef) {
item = item.toRef;
}

var commandInvocation = data;

var parts = item.CloneLocation.split("/");

var handleResponse = function(jsonData, commandInvocation){
if (jsonData.JsonData.HostKey){
commandInvocation.parameters = null;
Expand All @@ -1220,99 +1221,155 @@ var exports = {};
commandService.collectParameters(commandInvocation);
return;
}

exports.gatherSshCredentials(serviceRegistry, commandInvocation).then(
function(options) {

var gitService = serviceRegistry.getService("orion.git.provider"); //$NON-NLS-0$
if (item.RemoteLocation.length == 1 && item.RemoteLocation[0].Children.length == 1) {
var progressService = serviceRegistry.getService("orion.page.message"); //$NON-NLS-0$
progressService.createProgressMonitor(gitService.doPush(item.RemoteLocation[0].Children[0].Location, "HEAD", true, false, //$NON-NLS-0$
options.gitSshUsername, options.gitSshPassword,
options.knownHosts, options.gitPrivateKey, options.gitPassphrase), messages["Pushing remote: "] + path).deferred.then(
function(jsonData){
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {
if (explorer.parentId === "explorer-tree") { //$NON-NLS-0$
if (!jsonData || !jsonData.HttpCode)
dojo.query(".treeTableRow").forEach(function(node, i) { //$NON-NLS-0$
dojo.toggleClass(node, "outgoingCommitsdRow", false); //$NON-NLS-0$
});
} else {
dojo.hitch(explorer, explorer.changedItem)();
}
}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
}
);
}, function(jsonData, secondArg) {
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {

}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
var gitService = serviceRegistry.getService("orion.git.provider");

var handlePush = function(options, location, ref, name, force){
var progressService = serviceRegistry.getService("orion.page.message"); //$NON-NLS-0$
progressService.createProgressMonitor(gitService.doPush(location, ref, true, force, //$NON-NLS-0$
options.gitSshUsername, options.gitSshPassword, options.knownHosts,
options.gitPrivateKey, options.gitPassphrase), messages['Pushing remote: '] + name).deferred.then(
function(jsonData){
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {
if (explorer.parentId === "explorer-tree") { //$NON-NLS-0$
if (!jsonData || !jsonData.HttpCode)
dojo.query(".treeTableRow").forEach(function(node, i) { //$NON-NLS-0$
dojo.toggleClass(node, "outgoingCommitsdRow", false); //$NON-NLS-0$
});
} else {
dojo.hitch(explorer, explorer.changedItem)();
}
);
}
);
} else {
}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
}
);
}, function(jsonData, secondArg) {
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {

}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
}
);
}
);
};

gitService.getGitClone(item.CloneLocation).then(
function(clone){
var remoteLocation = clone.Children[0].RemoteLocation;
var locationToChange = clone.Children[0].ConfigLocation;
exports.gatherSshCredentials(serviceRegistry, commandInvocation).then(
function(options) {
if (item.RemoteLocation.length == 1 && item.RemoteLocation[0].Children.length == 1) { //when we push next time - chance to switch saved remote
gitService.getGitRemote(remoteLocation).then(
function(resp){
var remotes = resp.Children;
var dialog = new orion.git.widgets.RemotePrompterDialog({
title: messages["Choose Branch"],
serviceRegistry: serviceRegistry,
gitClient: gitService,
treeRoot: {
Children: remotes
},
hideNewBranch: false,
func: dojo.hitch(this,
function(targetBranch, remote, optional) {//third argument occurs when remote name is typed, not selected from the list
if(targetBranch === null){
target = optional;
}
else{
target = targetBranch;
}
var locationToUpdate = "/gitapi/config/" + "branch." + item.Name + ".remote" + "/clone/file/" + parts[4];
gitService.addCloneConfigurationProperty(locationToChange,"branch." + item.Name + ".remote" ,target.parent.Name).then(
function(){
handlePush(options, target.Location, "HEAD",target.Name, false);
},
function(err){
if(err.status == 409){ //when confing entry is already defined we have to edit it
gitService.editCloneConfigurationProperty(locationToUpdate,target.parent.Name).then(
function(){
handlePush(options, target.Location, "HEAD",target.Name, false);
},
function(error){
}
);
}
}
);
}
)
});
var dialog2 = new orion.git.widgets.ConfirmPushDialog({
title: messages["Choose Branch"],
serviceRegistry: serviceRegistry,
gitClient: gitService,
dialog: dialog,
location: item.RemoteLocation[0].Children[0].Name,
func: dojo.hitch(this, function(){handlePush(options,item.RemoteLocation[0].Children[0].Location, "HEAD", path, true);})
});
dialog2.startup();
dialog2.show();
},
function(err){
}
);
}
else { //pushing first time - branch tracs no remote yet
var remotes = item.RemoteLocation;

var dialog = new orion.git.widgets.RemotePrompterDialog({
title: messages["Choose Branch"],
serviceRegistry: serviceRegistry,
gitClient: gitService,
treeRoot: {
Children: remotes
},
hideNewBranch: true,
hideNewBranch: false,
func: dojo.hitch(this,
function(targetBranch, remote) {
var progressService = serviceRegistry.getService("orion.page.message"); //$NON-NLS-0$
progressService.createProgressMonitor(gitService.doPush(targetBranch.Location, "HEAD", true, true, //$NON-NLS-0$
options.gitSshUsername, options.gitSshPassword, options.knownHosts,
options.gitPrivateKey, options.gitPassphrase), messages['Pushing remote: '] + remote.Name).deferred.then(
function(jsonData){
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {
if (explorer.parentId === "explorer-tree") { //$NON-NLS-0$
if (!jsonData || !jsonData.HttpCode)
dojo.query(".treeTableRow").forEach(function(node, i) { //$NON-NLS-0$
dojo.toggleClass(node, "outgoingCommitsdRow", false); //$NON-NLS-0$
});
} else {
dojo.hitch(explorer, explorer.changedItem)();
function(targetBranch, remote, optional) {
if(targetBranch === null){
target = optional;
}
else{
target = targetBranch;
}
var locationToUpdate = "/gitapi/config/" + "branch." + item.Name + ".remote" + "/clone/file/" + parts[4];
gitService.addCloneConfigurationProperty(locationToChange,"branch." + item.Name + ".remote" ,target.parent.Name).then(
function(){
handlePush(options, target.Location, "HEAD",target.Name, false);
},
function(err){
if(err.status == 409){ //when confing entry is already defined we have to edit it
gitService.editCloneConfigurationProperty(locationToUpdate,target.parent.Name).then(
function(){
handlePush(options, target.Location, "HEAD",target.Name, false);
}
}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
}
);
}, function(jsonData, secondArg) {
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {

}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
}
);
);
}
}
);
}
)
});
dialog.startup();
dialog.show();
}
dialog.startup();
dialog.show();
}
}
);
}
);
);
},
visibleWhen : function(item) {
if (item.toRef)
// for action in the git log
return item.RepositoryPath === "" && item.toRef.Type === "Branch" && item.toRef.Current && item.toRef.RemoteLocation; //$NON-NLS-0$
else
if(item.Type === "LocalBranch")
return true;
// for action in the repo view
return item.Type === "Branch" && item.Current && item.RemoteLocation; //$NON-NLS-0$

}
});
commandService.addCommand(pushCommand);
Expand All @@ -1326,15 +1383,16 @@ var exports = {};
callback: function(data) {
if(!confirm(messages["You're going to override content of the remote branch. This can cause the remote repository to lose commits."]+"\n\n"+messages['Are you sure?'])) //$NON-NLS-1$
return;

var target;
var item = data.items;
var path = dojo.hash();
if (item.toRef) {
item = item.toRef;
}

var commandInvocation = data;

var parts = item.CloneLocation.split("/");

var handleResponse = function(jsonData, commandInvocation){
if (jsonData.JsonData.HostKey){
commandInvocation.parameters = null;
Expand All @@ -1355,97 +1413,152 @@ var exports = {};
commandService.collectParameters(commandInvocation);
return;
}

exports.gatherSshCredentials(serviceRegistry, commandInvocation).then(
function(options) {

var gitService = serviceRegistry.getService("orion.git.provider"); //$NON-NLS-0$
if (item.RemoteLocation.length == 1 && item.RemoteLocation[0].Children.length == 1) {
var progressService = serviceRegistry.getService("orion.page.message"); //$NON-NLS-0$
progressService.createProgressMonitor(gitService.doPush(item.RemoteLocation[0].Children[0].Location, "HEAD", true, true, //$NON-NLS-0$
options.gitSshUsername, options.gitSshPassword,
options.knownHosts, options.gitPrivateKey, options.gitPassphrase), messages['Pushing remote: '] + path).deferred.then(
function(jsonData){
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {
if (explorer.parentId === "explorer-tree") { //$NON-NLS-0$
if (!jsonData || !jsonData.HttpCode)
dojo.query(".treeTableRow").forEach(function(node, i) { //$NON-NLS-0$
dojo.toggleClass(node, "outgoingCommitsdRow", false); //$NON-NLS-0$
});
} else {
dojo.hitch(explorer, explorer.changedItem)();
}
}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
}
);
}, function(jsonData, secondArg) {
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {

}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
var gitService = serviceRegistry.getService("orion.git.provider");

var handlePush = function(options, location, ref, name, force){
var progressService = serviceRegistry.getService("orion.page.message"); //$NON-NLS-0$
progressService.createProgressMonitor(gitService.doPush(location, ref, true, force, //$NON-NLS-0$
options.gitSshUsername, options.gitSshPassword, options.knownHosts,
options.gitPrivateKey, options.gitPassphrase), messages['Pushing remote: '] + name).deferred.then(
function(jsonData){
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {
if (explorer.parentId === "explorer-tree") { //$NON-NLS-0$
if (!jsonData || !jsonData.HttpCode)
dojo.query(".treeTableRow").forEach(function(node, i) { //$NON-NLS-0$
dojo.toggleClass(node, "outgoingCommitsdRow", false); //$NON-NLS-0$
});
} else {
dojo.hitch(explorer, explorer.changedItem)();
}
);
}
);
} else {
}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
}
);
}, function(jsonData, secondArg) {
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {

}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
}
);
}
);
};

gitService.getGitClone(item.CloneLocation).then(
function(clone){
var remoteLocation = clone.Children[0].RemoteLocation;
var locationToChange = clone.Children[0].ConfigLocation;
exports.gatherSshCredentials(serviceRegistry, commandInvocation).then(
function(options) {
if (item.RemoteLocation.length == 1 && item.RemoteLocation[0].Children.length == 1) { //when we push next time - chance to switch saved remote
gitService.getGitRemote(remoteLocation).then(
function(resp){
var remotes = resp.Children;
var dialog = new orion.git.widgets.RemotePrompterDialog({
title: messages["Choose Branch"],
serviceRegistry: serviceRegistry,
gitClient: gitService,
treeRoot: {
Children: remotes
},
hideNewBranch: false,
func: dojo.hitch(this,
function(targetBranch, remote, optional) {//third argument occurs when remote name is typed, not selected from the list
if(targetBranch === null){
target = optional;
}
else{
target = targetBranch;
}
var locationToUpdate = "/gitapi/config/" + "branch." + item.Name + ".remote" + "/clone/file/" + parts[4];
gitService.addCloneConfigurationProperty(locationToChange,"branch." + item.Name + ".remote" ,target.parent.Name).then(
function(){
handlePush(options, target.Location, "HEAD",target.Name, true);
},
function(err){
if(err.status == 409){ //when confing entry is already defined we have to edit it
gitService.editCloneConfigurationProperty(locationToUpdate,target.parent.Name).then(
function(){
handlePush(options, target.Location, "HEAD",target.Name, true);
},
function(error){
}
);
}
}
);
}
)
});
var dialog2 = new orion.git.widgets.ConfirmPushDialog({
title: messages["Choose Branch"],
serviceRegistry: serviceRegistry,
gitClient: gitService,
dialog: dialog,
location: item.RemoteLocation[0].Children[0].Name,
func: dojo.hitch(this, function(){handlePush(options,item.RemoteLocation[0].Children[0].Location, "HEAD", path, true);})
});
dialog2.startup();
dialog2.show();
},
function(err){
}
);
}
else { //pushing first time - branch tracs no remote yet
var remotes = item.RemoteLocation;

var dialog = new orion.git.widgets.RemotePrompterDialog({
title: messages['Choose Branch'],
title: messages["Choose Branch"],
serviceRegistry: serviceRegistry,
gitClient: gitService,
treeRoot: {
Children: remotes
},
hideNewBranch: true,
hideNewBranch: false,
func: dojo.hitch(this,
function(targetBranch, remote) {
var progressService = serviceRegistry.getService("orion.page.message"); //$NON-NLS-0$
progressService.createProgressMonitor(gitService.doPush(targetBranch.Location, "HEAD", true, true, //$NON-NLS-0$
options.gitSshUsername, options.gitSshPassword, options.knownHosts,
options.gitPrivateKey, options.gitPassphrase), messages['Pushing remote: '] + remote.Name).deferred.then(
function(jsonData){
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {
if (explorer.parentId === "explorer-tree") { //$NON-NLS-0$
if (!jsonData || !jsonData.HttpCode)
dojo.query(".treeTableRow").forEach(function(node, i) { //$NON-NLS-0$
dojo.toggleClass(node, "outgoingCommitsdRow", false); //$NON-NLS-0$
});
} else {
dojo.hitch(explorer, explorer.changedItem)();
function(targetBranch, remote, optional) {
if(targetBranch === null){
target = optional;
}
else{
target = targetBranch;
}
var locationToUpdate = "/gitapi/config/" + "branch." + item.Name + ".remote" + "/clone/file/" + parts[4];
gitService.addCloneConfigurationProperty(locationToChange,"branch." + item.Name + ".remote" ,target.parent.Name).then(
function(){
handlePush(options, target.Location, "HEAD",target.Name, true);
},
function(err){
if(err.status == 409){ //when confing entry is already defined we have to edit it
gitService.editCloneConfigurationProperty(locationToUpdate,target.parent.Name).then(
function(){
handlePush(options, target.Location, "HEAD",target.Name, true);
}
}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
}
);
}, function(jsonData, secondArg) {
exports.handleProgressServiceResponse2(jsonData, serviceRegistry,
function() {

}, function (jsonData) {
handleResponse(jsonData, commandInvocation);
}
);
);
}
}
);
}
)
});
dialog.startup();
dialog.show();
}
dialog.startup();
dialog.show();
}
}
);
}
);

);
},
visibleWhen : function(item) {
if (item.toRef)
// for action in the git log
if(item.Type === "LocalBranch")
return true;
return item.RepositoryPath === "" && item.toRef.Type === "Branch" && item.toRef.Current && item.toRef.RemoteLocation; //$NON-NLS-0$

}
});
commandService.addCommand(pushForceCommand);
Expand Down
@@ -0,0 +1,51 @@
/*******************************************************************************
* @license
* Copyright (c) 2010, 2011 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
******************************************************************************/
/*jslint browser:true*/
/*global alert confirm orion window widgets eclipse:true serviceRegistry define */
define(['i18n!git/nls/gitmessages', 'dojo', 'dijit', 'dojox', 'dijit/Dialog', "orion/util", 'dojo/data/ItemFileReadStore', 'dojox/form/Uploader', 'dojox/form/uploader/FileList',
'dojox/form/uploader/plugins/IFrame', 'dijit/form/Button','dijit/ProgressBar', 'orion/widgets/_OrionDialogMixin',
'text!orion/git/widgets/templates/ConfirmPushDialog.html'], function(messages, dojo, dijit,dojox) {


dojo.declare("orion.git.widgets.ConfirmPushDialog", [dijit.Dialog, orion.widgets._OrionDialogMixin], { //$NON-NLS-0$
widgetsInTemplate: true,
templateString: dojo.cache('orion', 'git/widgets/templates/ConfirmPushDialog.html'), //$NON-NLS-1$ //$NON-NLS-0$

constructor : function() {
this.inherited(arguments);
this.options = arguments[0] || {};
},
postMixInProperties : function() {
this.inherited(arguments);
this.title = "Git Push";

},
postCreate: function() {
var that = this;
this.inherited(arguments);
this.dialog = this.options.dialog;
var header = dojo.byId("div1");
var button = dojo.byId("moreButton");
var dialog2 = this.options.dialog;
header.innerHTML = "You are going to push to the following remote: " + this.options.location + "<br><br> Click More to push to another remote or OK to push to default" ;
dojo.connect(button,"onclick",function(){
dialog2.startup();
dialog2.show();
that.destroy();
});

},
execute: function() {
this.options.func();
}

});
});
Expand Up @@ -107,12 +107,12 @@ dojo.declare("orion.git.widgets.RemotePrompterDialog", [ dijit.Dialog, orion.wid

validate : function(){
var selectedItems = this.treeWidget.getSelectedItems();
if(selectedItems.length==1){
if(selectedItems.length===1){
if(selectedItems[0].Type==="RemoteTrackingBranch"){ //$NON-NLS-0$
this.RemoteBrowserButton.disabled = false;
return;
}else if(selectedItems[0].Type==="Remote"){ //$NON-NLS-0$
if(this.newBranch.value!=""){
if(this.newBranch.value!==""){
this.RemoteBrowserButton.disabled = false;
return;
}
Expand All @@ -128,7 +128,14 @@ dojo.declare("orion.git.widgets.RemotePrompterDialog", [ dijit.Dialog, orion.wid
if(selectedItems[0].Type==="RemoteTrackingBranch"){ //$NON-NLS-0$
this.options.func(selectedItems[0], selectedItems[0].parent);
}else{
this.options.func(null, selectedItems[0], this.newBranch.value);
var id = selectedItems[0].CloneLocation.split("/")[4];
var newBranchObject = new Object();
newBranchObject.parent = selectedItems[0];
newBranchObject.FullName = "refs/remotes/" + selectedItems[0].Name + "/" + this.newBranch.value;
newBranchObject.Name = selectedItems[0].Name + "/" + this.newBranch.value;
newBranchObject.Type = "RemoteTrackingBranch";
newBranchObject.Location= "/gitapi/remote/" + selectedItems[0].Name + "/" + this.newBranch.value + "/file/" + id;
this.options.func(null, selectedItems[0], newBranchObject);
}
}
delete this.options.func; //prevent performing this action twice (IE)
Expand Down
@@ -0,0 +1,22 @@
<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="text-align: left"-->
<div style="padding: 0px; text-align: left;" , id = "div1">
</div>
<div style="padding-top:10px; text-align: right;">
<input type="button" id = "moreButton" label="More" value="OK" dojoType="dijit.form.Button"
style="text-align:right; display:inline-block; clear: both"/>
<input type="submit" label="OK" value="OK" dojoType="dijit.form.Button"
style="text-align:right; display:inline-block; clear: both"/>

</div>
<!--/div-->
</div>
</div>