githug 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/levels/ignore.rb +26 -0
- data/levels/log.rb +18 -0
- data/levels/rm.rb +19 -0
- data/levels/rm_cached.rb +17 -0
- data/lib/githug/game.rb +2 -3
- data/lib/githug/level.rb +6 -4
- data/lib/githug/profile.rb +19 -1
- data/lib/githug/repository.rb +1 -1
- data/lib/githug/version.rb +1 -1
- data/spec/githug/game_spec.rb +4 -4
- data/spec/githug/level_spec.rb +2 -2
- data/spec/githug/profile_spec.rb +29 -6
- data/spec/githug/repository_spec.rb +1 -1
- metadata +5 -1
data/levels/ignore.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
difficulty 2
|
2
|
+
description "The text editor 'vim' creates files ending in .swp (swap files) for all files that are currently open. We don't want them creeping into the repository. Make this repository ignore .swp files."
|
3
|
+
|
4
|
+
setup do
|
5
|
+
repo.init
|
6
|
+
end
|
7
|
+
|
8
|
+
solution do
|
9
|
+
|
10
|
+
valid = false
|
11
|
+
|
12
|
+
|
13
|
+
File.open(".gitignore", "r") do |file|
|
14
|
+
while line = file.gets
|
15
|
+
if line.chomp == "*.swp"
|
16
|
+
valid = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
valid
|
22
|
+
end
|
23
|
+
|
24
|
+
hint do
|
25
|
+
puts "You may have noticed there is a file named .gitignore in the repository"
|
26
|
+
end
|
data/levels/log.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
difficulty 2
|
2
|
+
|
3
|
+
description "You will be asked for the first 7 chars of the hash of most recent commit. You will need to investigate the logs of the repository for this."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
repo.init
|
7
|
+
file = File.new("newfile.rb", "w")
|
8
|
+
repo.add("newfile.rb")
|
9
|
+
repo.commit_all("THIS IS THE COMMIT YOU ARE LOOKING FOR!")
|
10
|
+
end
|
11
|
+
|
12
|
+
solution do
|
13
|
+
repo.commits.last.id_abbrev == request("What are the first 7 characters of the hash of the most recent commit?")
|
14
|
+
end
|
15
|
+
|
16
|
+
hint do
|
17
|
+
puts "You need to investigate the logs. There is probably a command for doing that!"
|
18
|
+
end
|
data/levels/rm.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
difficulty 2
|
2
|
+
|
3
|
+
description "A file has been removed from this repository, however the file was not removed from git. Find out what this file was and remove it."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
repo.init
|
7
|
+
file = File.new("deleteme.rb", "w")
|
8
|
+
repo.add("deleteme.rb")
|
9
|
+
repo.commit_all("Added a temp file")
|
10
|
+
File.delete("deleteme.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
solution do
|
14
|
+
repo.status.files["deleteme.rb"].nil? || repo.status.files["deleteme.rb"].stage.nil?
|
15
|
+
end
|
16
|
+
|
17
|
+
hint do
|
18
|
+
puts "You may need to use more than one command to complete this. You have checked your staging area in a previous level. Don't forget to run `git` for a list of commands."
|
19
|
+
end
|
data/levels/rm_cached.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
difficulty 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."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
repo.init
|
7
|
+
file = File.new("deleteme.rb", "w")
|
8
|
+
repo.add("deleteme.rb")
|
9
|
+
end
|
10
|
+
|
11
|
+
solution do
|
12
|
+
(repo.status.files["deleteme.rb"].nil? || repo.status.files["deleteme.rb"].stage.nil?) && File.exists?("deleteme.rb")
|
13
|
+
end
|
14
|
+
|
15
|
+
hint do
|
16
|
+
puts "You may need to use more than one command to complete this. You have checked your staging area in a previous level. Don't forget to run `git` for a list of commands."
|
17
|
+
end
|
data/lib/githug/game.rb
CHANGED
@@ -9,7 +9,7 @@ module Githug
|
|
9
9
|
|
10
10
|
def play_level
|
11
11
|
solve = true
|
12
|
-
if profile.level
|
12
|
+
if profile.level.nil?
|
13
13
|
UI.puts("Welcome to Githug")
|
14
14
|
solve = false
|
15
15
|
level_bump
|
@@ -28,8 +28,7 @@ module Githug
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def level_bump
|
31
|
-
profile.
|
32
|
-
profile.save
|
31
|
+
profile.level_bump
|
33
32
|
if level = Level.load(profile.level)
|
34
33
|
UI.puts(level.full_description)
|
35
34
|
level.setup_level
|
data/lib/githug/level.rb
CHANGED
@@ -2,19 +2,21 @@ module Githug
|
|
2
2
|
class Level
|
3
3
|
include UI
|
4
4
|
|
5
|
-
LEVELS = [nil, "init", "add", "commit", "config", "clone",
|
5
|
+
LEVELS = [nil, "init", "add", "commit", "config", "clone",
|
6
|
+
"clone_to_folder", "ignore", "status", "rm", "rm_cached", "log",
|
7
|
+
"diff", "blame", "contribute"]
|
6
8
|
|
7
9
|
attr_accessor :level_no, :level_path
|
8
10
|
|
9
11
|
class << self
|
10
12
|
|
11
|
-
def load(
|
13
|
+
def load(level_name)
|
12
14
|
level = new
|
13
|
-
level_path = "#{File.dirname(__FILE__)}/../../levels/#{
|
15
|
+
level_path = "#{File.dirname(__FILE__)}/../../levels/#{level_name}"
|
14
16
|
location = "#{level_path}.rb"
|
15
17
|
return false unless File.exists?(location)
|
16
18
|
level.instance_eval(File.read(location))
|
17
|
-
level.level_no =
|
19
|
+
level.level_no = LEVELS.index(level_name)
|
18
20
|
level.level_path = level_path
|
19
21
|
level
|
20
22
|
end
|
data/lib/githug/profile.rb
CHANGED
@@ -8,10 +8,13 @@ module Githug
|
|
8
8
|
class << self
|
9
9
|
def load
|
10
10
|
settings = {
|
11
|
-
:level =>
|
11
|
+
:level => nil,
|
12
|
+
:current_levels => [],
|
13
|
+
:completed_levels => []
|
12
14
|
}
|
13
15
|
|
14
16
|
settings.merge! YAML::load(File.open(PROFILE_FILE)) if File.exists?(PROFILE_FILE)
|
17
|
+
|
15
18
|
self.new(settings)
|
16
19
|
end
|
17
20
|
end
|
@@ -36,6 +39,21 @@ module Githug
|
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
42
|
+
def level_bump
|
43
|
+
levels = Level::LEVELS
|
44
|
+
level_no = levels.index(settings[:level])
|
45
|
+
|
46
|
+
settings[:completed_levels] << level
|
47
|
+
|
48
|
+
settings[:current_levels] = levels
|
49
|
+
|
50
|
+
next_level = (levels - settings[:completed_levels]).first || levels.last
|
51
|
+
|
52
|
+
settings[:level] = next_level
|
53
|
+
save
|
54
|
+
next_level
|
55
|
+
end
|
56
|
+
|
39
57
|
|
40
58
|
end
|
41
59
|
end
|
data/lib/githug/repository.rb
CHANGED
data/lib/githug/version.rb
CHANGED
data/spec/githug/game_spec.rb
CHANGED
@@ -8,6 +8,7 @@ describe Githug::Game do
|
|
8
8
|
@game = Githug::Game.new
|
9
9
|
@profile.stub(:level).and_return(1)
|
10
10
|
@profile.stub(:save)
|
11
|
+
@profile.stub(:level_bump)
|
11
12
|
@level = mock
|
12
13
|
@level.stub(:full_description)
|
13
14
|
@level.stub(:setup_level)
|
@@ -21,16 +22,15 @@ describe Githug::Game do
|
|
21
22
|
|
22
23
|
it "should show a description if the level is 0" do
|
23
24
|
@level.should_not_receive(:solve)
|
24
|
-
@profile.stub(:level).and_return(
|
25
|
-
@profile.should_receive(:
|
25
|
+
@profile.stub(:level).and_return(nil)
|
26
|
+
@profile.should_receive(:level_bump)
|
26
27
|
Githug::UI.should_receive(:puts).with("Welcome to Githug")
|
27
|
-
@profile.should_receive(:level=).with(1)
|
28
28
|
@game.play_level
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should echo congratulations if the level is solved" do
|
32
32
|
@level.stub(:solve).and_return(true)
|
33
|
-
@profile.should_receive(:
|
33
|
+
@profile.should_receive(:level_bump)
|
34
34
|
Githug::UI.should_receive(:success).with("Congratulations, you have solved the level")
|
35
35
|
@game.play_level
|
36
36
|
end
|
data/spec/githug/level_spec.rb
CHANGED
@@ -20,7 +20,7 @@ end
|
|
20
20
|
eof
|
21
21
|
File.stub(:exists?).and_return(true)
|
22
22
|
File.stub(:read).and_return(@file)
|
23
|
-
@level = Githug::Level.load(
|
23
|
+
@level = Githug::Level.load("init")
|
24
24
|
@repo = mock
|
25
25
|
@repo.stub(:reset)
|
26
26
|
Githug::Repository.stub(:new).and_return(@repo)
|
@@ -38,7 +38,7 @@ end
|
|
38
38
|
it "should load the level" do
|
39
39
|
File.stub(:dirname).and_return("")
|
40
40
|
File.should_receive(:read).with('/../../levels/init.rb').and_return(@file)
|
41
|
-
level = Githug::Level.load(
|
41
|
+
level = Githug::Level.load("init")
|
42
42
|
level.instance_variable_get("@difficulty").should eql(1)
|
43
43
|
level.instance_variable_get("@description").should eql("A test description")
|
44
44
|
end
|
data/spec/githug/profile_spec.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Githug::Profile do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
end
|
7
4
|
|
8
5
|
it "should load the profile" do
|
9
|
-
settings = {:level => 1}
|
6
|
+
settings = {:level => 1, :current_levels => [], :completed_levels => []}
|
10
7
|
File.should_receive(:exists?).with(Githug::Profile::PROFILE_FILE).and_return(true)
|
11
8
|
File.should_receive(:open).with(Githug::Profile::PROFILE_FILE).and_return("settings")
|
12
9
|
YAML.should_receive(:load).with("settings").and_return(settings)
|
@@ -15,14 +12,15 @@ describe Githug::Profile do
|
|
15
12
|
end
|
16
13
|
|
17
14
|
it "should load the defaults if the file does not exist" do
|
18
|
-
defaults = {:level =>
|
15
|
+
defaults = {:level => nil, :current_levels => [], :completed_levels => []}
|
16
|
+
File.should_receive(:exists?).with(Githug::Profile::PROFILE_FILE).and_return(false)
|
19
17
|
Githug::Profile.should_receive(:new).with(defaults)
|
20
18
|
Githug::Profile.load
|
21
19
|
end
|
22
20
|
|
23
21
|
it "should allow method acces to getters and setters" do
|
24
22
|
profile = Githug::Profile.load
|
25
|
-
profile.level.should eql(
|
23
|
+
profile.level.should eql(nil)
|
26
24
|
profile.level = 1
|
27
25
|
profile.level.should eql(1)
|
28
26
|
end
|
@@ -32,5 +30,30 @@ describe Githug::Profile do
|
|
32
30
|
File.should_receive(:open).with(Githug::Profile::PROFILE_FILE, "w")
|
33
31
|
profile.save
|
34
32
|
end
|
33
|
+
|
34
|
+
describe "level_bump" do
|
35
|
+
before(:each) do
|
36
|
+
@profile = Githug::Profile.load
|
37
|
+
@levels = Githug::Level::LEVELS
|
38
|
+
Githug::Level::LEVELS = ["init", "add", "rm", "rm_cached", "diff"]
|
39
|
+
@profile.level = "init"
|
40
|
+
@profile.should_receive(:save)
|
41
|
+
end
|
42
|
+
|
43
|
+
after(:each) do
|
44
|
+
Githug::Level::LEVELS = @levels
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should bump the level" do
|
48
|
+
@profile.level_bump.should eql("add")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should set the level to the first incomplete level" do
|
52
|
+
@profile.settings.stub(:[]).with(:level).and_return("rm_cached")
|
53
|
+
@profile.settings.stub(:[]).with(:completed_levels).and_return(["init", "add"])
|
54
|
+
@profile.level_bump.should eql("rm")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
35
58
|
|
36
59
|
end
|
@@ -69,7 +69,7 @@ describe Githug::Repository do
|
|
69
69
|
|
70
70
|
it "should initialize an empty repository and add .gitignore" do
|
71
71
|
@repo.should_receive(:add).with(".gitignore")
|
72
|
-
@repo.should_receive(:
|
72
|
+
@repo.should_receive(:commit_all).with("added .gitignore")
|
73
73
|
@repository.init
|
74
74
|
end
|
75
75
|
|
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.0.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gary Rennie
|
@@ -129,7 +129,11 @@ files:
|
|
129
129
|
- levels/diff/.githug/objects/dc/aa55e97af34402e84d5336da37abcccc23cba6
|
130
130
|
- levels/diff/.githug/refs/heads/master
|
131
131
|
- levels/diff/app.rb
|
132
|
+
- levels/ignore.rb
|
132
133
|
- levels/init.rb
|
134
|
+
- levels/log.rb
|
135
|
+
- levels/rm.rb
|
136
|
+
- levels/rm_cached.rb
|
133
137
|
- levels/status.rb
|
134
138
|
- lib/githug.rb
|
135
139
|
- lib/githug/cli.rb
|