level 2 and 3

This commit is contained in:
Peter Cottle 2013-01-12 01:02:48 -08:00
parent 1fae2f18bc
commit 9249ef0604
6 changed files with 211 additions and 25 deletions

View file

@ -6811,7 +6811,7 @@ var Level = Sandbox.extend({
// ok so lets see if they solved it...
var current = this.mainVis.gitEngine.exportTree();
var solved = this.treeCompare.compareAllBranchesWithinTrees(current, this.level.goalTreeString);
var solved = this.treeCompare.compareAllBranchesWithinTreesAndHEAD(current, this.level.goalTreeString);
if (!solved) {
defer.resolve();
@ -9409,6 +9409,13 @@ function TreeCompare() {
}
TreeCompare.prototype.compareAllBranchesWithinTreesAndHEAD = function(treeA, treeB) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
return treeA.HEAD.target == treeB.HEAD.target && this.compareAllBranchesWithinTrees(treeA, treeB);
};
TreeCompare.prototype.compareAllBranchesWithinTrees = function(treeA, treeB) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
@ -9435,12 +9442,7 @@ TreeCompare.prototype.compareBranchesWithinTrees = function(treeA, treeB, branch
return result;
};
TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchName) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
this.reduceTreeFields([treeA, treeB]);
TreeCompare.prototype.getRecurseCompare = function(treeA, treeB) {
// we need a recursive comparison function to bubble up the branch
var recurseCompare = function(commitA, commitB) {
// this is the short-circuit base case
@ -9462,7 +9464,15 @@ TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchNa
// if each of our children recursively are equal, we are good
return result;
};
return recurseCompare;
};
TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchName) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
this.reduceTreeFields([treeA, treeB]);
var recurseCompare = this.getRecurseCompare(treeA, treeB);
var branchA = treeA.branches[branchName];
var branchB = treeB.branches[branchName];
@ -16893,7 +16903,7 @@ require.define("/src/levels/intro/2.js",function(require,module,exports,__dirnam
"make a new branch named `bugFix` and switch to that branch"
]
}
},
}
]
}
};
@ -20034,6 +20044,13 @@ function TreeCompare() {
}
TreeCompare.prototype.compareAllBranchesWithinTreesAndHEAD = function(treeA, treeB) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
return treeA.HEAD.target == treeB.HEAD.target && this.compareAllBranchesWithinTrees(treeA, treeB);
};
TreeCompare.prototype.compareAllBranchesWithinTrees = function(treeA, treeB) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
@ -20060,12 +20077,7 @@ TreeCompare.prototype.compareBranchesWithinTrees = function(treeA, treeB, branch
return result;
};
TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchName) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
this.reduceTreeFields([treeA, treeB]);
TreeCompare.prototype.getRecurseCompare = function(treeA, treeB) {
// we need a recursive comparison function to bubble up the branch
var recurseCompare = function(commitA, commitB) {
// this is the short-circuit base case
@ -20087,7 +20099,15 @@ TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchNa
// if each of our children recursively are equal, we are good
return result;
};
return recurseCompare;
};
TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchName) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
this.reduceTreeFields([treeA, treeB]);
var recurseCompare = this.getRecurseCompare(treeA, treeB);
var branchA = treeA.branches[branchName];
var branchB = treeB.branches[branchName];
@ -21027,7 +21047,7 @@ var Level = Sandbox.extend({
// ok so lets see if they solved it...
var current = this.mainVis.gitEngine.exportTree();
var solved = this.treeCompare.compareAllBranchesWithinTrees(current, this.level.goalTreeString);
var solved = this.treeCompare.compareAllBranchesWithinTreesAndHEAD(current, this.level.goalTreeString);
if (!solved) {
defer.resolve();
@ -27445,13 +27465,91 @@ require.define("/src/levels/intro/2.js",function(require,module,exports,__dirnam
"make a new branch named `bugFix` and switch to that branch"
]
}
},
}
]
}
};
});
require("/src/levels/intro/2.js");
require.define("/src/levels/intro/3.js",function(require,module,exports,__dirname,__filename,process,global){exports.level = {
"goalTreeString": "{\"branches\":{\"master\":{\"target\":\"C4\",\"id\":\"master\"},\"bugFix\":{\"target\":\"C2\",\"id\":\"bugFix\"}},\"commits\":{\"C0\":{\"parents\":[],\"id\":\"C0\",\"rootCommit\":true},\"C1\":{\"parents\":[\"C0\"],\"id\":\"C1\"},\"C2\":{\"parents\":[\"C1\"],\"id\":\"C2\"},\"C3\":{\"parents\":[\"C1\"],\"id\":\"C3\"},\"C4\":{\"parents\":[\"C2\",\"C3\"],\"id\":\"C4\"}},\"HEAD\":{\"target\":\"master\",\"id\":\"HEAD\"}}",
"solutionCommand": "git checkout -b bugFix;git commit;git checkout master;git commit;git merge bugFix",
"name": "Merging in Git",
"hint": "Remember to commit in the order specified (bugFix before master)",
"startDialog": {
"childViews": [
{
"type": "ModalAlert",
"options": {
"markdowns": [
"## Branches and Merging",
"",
"Great! We now know how to commit and branch. Now we need to learn some kind of way of combining the work from two different branches together. This will allow us to branch off, develop a new feature, and then branch it back in.",
"",
"The first method to combine work that we will examine is `git merge`. Merging in Git creates a special commit that has two unique parents. A commit with two parents essentially means \"I want to include all the work from this parent over here and this one over here, *and* the set of all their parents.\"",
"",
"It's easier with visuals, let's check it out in the next view"
]
}
},
{
"type": "GitDemonstrationView",
"options": {
"beforeMarkdowns": [
"Here we have two branches; each has one commit that's unique. This means that neither branch includes the entire set of \"work\" in the repository that we have done. Let's fix that with merge.",
"",
"We will `merge` the branch `bugFix` into `master`"
],
"afterMarkdowns": [
"Woah! See that? FIrst of all, `master` now points to a commit that has two parents. If you follow the arrows upstream from `master`, you will hit every commit along the way to the root. This means that `master` contains all the work in the repository now.",
"",
"Also, see how the colors of the commits changed? To help with learning, I have included some color coordination. Each branch has a unique color. Each commit turns a color that is the blended combination of all the branches that contain that color.",
"",
"So here we see that the `master` branch color is blended into all the commits, but the `bugFix` color is not. Let's fix that..."
],
"command": "git merge bugFix master",
"beforeCommand": "git checkout -b bugFix; git commit; git checkout master; git commit"
}
},
{
"type": "GitDemonstrationView",
"options": {
"beforeMarkdowns": [
"Let's merge `master` into `bugFix`:"
],
"afterMarkdowns": [
"Since `bugFix` was downstream of `master`, git didn't have to do any work; it simply just moved `bugFix` to the same commit `master` was attached to.",
"",
"Now all the commits are the same color, which means each branch contains all the work in the repository! Woohoo"
],
"command": "git merge master bugFix",
"beforeCommand": "git checkout -b bugFix; git commit; git checkout master; git commit; git merge bugFix master"
}
},
{
"type": "ModalAlert",
"options": {
"markdowns": [
"To complete this level, do the following steps:",
"",
"* Make a new branch called `bugFix`",
"* Commit once",
"* Go back to `master` with `git checkout`",
"* Commit another time",
"* Merge the branch `bugFix` into `master` with `git merge`",
"",
"*Remember, you can always re-display this dialog with \"help level\"!*"
]
}
}
]
}
};
});
require("/src/levels/intro/3.js");
require.define("/src/levels/rebase/1.js",function(require,module,exports,__dirname,__filename,process,global){exports.level = {
name: 'Introduction #1',
description: 'Oh wut?',

View file

@ -5,6 +5,13 @@ function TreeCompare() {
}
TreeCompare.prototype.compareAllBranchesWithinTreesAndHEAD = function(treeA, treeB) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
return treeA.HEAD.target == treeB.HEAD.target && this.compareAllBranchesWithinTrees(treeA, treeB);
};
TreeCompare.prototype.compareAllBranchesWithinTrees = function(treeA, treeB) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
@ -31,12 +38,7 @@ TreeCompare.prototype.compareBranchesWithinTrees = function(treeA, treeB, branch
return result;
};
TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchName) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
this.reduceTreeFields([treeA, treeB]);
TreeCompare.prototype.getRecurseCompare = function(treeA, treeB) {
// we need a recursive comparison function to bubble up the branch
var recurseCompare = function(commitA, commitB) {
// this is the short-circuit base case
@ -58,7 +60,15 @@ TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchNa
// if each of our children recursively are equal, we are good
return result;
};
return recurseCompare;
};
TreeCompare.prototype.compareBranchWithinTrees = function(treeA, treeB, branchName) {
treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB);
this.reduceTreeFields([treeA, treeB]);
var recurseCompare = this.getRecurseCompare(treeA, treeB);
var branchA = treeA.branches[branchName];
var branchB = treeB.branches[branchName];

View file

@ -282,7 +282,7 @@ var Level = Sandbox.extend({
// ok so lets see if they solved it...
var current = this.mainVis.gitEngine.exportTree();
var solved = this.treeCompare.compareAllBranchesWithinTrees(current, this.level.goalTreeString);
var solved = this.treeCompare.compareAllBranchesWithinTreesAndHEAD(current, this.level.goalTreeString);
if (!solved) {
defer.resolve();

View file

@ -78,7 +78,7 @@ exports.level = {
"make a new branch named `bugFix` and switch to that branch"
]
}
},
}
]
}
};

