githug 0.0.10 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -6
- data/levels/checkout_file.rb +25 -0
- data/levels/commit_ammend.rb +18 -0
- data/levels/remote.rb +16 -0
- data/levels/remote_add.rb +16 -0
- data/levels/remote_url.rb +17 -0
- data/levels/reset.rb +22 -0
- data/levels/rm_cached.rb +4 -3
- data/lib/githug/game.rb +7 -0
- data/lib/githug/level.rb +2 -1
- data/lib/githug/profile.rb +3 -0
- data/lib/githug/version.rb +1 -1
- data/spec/githug/game_spec.rb +31 -11
- data/spec/githug/profile_spec.rb +8 -2
- metadata +8 -2
data/README.md
CHANGED
@@ -23,13 +23,19 @@ Githug has 3 commands:
|
|
23
23
|
|
24
24
|
Get yourself on the [contributors list](https://github.com/Gazler/githug/contributors) by doing the following:
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
* Fork the repository
|
27
|
+
* Make a level in the levels directory (covered below)
|
28
|
+
* Add your level to the LEVELS array inside `lib/githug/level.rb` in a position that makes sense (the "commit" level after the "add" and "init" levels for example)
|
29
|
+
* Make sure your level works (covered below)
|
30
|
+
* Submit a pull request
|
31
31
|
|
32
|
-
##
|
32
|
+
##Todo List
|
33
|
+
|
34
|
+
* A better way of returning from the solution block
|
35
|
+
* A follow up to the level, more information on a specific command, etc.
|
36
|
+
* More levels!
|
37
|
+
|
38
|
+
##Writing Levels
|
33
39
|
|
34
40
|
Githug has a DSL for writing levels
|
35
41
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
difficulty 3
|
2
|
+
|
3
|
+
description "A file has been modified, but you don't want to keep the files. Checkout the `config.rb` file from the last commit."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
repo.init
|
7
|
+
File.open("config.rb", "w") do |file|
|
8
|
+
file.puts("This is the initial config file")
|
9
|
+
end
|
10
|
+
|
11
|
+
repo.add("config.rb")
|
12
|
+
repo.commit_all("Added initial config file")
|
13
|
+
|
14
|
+
File.open("config.rb", "a") do |file|
|
15
|
+
file.puts("These are changed you don't want to keep!")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
solution do
|
20
|
+
repo.status.files["config.rb"].type != "M" && repo.commits.length == 2
|
21
|
+
end
|
22
|
+
|
23
|
+
hint do
|
24
|
+
puts "You will need to do some research on the checkout command for this one."
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
difficulty 2
|
2
|
+
description "The README file has been committed, but it looks like the file `forgotten_file.rb` was missing from the commit. Add the file and ammend your previous commit to include it."
|
3
|
+
|
4
|
+
setup do
|
5
|
+
repo.init
|
6
|
+
FileUtils.touch("README")
|
7
|
+
repo.add("README")
|
8
|
+
repo.commit_all("Initial commit")
|
9
|
+
FileUtils.touch("forgotten_file.rb")
|
10
|
+
end
|
11
|
+
|
12
|
+
solution do
|
13
|
+
repo.commits.length == 2 && repo.commits.first.stats.files.length == 2
|
14
|
+
end
|
15
|
+
|
16
|
+
hint do
|
17
|
+
puts "Running `git commit --help` will display the man page and possible flags."
|
18
|
+
end
|
data/levels/remote.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
difficulty 2
|
2
|
+
|
3
|
+
description "This projects has a remote repository. Identify it."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
repo.init
|
7
|
+
repo.remote_add("my_remote_repo", "https://github.com/Gazler/githug")
|
8
|
+
end
|
9
|
+
|
10
|
+
solution do
|
11
|
+
"my_remote_repo" == request("What is the name of the remote repository?")
|
12
|
+
end
|
13
|
+
|
14
|
+
hint do
|
15
|
+
puts "You are looking for a remote. You can run `git` for a list of commands"
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
difficulty 2
|
2
|
+
|
3
|
+
description "Add a remote repository called `origin` with the url `https://github.com/githug/githug`"
|
4
|
+
|
5
|
+
setup do
|
6
|
+
repo.init
|
7
|
+
end
|
8
|
+
|
9
|
+
solution do
|
10
|
+
result = `git remote -v`
|
11
|
+
result.include?("https://github.com/githug/githug")
|
12
|
+
end
|
13
|
+
|
14
|
+
hint do
|
15
|
+
puts "You can run `git remote --help` for the man pages"
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
difficulty 2
|
2
|
+
|
3
|
+
description "The remote repositories have a url associated to them. Please enter the url of remote_location"
|
4
|
+
|
5
|
+
setup do
|
6
|
+
repo.init
|
7
|
+
repo.remote_add("my_remote_repo", "https://github.com/Gazler/githug")
|
8
|
+
repo.remote_add("remote_location", "https://github.com/githug/not_a_repo")
|
9
|
+
end
|
10
|
+
|
11
|
+
solution do
|
12
|
+
"https://github.com/githug/not_a_repo" == request("What is the url of the remote repository?")
|
13
|
+
end
|
14
|
+
|
15
|
+
hint do
|
16
|
+
puts "You can run `git remote --help` for the man pages"
|
17
|
+
end
|
data/levels/reset.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
difficulty 2
|
2
|
+
description "There are two files to be committed. The goal was to add each file as a separate commit, however both were added by accident. Unstage the file `to_commit_second` using the reset command"
|
3
|
+
|
4
|
+
setup do
|
5
|
+
repo.init
|
6
|
+
FileUtils.touch("README")
|
7
|
+
repo.add("README")
|
8
|
+
repo.commit_all("Initial commit")
|
9
|
+
FileUtils.touch("to_commit_first.rb")
|
10
|
+
FileUtils.touch("to_commit_second.rb")
|
11
|
+
repo.add(".")
|
12
|
+
end
|
13
|
+
|
14
|
+
solution do
|
15
|
+
return false unless (repo.status.files["to_commit_second.rb"].nil? || repo.status.files["to_commit_second.rb"].stage.nil?) && File.exists?("to_commit_second.rb")
|
16
|
+
return false if (repo.status.files["to_commit_first.rb"].nil? || repo.status.files["to_commit_first.rb"].stage.nil?)
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
hint do
|
21
|
+
puts "You can get some useful information for git status, it will tell you the command you need to run"
|
22
|
+
end
|
data/levels/rm_cached.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
difficulty 2
|
2
2
|
|
3
|
-
description "A file has accidentally been added to your staging area, find out which file and remove it from the staging area. *NOTE* Do not remove the file system, only from git."
|
3
|
+
description "A file (deleteme.rb) has accidentally been added to your staging area, find out which file and remove it from the staging area. *NOTE* Do not remove the file system, only from git."
|
4
4
|
|
5
5
|
setup do
|
6
|
-
repo.init
|
7
|
-
|
6
|
+
repo.init(false)
|
7
|
+
FileUtils.touch("deleteme.rb")
|
8
|
+
repo.add(".gitignore")
|
8
9
|
repo.add("deleteme.rb")
|
9
10
|
end
|
10
11
|
|
data/lib/githug/game.rb
CHANGED
@@ -21,6 +21,13 @@ module Githug
|
|
21
21
|
level_bump
|
22
22
|
else
|
23
23
|
UI.error "Sorry, this solution is not quite right!"
|
24
|
+
profile.current_attempts += 1
|
25
|
+
profile.save
|
26
|
+
|
27
|
+
if (profile.current_attempts > 2 && profile.current_attempts % 3 == 0)
|
28
|
+
UI.error "Don't forget you can type `githug hint` for a hint and `githug reset` to reset the current level"
|
29
|
+
end
|
30
|
+
|
24
31
|
UI.puts level.full_description
|
25
32
|
end
|
26
33
|
end
|
data/lib/githug/level.rb
CHANGED
@@ -4,7 +4,8 @@ module Githug
|
|
4
4
|
|
5
5
|
LEVELS = [nil, "init", "add", "commit", "config", "clone",
|
6
6
|
"clone_to_folder", "ignore", "status", "rm", "rm_cached", "log",
|
7
|
-
"
|
7
|
+
"commit_ammend", "reset", "checkout_file", "remote", "remote_url",
|
8
|
+
"remote_add", "diff", "blame", "contribute"]
|
8
9
|
|
9
10
|
attr_accessor :level_no, :level_path
|
10
11
|
|
data/lib/githug/profile.rb
CHANGED
@@ -9,6 +9,7 @@ module Githug
|
|
9
9
|
def load
|
10
10
|
settings = {
|
11
11
|
:level => nil,
|
12
|
+
:current_attempts => 0,
|
12
13
|
:current_levels => [],
|
13
14
|
:completed_levels => []
|
14
15
|
}
|
@@ -47,6 +48,8 @@ module Githug
|
|
47
48
|
|
48
49
|
settings[:current_levels] = levels
|
49
50
|
|
51
|
+
settings[:current_attempts] = 0
|
52
|
+
|
50
53
|
next_level = (levels - settings[:completed_levels]).first || levels.last
|
51
54
|
|
52
55
|
settings[:level] = next_level
|
data/lib/githug/version.rb
CHANGED
data/spec/githug/game_spec.rb
CHANGED
@@ -3,12 +3,13 @@ require 'spec_helper'
|
|
3
3
|
describe Githug::Game do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@profile = mock
|
6
|
+
@profile = mock.as_null_object
|
7
7
|
Githug::Profile.stub(:new).and_return(@profile)
|
8
8
|
@game = Githug::Game.new
|
9
9
|
@profile.stub(:level).and_return(1)
|
10
10
|
@profile.stub(:save)
|
11
11
|
@profile.stub(:level_bump)
|
12
|
+
@profile.stub(:current_attempts).and_return(0)
|
12
13
|
@level = mock
|
13
14
|
@level.stub(:full_description)
|
14
15
|
@level.stub(:setup_level)
|
@@ -28,17 +29,36 @@ describe Githug::Game do
|
|
28
29
|
@game.play_level
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
describe "solve" do
|
33
|
+
|
34
|
+
it "should echo congratulations if the level is solved" do
|
35
|
+
@level.stub(:solve).and_return(true)
|
36
|
+
@profile.should_receive(:level_bump)
|
37
|
+
Githug::UI.should_receive(:success).with("Congratulations, you have solved the level")
|
38
|
+
@game.play_level
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should echo the solution is not right" do
|
42
|
+
@level.stub(:solve).and_return(false)
|
43
|
+
Githug::UI.should_receive(:error).with("Sorry, this solution is not quite right!")
|
44
|
+
@game.play_level
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should increment the number of failed attempts" do
|
48
|
+
@level.stub(:solve).and_return(false)
|
49
|
+
@profile.should_receive(:current_attempts=).with(1)
|
50
|
+
@profile.should_receive(:save)
|
51
|
+
@game.play_level
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should prompt for a hint if the user has failed 3 times." do
|
55
|
+
@profile.stub(:current_attempts).and_return(3)
|
56
|
+
@level.stub(:solve).and_return(false)
|
57
|
+
Githug::UI.should_receive(:error).with("Sorry, this solution is not quite right!")
|
58
|
+
Githug::UI.should_receive(:error).with("Don't forget you can type `githug hint` for a hint and `githug reset` to reset the current level")
|
59
|
+
@game.play_level
|
60
|
+
end
|
37
61
|
|
38
|
-
it "should echo congratulations if the level is solved" do
|
39
|
-
@level.stub(:solve).and_return(false)
|
40
|
-
Githug::UI.should_receive(:error).with("Sorry, this solution is not quite right!")
|
41
|
-
@game.play_level
|
42
62
|
end
|
43
63
|
|
44
64
|
it "should output the description of the next level" do
|
data/spec/githug/profile_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Githug::Profile do
|
4
4
|
|
5
5
|
it "should load the profile" do
|
6
|
-
settings = {:level => 1, :current_levels => [], :completed_levels => []}
|
6
|
+
settings = {:level => 1, :current_attempts => 0, :current_levels => [], :completed_levels => []}
|
7
7
|
File.should_receive(:exists?).with(Githug::Profile::PROFILE_FILE).and_return(true)
|
8
8
|
File.should_receive(:open).with(Githug::Profile::PROFILE_FILE).and_return("settings")
|
9
9
|
YAML.should_receive(:load).with("settings").and_return(settings)
|
@@ -12,7 +12,7 @@ describe Githug::Profile do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should load the defaults if the file does not exist" do
|
15
|
-
defaults = {:level => nil, :current_levels => [], :completed_levels => []}
|
15
|
+
defaults = {:level => nil, :current_attempts => 0, :current_levels => [], :completed_levels => []}
|
16
16
|
File.should_receive(:exists?).with(Githug::Profile::PROFILE_FILE).and_return(false)
|
17
17
|
Githug::Profile.should_receive(:new).with(defaults)
|
18
18
|
Githug::Profile.load
|
@@ -48,6 +48,12 @@ describe Githug::Profile do
|
|
48
48
|
@profile.level_bump.should eql("add")
|
49
49
|
end
|
50
50
|
|
51
|
+
it "should reset the current_attempts" do
|
52
|
+
@profile.current_attempts = 1
|
53
|
+
@profile.level_bump
|
54
|
+
@profile.current_attempts.should eql(0)
|
55
|
+
end
|
56
|
+
|
51
57
|
it "should set the level to the first incomplete level" do
|
52
58
|
@profile.settings.stub(:[]).with(:level).and_return("rm_cached")
|
53
59
|
@profile.settings.stub(:[]).with(:completed_levels).and_return(["init", "add"])
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: githug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gary Rennie
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-15 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -100,9 +100,11 @@ files:
|
|
100
100
|
- levels/blame/.githug/objects/ff/d39c2dbfd94bdbca06d48686e0cbda642f3de7
|
101
101
|
- levels/blame/.githug/refs/heads/master
|
102
102
|
- levels/blame/config.rb
|
103
|
+
- levels/checkout_file.rb
|
103
104
|
- levels/clone.rb
|
104
105
|
- levels/clone_to_folder.rb
|
105
106
|
- levels/commit.rb
|
107
|
+
- levels/commit_ammend.rb
|
106
108
|
- levels/config.rb
|
107
109
|
- levels/contribute.rb
|
108
110
|
- levels/diff.rb
|
@@ -132,6 +134,10 @@ files:
|
|
132
134
|
- levels/ignore.rb
|
133
135
|
- levels/init.rb
|
134
136
|
- levels/log.rb
|
137
|
+
- levels/remote.rb
|
138
|
+
- levels/remote_add.rb
|
139
|
+
- levels/remote_url.rb
|
140
|
+
- levels/reset.rb
|
135
141
|
- levels/rm.rb
|
136
142
|
- levels/rm_cached.rb
|
137
143
|
- levels/status.rb
|