From c543aefad5c8bf148a0cafe6b1d780ffcd0f6b81 Mon Sep 17 00:00:00 2001 From: Janis Vitols Date: Sun, 13 Nov 2016 21:05:34 +0200 Subject: [PATCH] feat(rebase_onto): add level (#221) --- levels/rebase_onto.rb | 45 +++++++++++++++++++++++++++++++++++++++++ lib/githug/level.rb | 2 +- lib/githug/version.rb | 2 +- spec/githug/cli_spec.rb | 4 ++-- spec/githug_spec.rb | 6 ++++++ 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 levels/rebase_onto.rb diff --git a/levels/rebase_onto.rb b/levels/rebase_onto.rb new file mode 100644 index 00000000..e5043ef2 --- /dev/null +++ b/levels/rebase_onto.rb @@ -0,0 +1,45 @@ +difficulty 2 + +description "You have created your branch from `wrong_branch` and already made some commits, \ +and you realise that you needed to create your branch from `master`. \ +Rebase your commits onto `master` branch so that you don't have `wrong_branch` commits." + +setup do + readme_file = "README.md" + authors_file = "authors.md" + + repo.init + FileUtils.touch(authors_file) + File.open(authors_file, "w") { |f| f << "https://github.com/janis-vitols\n" } + repo.add(authors_file) + repo.commit_all("Create authors file") + + repo.git.native :checkout, { "b" => true }, "wrong_branch" + File.open(authors_file, "w") { |f| f << "None\n" } + repo.add(authors_file) + repo.commit_all("Wrong changes") + + repo.git.native :checkout, { "b" => true }, "readme-update" + FileUtils.touch(readme_file) + File.open(readme_file, "a") { |f| f << "# SuperApp\n" } + repo.add(readme_file) + repo.commit_all("Add app name in readme") + File.open(readme_file, "a") { |f| f << "## About\n" } + repo.add(readme_file) + repo.commit_all("Add `About` header in readme") + File.open(readme_file, "a") { |f| f << "## Install\n" } + repo.add(readme_file) + repo.commit_all("Add `Install` header in readme") +end + +solution do + repo.commits("readme-update").each { |commit| return false if commit.message == "Wrong changes" } + return false unless repo.commits("readme-update").length == 4 + return false unless File.readlines("authors.md").include?("https://github.com/janis-vitols\n") + + true +end + +hint do + puts "You want to research the `git rebase` commands `--onto` argument" +end diff --git a/lib/githug/level.rb b/lib/githug/level.rb index d0b46fe3..051d1738 100644 --- a/lib/githug/level.rb +++ b/lib/githug/level.rb @@ -9,7 +9,7 @@ class Level "commit_in_future", "reset", "reset_soft", "checkout_file", "remote", "remote_url", "pull", "remote_add", "push", "diff", "blame", "branch", "checkout", "checkout_tag", "checkout_tag_over_branch", "branch_at", - "delete_branch", "push_branch", "merge", "fetch", "rebase", "repack", "cherry-pick", + "delete_branch", "push_branch", "merge", "fetch", "rebase", "rebase_onto", "repack", "cherry-pick", "grep", "rename_commit", "squash", "merge_squash", "reorder", "bisect", "stage_lines", "find_old_branch", "revert", "restore", "conflict", "submodule","contribute"] diff --git a/lib/githug/version.rb b/lib/githug/version.rb index a18c4992..db82e905 100644 --- a/lib/githug/version.rb +++ b/lib/githug/version.rb @@ -1,3 +1,3 @@ module Githug - VERSION = "0.4.8" + VERSION = "0.4.9" end diff --git a/spec/githug/cli_spec.rb b/spec/githug/cli_spec.rb index d3c26829..791e2902 100644 --- a/spec/githug/cli_spec.rb +++ b/spec/githug/cli_spec.rb @@ -103,8 +103,8 @@ level.should_receive(:full_description) profile = mock Githug::Profile.stub(:load).and_return(profile) - profile.should_receive(:set_level).with("squash") - Githug::Level.should_receive(:load).with("squash").and_return(level) + profile.should_receive(:set_level).with("rename_commit") + Githug::Level.should_receive(:load).with("rename_commit").and_return(level) Githug::UI.should_receive(:word_box).with("Githug") Githug::UI.should_receive(:puts).with("resetting level") subject.reset("45") diff --git a/spec/githug_spec.rb b/spec/githug_spec.rb index ad5a4435..988892b9 100644 --- a/spec/githug_spec.rb +++ b/spec/githug_spec.rb @@ -237,6 +237,12 @@ def skip_level `githug`.should be_solved end + it "solves the rebase_onto level" do + `git checkout readme-update` + `git rebase --onto master wrong_branch readme-update` + `githug`.should be_solved + end + it "solves the repack level" do `git repack -d` `githug`.should be_solved