diff options
| author | Gubolin <gubolin@fantasymail.de> | 2014-09-12 19:54:58 +0200 |
|---|---|---|
| committer | Gubolin <gubolin@fantasymail.de> | 2014-09-12 19:54:58 +0200 |
| commit | 0772e7d750532a91fc89c9bb131229a7fb989b91 (patch) | |
| tree | 0169c343a399cb2d3d7faa84518d798fe4b50f16 | |
| parent | 39a50e190ac39560564507399d26fe7c141de86f (diff) | |
| download | snap-0772e7d750532a91fc89c9bb131229a7fb989b91.tar.gz snap-0772e7d750532a91fc89c9bb131229a7fb989b91.zip | |
support merging [WIP]
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | github.js | 71 | ||||
| -rw-r--r-- | gui.js | 18 | ||||
| -rwxr-xr-x | snap.html | 1 |
4 files changed, 68 insertions, 25 deletions
diff --git a/.gitmodules b/.gitmodules index 417778f..510117d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "vkBeautify"] path = vkBeautify url = https://github.com/vkiryukhin/vkBeautify +[submodule "diff-merge"] + path = diff-merge + url = https://github.com/nighca/diff-merge @@ -57,7 +57,8 @@ GitHubBackend.prototype.getProject = function ( userName, projectName, callBack, - errorCall + errorCall, + commitSha ) { var myself = this; @@ -67,12 +68,19 @@ GitHubBackend.prototype.getProject = function ( var repo = myself.gh.getRepo(userName, projectName); var branch = repo.getBranch(); // master (default) - - branch.read('snap.xml', false).then( - function (sourceContent) { - callBack.call( - null, - sourceContent.content + branch.getCommits({}).then( + function (commits) { + branch.read('snap.xml', false).then( + function (sourceContent) { + callBack.call( + null, + sourceContent.content, + commits[0].sha + ); + }, + function (error) { + errorCall.call(this, error, 'GitHub'); + } ); }, function (error) { @@ -100,7 +108,7 @@ GitHubBackend.prototype.login = function ( me = myself.gh.getUser(); if (me !== null) { me.getInfo().then( - function(info) { + function() { myself.username = username; myself.password = password; @@ -121,7 +129,7 @@ GitHubBackend.prototype.login = function ( } }; -GitHubBackend.prototype.saveProject = function (commitMessage, ide, callBack, errorCall) { +GitHubBackend.prototype.saveProject = function (commitMessage, parentCommitSha, lastCommit, ide, callBack, errorCall) { var myself = this, data; var pdata, media; @@ -162,27 +170,46 @@ GitHubBackend.prototype.saveProject = function (commitMessage, ide, callBack, er } }); - function pushChanges () { + pushChanges = function () { if (myself.gh !== null) { var repo = myself.gh.getRepo(myself.username, ide.projectName); var branch = repo.getBranch(); // master (default) var message = commitMessage; - var contents = { - 'snap.xml': data, - 'README.md': ide.projectNotes + writeChanges = function (code, pcSha) { + if (pcSha !== parentCommitSha && data !== code) { + var compareResult = window.diff.compare(lastCommit, data, '\n'); // get diff from last push + data = window.diff.merge(code, compareResult); // apply it to the latest code + console.log(data); + } + + var contents = { + 'snap.xml': data, + 'README.md': ide.projectNotes + }; + + branch.writeMany(contents, message, pcSha).then( + function () { + callBack.call(); + }, + function (error) { + errorCall.call(this, error, 'GitHub'); + } + ); }; - branch.writeMany(contents, message).then( - function () { - callBack.call(); - }, - function (error) { - errorCall.call(this, error, 'GitHub'); - } - ); + if (parentCommitSha !== null) { // repo was just created + myself.getProject(myself.username, ide.projectName, + writeChanges, + function (error) { + errorCall.call(this, error, 'GitHub'); + } + ); + } else { + writeChanges(data, parentCommitSha); + } } - } + }; if (exists === false){ myself.gh.getUser().createRepo(repoName, { // these should be discussed @@ -221,6 +221,8 @@ IDE_Morph.prototype.init = function (isAutoFill) { this.stageRatio = 1; // for IDE animations, e.g. when zooming this.loadNewProject = false; // flag when starting up translated + this.parentCommitSha = null; // for GitHub + this.lastCommit = null; // for GitHub this.shield = null; // initialize inherited properties: @@ -401,13 +403,15 @@ IDE_Morph.prototype.openIn = function (world) { GitHub.getProject( dict.Username, dict.projectName, - function (code) { + function (code, pcSha) { var msg; myself.nextSteps([ function () { msg = myself.showMessage('Opening GitHub project...'); }, function () { + myself.parentCommitSha = pcSha; + myself.lastCommit = code; myself.rawOpenCloudDataString(code); myself.hasChangedMedia = true; }, @@ -3935,13 +3939,17 @@ IDE_Morph.prototype.saveProjectToGitHub = function (name, commitMessage) { this.setProjectName(name); GitHub.saveProject( commitMessage, + this.parentCommitSha, + this.lastCommit, this, function () { GitHub.getProject( GitHub.username, name, - function (code) { + function (code, pcSha) { myself.source = 'github'; + myself.parentCommitSha = pcSha; + myself.lastCommit = code; myself.droppedText(code); }, myself.githubError() @@ -5072,8 +5080,10 @@ ProjectDialogMorph.prototype.rawOpenGitHubProject = function (proj, user) { GitHub.getProject( user, proj.ProjectName, - function (code) { + function (code, pcSha) { myself.ide.source = 'github'; + myself.ide.parentCommitSha = pcSha; + myself.ide.lastCommit = code; myself.ide.droppedText(code); }, myself.ide.githubError() @@ -5171,6 +5181,8 @@ ProjectDialogMorph.prototype.saveGitHubProject = function () { this.ide.showMessage('Committing project\nto GitHub...'); GitHub.saveProject( null, + this.ide.parentCommitSha, + this.ide.lastCommit, this.ide, function () { myself.ide.source = 'github'; @@ -22,6 +22,7 @@ <script type="text/javascript" src="github.js"></script> <script type="text/javascript" src="sha512.js"></script> <script type="text/javascript" src="vkBeautify/vkbeautify.js"></script> + <script type="text/javascript" src="diff-merge/dist/diff.js"></script> <script type="text/javascript"> var world; window.onload = function () { |
