diff --git a/src/js/git/commands.js b/src/js/git/commands.js index 2633efdd..d66948f2 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -569,6 +569,7 @@ var commandConfig = { sc: /^gr($|\s)/, options: [ '-i', + '--solution-ordering', '--interactive-test', '--aboveAll', '-p', @@ -595,6 +596,7 @@ var commandConfig = { args[0], args[1], { aboveAll: !!commandOptions['--aboveAll'], + initialCommitOrdering: commandOptions['--solution-ordering'] } ); } diff --git a/src/js/git/index.js b/src/js/git/index.js index ed3799e6..b47a81e4 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -2178,12 +2178,43 @@ GitEngine.prototype.rebaseInteractive = function(targetSource, currentLocation, this.animationQueue.start(); }, this)) .done(); + + // If we have a solution provided, set up the GUI to display it by default + var initialCommitOrdering; + if (options.initialCommitOrdering && options.initialCommitOrdering.length > 0) { + var rebaseMap = {}; + _.each(toRebase, function(commit) { + var id = commit.get('id'); + rebaseMap[id] = commit; + }); + + // Verify each chosen commit exists in the list of commits given to the user + var extraCommits = []; + initialCommitOrdering = []; + _.each(options.initialCommitOrdering[0].split(','), function(id) { + if (id in rebaseMap) { + initialCommitOrdering.push(rebaseMap[id]); + } else { + extraCommits.push(id); + } + }); + + if (extraCommits.length > 0) { + throw new GitError({ + msg: intl.todo('Hey those commits dont exist in the set!') + }); + } + } + + // The rebase view expects the commits reversed, so do that here + toRebase.reverse(); var InteractiveRebaseView = require('../views/rebaseView').InteractiveRebaseView; // interactive rebase view will reject or resolve our promise new InteractiveRebaseView({ deferred: deferred, toRebase: toRebase, + initialCommitOrdering: initialCommitOrdering, aboveAll: options.aboveAll }); }; diff --git a/src/js/views/rebaseView.js b/src/js/views/rebaseView.js index fde5f47a..24aec9fc 100644 --- a/src/js/views/rebaseView.js +++ b/src/js/views/rebaseView.js @@ -13,24 +13,54 @@ var InteractiveRebaseView = ContainedBase.extend({ tagName: 'div', template: _.template($('#interactive-rebase-template').html()), - initialize: function(options) { - this.deferred = options.deferred; + createRebaseEntries: function() { this.rebaseMap = {}; this.entryObjMap = {}; - this.options = options; - this.rebaseEntries = new RebaseEntryCollection(); - options.toRebase.reverse(); - _.each(options.toRebase, function(commit) { + + // If we are displaying a solution, we potentially only want to pick certain commits, and reorder + // the ones that are picked. The commits we want to pick and the order are contained in the options.initialCommitOrdering, + // the list of all the commits that are part of the rebase are in options.toRebase + var commitsToUse = this.options.initialCommitOrdering === undefined ? this.options.toRebase + : this.options.initialCommitOrdering; + + _.each(commitsToUse, function(commit) { var id = commit.get('id'); this.rebaseMap[id] = commit; // make basic models for each commit this.entryObjMap[id] = new RebaseEntry({ - id: id + id: id, + pick: true }); this.rebaseEntries.add(this.entryObjMap[id]); }, this); + + // If we are using the initialCommitOrdering, we might not have picked all of the commits, + // but we would still want to see the other unpicked ones. Just show them as unpicked by default + if (this.options.initialCommitOrdering !== undefined) { + _.each(this.options.toRebase, function(commit) { + var id = commit.get('id'); + + if (!(id in this.rebaseMap)) { + this.rebaseMap[id] = commit; + + // make basic models for each commit + this.entryObjMap[id] = new RebaseEntry({ + id: id, + pick: false + }); + } + this.rebaseEntries.add(this.entryObjMap[id]); + }, this); + } + }, + + initialize: function(options) { + this.deferred = options.deferred; + this.options = options; + + this.createRebaseEntries(); this.container = new ModalTerminal({ title: 'Interactive Rebase' @@ -170,6 +200,7 @@ var RebaseEntryView = Backbone.View.extend({ // hacky :( who would have known jquery barfs on ids with %'s and quotes this.listEntry = this.$el.children(':last'); + this.listEntry.toggleClass('notPicked', !this.model.get('pick')); this.listEntry.delegate('#toggleButton', 'click', _.bind(function() { this.toggle(); diff --git a/src/levels/mixed/jugglingCommits.js b/src/levels/mixed/jugglingCommits.js index 657bc9df..15d0ec50 100644 --- a/src/levels/mixed/jugglingCommits.js +++ b/src/levels/mixed/jugglingCommits.js @@ -15,7 +15,7 @@ exports.level = { ] }, "goalTreeString": "%7B%22branches%22%3A%7B%22master%22%3A%7B%22target%22%3A%22C3%27%27%22%2C%22id%22%3A%22master%22%7D%2C%22newImage%22%3A%7B%22target%22%3A%22C2%22%2C%22id%22%3A%22newImage%22%7D%2C%22caption%22%3A%7B%22target%22%3A%22C3%27%27%22%2C%22id%22%3A%22caption%22%7D%7D%2C%22commits%22%3A%7B%22C0%22%3A%7B%22parents%22%3A%5B%5D%2C%22id%22%3A%22C0%22%2C%22rootCommit%22%3Atrue%7D%2C%22C1%22%3A%7B%22parents%22%3A%5B%22C0%22%5D%2C%22id%22%3A%22C1%22%7D%2C%22C2%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%22%7D%2C%22C3%22%3A%7B%22parents%22%3A%5B%22C2%22%5D%2C%22id%22%3A%22C3%22%7D%2C%22C3%27%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C3%27%22%7D%2C%22C2%27%22%3A%7B%22parents%22%3A%5B%22C3%27%22%5D%2C%22id%22%3A%22C2%27%22%7D%2C%22C2%27%27%22%3A%7B%22parents%22%3A%5B%22C3%27%22%5D%2C%22id%22%3A%22C2%27%27%22%7D%2C%22C2%27%27%27%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%27%27%27%22%7D%2C%22C3%27%27%22%3A%7B%22parents%22%3A%5B%22C2%27%27%27%22%5D%2C%22id%22%3A%22C3%27%27%22%7D%7D%2C%22HEAD%22%3A%7B%22target%22%3A%22master%22%2C%22id%22%3A%22HEAD%22%7D%7D", - "solutionCommand": "git rebase -i HEAD~2;git commit --amend;git rebase -i HEAD~2;git rebase caption master", + "solutionCommand": "git rebase -i HEAD~2 --solution-ordering C3,C2;git commit --amend;git rebase -i HEAD~2 --solution-ordering C2'',C3';git rebase caption master", "startTree": "{\"branches\":{\"master\":{\"target\":\"C1\",\"id\":\"master\"},\"newImage\":{\"target\":\"C2\",\"id\":\"newImage\"},\"caption\":{\"target\":\"C3\",\"id\":\"caption\"}},\"commits\":{\"C0\":{\"parents\":[],\"id\":\"C0\",\"rootCommit\":true},\"C1\":{\"parents\":[\"C0\"],\"id\":\"C1\"},\"C2\":{\"parents\":[\"C1\"],\"id\":\"C2\"},\"C3\":{\"parents\":[\"C2\"],\"id\":\"C3\"}},\"HEAD\":{\"target\":\"caption\",\"id\":\"HEAD\"}}", "name": { "ko": "커밋들 갖고 놀기", diff --git a/src/levels/rampup/interactiveRebase.js b/src/levels/rampup/interactiveRebase.js index 0600d360..1419a1e2 100644 --- a/src/levels/rampup/interactiveRebase.js +++ b/src/levels/rampup/interactiveRebase.js @@ -1,6 +1,6 @@ exports.level = { "goalTreeString": "%7B%22branches%22%3A%7B%22master%22%3A%7B%22target%22%3A%22C4%27%22%2C%22id%22%3A%22master%22%7D%2C%22overHere%22%3A%7B%22target%22%3A%22C1%22%2C%22id%22%3A%22overHere%22%7D%7D%2C%22commits%22%3A%7B%22C0%22%3A%7B%22parents%22%3A%5B%5D%2C%22id%22%3A%22C0%22%2C%22rootCommit%22%3Atrue%7D%2C%22C1%22%3A%7B%22parents%22%3A%5B%22C0%22%5D%2C%22id%22%3A%22C1%22%7D%2C%22C2%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%22%7D%2C%22C3%22%3A%7B%22parents%22%3A%5B%22C2%22%5D%2C%22id%22%3A%22C3%22%7D%2C%22C4%22%3A%7B%22parents%22%3A%5B%22C3%22%5D%2C%22id%22%3A%22C4%22%7D%2C%22C5%22%3A%7B%22parents%22%3A%5B%22C4%22%5D%2C%22id%22%3A%22C5%22%7D%2C%22C3%27%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C3%27%22%7D%2C%22C5%27%22%3A%7B%22parents%22%3A%5B%22C3%27%22%5D%2C%22id%22%3A%22C5%27%22%7D%2C%22C4%27%22%3A%7B%22parents%22%3A%5B%22C5%27%22%5D%2C%22id%22%3A%22C4%27%22%7D%7D%2C%22HEAD%22%3A%7B%22target%22%3A%22master%22%2C%22id%22%3A%22HEAD%22%7D%7D", - "solutionCommand": "git rebase -i overHere", + "solutionCommand": "git rebase -i overHere --solution-ordering C3,C5,C4", "compareOnlyMasterHashAgnostic": true, "disabledMap": { "git cherry-pick": true