Skip to content

Commit

Permalink
feat(rebase_onto): add level (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
janis-vitols authored and Gazler committed Nov 13, 2016
1 parent fd38c65 commit c543aef
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
45 changes: 45 additions & 0 deletions levels/rebase_onto.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/githug/level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion lib/githug/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Githug
VERSION = "0.4.8"
VERSION = "0.4.9"
end
4 changes: 2 additions & 2 deletions spec/githug/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions spec/githug_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c543aef

Please sign in to comment.