74
src/levels/intro/3.js Normal file
View file

@ -0,0 +1,74 @@
exports.level = {
"goalTreeString": "{\"branches\":{\"master\":{\"target\":\"C4\",\"id\":\"master\"},\"bugFix\":{\"target\":\"C2\",\"id\":\"bugFix\"}},\"commits\":{\"C0\":{\"parents\":[],\"id\":\"C0\",\"rootCommit\":true},\"C1\":{\"parents\":[\"C0\"],\"id\":\"C1\"},\"C2\":{\"parents\":[\"C1\"],\"id\":\"C2\"},\"C3\":{\"parents\":[\"C1\"],\"id\":\"C3\"},\"C4\":{\"parents\":[\"C2\",\"C3\"],\"id\":\"C4\"}},\"HEAD\":{\"target\":\"master\",\"id\":\"HEAD\"}}",
"solutionCommand": "git checkout -b bugFix;git commit;git checkout master;git commit;git merge bugFix",
"name": "Merging in Git",
"hint": "Remember to commit in the order specified (bugFix before master)",
"startDialog": {
"childViews": [
{
"type": "ModalAlert",
"options": {
"markdowns": [
"## Branches and Merging",
"",
"Great! We now know how to commit and branch. Now we need to learn some kind of way of combining the work from two different branches together. This will allow us to branch off, develop a new feature, and then branch it back in.",
"",
"The first method to combine work that we will examine is `git merge`. Merging in Git creates a special commit that has two unique parents. A commit with two parents essentially means \"I want to include all the work from this parent over here and this one over here, *and* the set of all their parents.\"",
"",
"It's easier with visuals, let's check it out in the next view"
]
}
},
{
"type": "GitDemonstrationView",
"options": {
"beforeMarkdowns": [
"Here we have two branches; each has one commit that's unique. This means that neither branch includes the entire set of \"work\" in the repository that we have done. Let's fix that with merge.",
"",
"We will `merge` the branch `bugFix` into `master`"
],
"afterMarkdowns": [
"Woah! See that? FIrst of all, `master` now points to a commit that has two parents. If you follow the arrows upstream from `master`, you will hit every commit along the way to the root. This means that `master` contains all the work in the repository now.",
"",
"Also, see how the colors of the commits changed? To help with learning, I have included some color coordination. Each branch has a unique color. Each commit turns a color that is the blended combination of all the branches that contain that color.",
"",
"So here we see that the `master` branch color is blended into all the commits, but the `bugFix` color is not. Let's fix that..."
],
"command": "git merge bugFix master",
"beforeCommand": "git checkout -b bugFix; git commit; git checkout master; git commit"
}
},
{
"type": "GitDemonstrationView",
"options": {
"beforeMarkdowns": [
"Let's merge `master` into `bugFix`:"
],
"afterMarkdowns": [
"Since `bugFix` was downstream of `master`, git didn't have to do any work; it simply just moved `bugFix` to the same commit `master` was attached to.",
"",
"Now all the commits are the same color, which means each branch contains all the work in the repository! Woohoo"
],
"command": "git merge master bugFix",
"beforeCommand": "git checkout -b bugFix; git commit; git checkout master; git commit; git merge bugFix master"
}
},
{
"type": "ModalAlert",
"options": {
"markdowns": [
"To complete this level, do the following steps:",
"",
"* Make a new branch called `bugFix`",
"* Commit once",
"* Go back to `master` with `git checkout`",
"* Commit another time",
"* Merge the branch `bugFix` into `master` with `git merge`",
"",
"*Remember, you can always re-display this dialog with \"help level\"!*"
]
}
}
]
}
};

View file

@ -26,7 +26,11 @@ code {
p {
word-wrap: break-word;
line-height: 26px;
}
div.modalTerminal p {
line-height: 24px;
margin: 1.5em 0;
}
.textAlignCenter {