/** * Copyright JS Foundation and other contributors, http://js.foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ RED.sidebar.versionControl = (function() { var sidebarContent; var sections; var allChanges = {}; var unstagedChangesList; var stageAllButton; var stagedChangesList; var unstageAllButton; var unstagedChanges; var stagedChanges; var bulkChangeSpinner; var unmergedContent; var unmergedChangesList; var commitButton; var localChanges; var localCommitList; var localCommitListShade; // var remoteCommitList; var isMerging; function viewFileDiff(entry,state) { var activeProject = RED.projects.getActiveProject(); var diffTarget = (state === 'staged')?"index":"tree"; utils.sendRequest({ url: "projects/"+activeProject.name+"/diff/"+diffTarget+"/"+encodeURIComponent(entry.file), type: "GET", responses: { 0: function(error) { console.log(error); // done(error,null); }, 200: function(data) { var title; if (state === 'unstaged') { title = RED._("sidebar.project.versionControl.unstagedChanges")+' : '+entry.file } else if (state === 'staged') { title = RED._("sidebar.project.versionControl.stagedChanges")+' : '+entry.file } else { title = RED._("sidebar.project.versionControl.resolveConflicts")+' : '+entry.file } var options = { diff: data.diff, title: title, unmerged: state === 'unmerged', project: activeProject } if (state == 'unstaged') { options.oldRevTitle = entry.indexStatus === " "?RED._("sidebar.project.versionControl.head"):RED._("sidebar.project.versionControl.staged"); options.newRevTitle = RED._("sidebar.project.versionControl.unstaged"); options.oldRev = entry.indexStatus === " "?"@":":0"; options.newRev = "_"; } else if (state === 'staged') { options.oldRevTitle = RED._("sidebar.project.versionControl.head"); options.newRevTitle = RED._("sidebar.project.versionControl.staged"); options.oldRev = "@"; options.newRev = ":0"; } else { options.oldRevTitle = RED._("sidebar.project.versionControl.local"); options.newRevTitle = RED._("sidebar.project.versionControl.remote"); options.commonRev = ":1"; options.oldRev = ":2"; options.newRev = ":3"; options.onresolve = function(resolution) { utils.sendRequest({ url: "projects/"+activeProject.name+"/resolve/"+encodeURIComponent(entry.file), type: "POST", responses: { 0: function(error) { console.log(error); // done(error,null); }, 200: function(data) { refresh(true); }, 400: { 'unexpected_error': function(error) { console.log(error); // done(error,null); } }, } },{resolutions:resolution.resolutions[entry.file]}); } } RED.diff.showUnifiedDiff(options); }, 400: { 'unexpected_error': function(error) { console.log(error); // done(error,null); } } } }) } function createChangeEntry(row, entry, status, state) { row.addClass("sidebar-version-control-change-entry"); var container = $('
'+RED._("sidebar.project.versionControl.showUnstagedChanges")+'
',"error",false,10000000); }, 'git_pull_merge_conflict': function(err) { refresh(true); closeRemoteBox(); }, 'git_connection_failed': function(err) { RED.notify(RED._("sidebar.project.versionControl.connectionFailed")+err.toString(),"warning") }, 'git_pull_unrelated_history': function(error) { var notification = RED.notify(RED._("sidebar.project.versionControl.pullUnrelatedHistory"),{ type: 'error', modal: true, fixed: true, buttons: [ { text: RED._("common.label.cancel"), click: function() { notification.close(); } },{ text: RED._("sidebar.project.versionControl.pullChanges"), click: function() { notification.close(); options.allowUnrelatedHistories = true; pullRemote(options) } } ] }); }, '*': function(error) { utils.reportUnexpectedError(error); } }, } },{}).always(function() { spinner.remove(); }); } $('') .appendTo(row) .click(function(e) { e.preventDefault(); pullRemote({ setUpstream: $("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked') }); }); $('