githug 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/levels/blame.rb +1 -6
- data/levels/branch_at.rb +1 -3
- data/levels/merge.rb +3 -3
- data/levels/pull.rb +16 -0
- data/levels/rename.rb +6 -6
- data/levels/rename_commit.rb +8 -8
- data/levels/stage_lines.rb +29 -0
- data/lib/githug/level.rb +2 -2
- data/lib/githug/version.rb +1 -1
- metadata +4 -3
- data/lib/githug/level.rb.orig +0 -120
data/README.md
CHANGED
@@ -38,6 +38,7 @@ If you want to suggest a level or make a level that has been suggested, check ou
|
|
38
38
|
* A better way of returning from the solution block
|
39
39
|
* A follow up to the level, more information on a specific command, etc.
|
40
40
|
* More levels!
|
41
|
+
* [Windows support](https://github.com/Gazler/githug/wiki/Windows-Support)
|
41
42
|
|
42
43
|
##Writing Levels
|
43
44
|
|
data/levels/blame.rb
CHANGED
@@ -6,13 +6,8 @@ setup do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
solution do
|
9
|
-
|
10
|
-
solved = false
|
11
|
-
|
12
9
|
offender = repo.commit("97bdd0cccf9f4b8730f78cb53a81a74f205dbcc2").author.name
|
13
|
-
|
14
|
-
|
15
|
-
solved
|
10
|
+
request("Who made the commit with the password?").downcase == offender.downcase
|
16
11
|
end
|
17
12
|
|
18
13
|
hint do
|
data/levels/branch_at.rb
CHANGED
@@ -15,9 +15,7 @@ setup do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
solution do
|
18
|
-
|
19
|
-
solved = true if repo.branches.map(&:name).include?("test_branch") and (repo.commits("test_branch").last.message == "Updating file1")
|
20
|
-
solved
|
18
|
+
repo.branches.map(&:name).include?("test_branch") and (repo.commits("test_branch").last.message == "Updating file1")
|
21
19
|
end
|
22
20
|
|
23
21
|
hint do
|
data/levels/merge.rb
CHANGED
@@ -2,13 +2,13 @@ difficulty 2
|
|
2
2
|
description "We have a file in the branch 'feature'; Let's merge it to the master branch"
|
3
3
|
|
4
4
|
setup do
|
5
|
-
|
5
|
+
init_from_level
|
6
6
|
end
|
7
7
|
|
8
8
|
solution do
|
9
|
-
|
9
|
+
`ls`.strip().split() == ["file1", "file2"]
|
10
10
|
end
|
11
11
|
|
12
12
|
hint do
|
13
|
-
|
13
|
+
puts "You want to research the `git merge` command"
|
14
14
|
end
|
data/levels/pull.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
difficulty 2
|
2
|
+
|
3
|
+
description "You need to pull changes from your origin repository."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
repo.init
|
7
|
+
repo.remote_add("origin", "https://github.com/pull-this/thing-to-pull")
|
8
|
+
end
|
9
|
+
|
10
|
+
solution do
|
11
|
+
repo.commits.last.id_abbrev == "1797a7c"
|
12
|
+
end
|
13
|
+
|
14
|
+
hint do
|
15
|
+
puts "Check out the remote repositories and research `git pull`."
|
16
|
+
end
|
data/levels/rename.rb
CHANGED
@@ -3,16 +3,16 @@ difficulty 3
|
|
3
3
|
description "We have a file called oldfile.txt. We want to rename it to newfile.txt and stage this change."
|
4
4
|
|
5
5
|
setup do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
repo.init
|
7
|
+
FileUtils.touch("oldfile.txt")
|
8
|
+
repo.add("oldfile.txt")
|
9
|
+
repo.commit_all("Commited oldfile.txt")
|
10
10
|
end
|
11
11
|
|
12
12
|
solution do
|
13
|
-
|
13
|
+
repo.status["oldfile.txt"].type == "D" && repo.status["newfile.txt"].type == "A" && repo.status["oldfile.txt"].stage.nil?
|
14
14
|
end
|
15
15
|
|
16
16
|
hint do
|
17
|
-
|
17
|
+
puts "Take a look at `git mv`"
|
18
18
|
end
|
data/levels/rename_commit.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
difficulty 3
|
2
|
-
description "Correct the
|
2
|
+
description "Correct the typo in the message of your first commit."
|
3
3
|
|
4
4
|
setup do
|
5
5
|
repo.init
|
6
6
|
|
7
|
-
FileUtils.touch "README"
|
8
|
-
repo.add "README"
|
9
|
-
repo.commit_all "Adding README"
|
10
|
-
|
11
7
|
FileUtils.touch "file1"
|
12
8
|
repo.add "file1"
|
13
|
-
repo.commit_all "
|
9
|
+
repo.commit_all "First commmit"
|
10
|
+
|
11
|
+
FileUtils.touch "file2"
|
12
|
+
repo.add "file2"
|
13
|
+
repo.commit_all "Second commit"
|
14
14
|
end
|
15
15
|
|
16
16
|
solution do
|
17
|
-
repo.commits.
|
17
|
+
repo.commits[1].message == "First commit"
|
18
18
|
end
|
19
19
|
|
20
20
|
hint do
|
21
|
-
puts "Take a look the -i flag of the rebase command"
|
21
|
+
puts "Take a look the -i flag of the rebase command."
|
22
22
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
difficulty 4
|
2
|
+
|
3
|
+
description "You've made changes within a single file that belong to two different features, but niether of the changes are yet staged. Stage and commit only the changes belonging to the first feature."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
repo.init
|
7
|
+
File.open("feature.rb", "w") do |file|
|
8
|
+
file.puts("this is the class of my feature")
|
9
|
+
end
|
10
|
+
|
11
|
+
repo.add("feature.rb")
|
12
|
+
repo.commit_all("Added initial feature file")
|
13
|
+
|
14
|
+
File.open("feature.rb", "a") do |file|
|
15
|
+
file.puts("This change belongs to the first feature")
|
16
|
+
end
|
17
|
+
|
18
|
+
File.open("feature.rb", "a") do |file|
|
19
|
+
file.puts("This change belongs to the second feature")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
solution do
|
24
|
+
`git diff --staged` =~ /\+This change belongs to the first feature/ && `git diff` =~ /\+This change belongs to the second feature/
|
25
|
+
end
|
26
|
+
|
27
|
+
hint do
|
28
|
+
puts "Read about the -p flag which can be passed to the 'add' command; man git-add. After that have a look the options available while using 'add -p' mode to manupulate hunks."
|
29
|
+
end
|
data/lib/githug/level.rb
CHANGED
@@ -5,8 +5,8 @@ module Githug
|
|
5
5
|
LEVELS = [nil, "init", "add", "commit", "config", "clone",
|
6
6
|
"clone_to_folder", "ignore", "status", "rm", "rm_cached", "rename",
|
7
7
|
"log", "tag", "commit_ammend", "reset", "checkout_file", "remote",
|
8
|
-
"remote_url", "remote_add", "diff", "blame", "branch", "checkout",
|
9
|
-
"branch_at", "merge", "rename_commit", "squash", "contribute"]
|
8
|
+
"remote_url", "pull", "remote_add", "diff", "blame", "branch", "checkout",
|
9
|
+
"branch_at", "merge", "rename_commit", "squash", "stage_lines", "contribute"]
|
10
10
|
|
11
11
|
attr_accessor :level_no, :level_path
|
12
12
|
|
data/lib/githug/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: githug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.8
|
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-22 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- levels/merge/.githug/refs/heads/feature
|
178
178
|
- levels/merge/.githug/refs/heads/master
|
179
179
|
- levels/merge/file1
|
180
|
+
- levels/pull.rb
|
180
181
|
- levels/remote.rb
|
181
182
|
- levels/remote_add.rb
|
182
183
|
- levels/remote_url.rb
|
@@ -186,13 +187,13 @@ files:
|
|
186
187
|
- levels/rm.rb
|
187
188
|
- levels/rm_cached.rb
|
188
189
|
- levels/squash.rb
|
190
|
+
- levels/stage_lines.rb
|
189
191
|
- levels/status.rb
|
190
192
|
- levels/tag.rb
|
191
193
|
- lib/githug.rb
|
192
194
|
- lib/githug/cli.rb
|
193
195
|
- lib/githug/game.rb
|
194
196
|
- lib/githug/level.rb
|
195
|
-
- lib/githug/level.rb.orig
|
196
197
|
- lib/githug/profile.rb
|
197
198
|
- lib/githug/repository.rb
|
198
199
|
- lib/githug/ui.rb
|
data/lib/githug/level.rb.orig
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
module Githug
|
2
|
-
class Level
|
3
|
-
include UI
|
4
|
-
|
5
|
-
LEVELS = [nil, "init", "add", "commit", "config", "clone",
|
6
|
-
"clone_to_folder", "ignore", "status", "rm", "rm_cached", "rename",
|
7
|
-
<<<<<<< HEAD
|
8
|
-
"log", "tag", "commit_ammend", "reset", "checkout_file", "remote",
|
9
|
-
"remote_url", "remote_add", "diff", "blame", "branch", "checkout",
|
10
|
-
=======
|
11
|
-
"log", "commit_ammend", "reset", "checkout_file", "remote",
|
12
|
-
"remote_url", "remote_add", "diff", "blame", "branch", "checkout", "branch_at",
|
13
|
-
>>>>>>> manojlds/master
|
14
|
-
"merge", "squash", "contribute"]
|
15
|
-
|
16
|
-
attr_accessor :level_no, :level_path
|
17
|
-
|
18
|
-
class << self
|
19
|
-
|
20
|
-
def load(level_name)
|
21
|
-
path = "#{File.dirname(__FILE__)}/../../levels/#{level_name}.rb"
|
22
|
-
setup(path)
|
23
|
-
end
|
24
|
-
|
25
|
-
def load_from_file(path)
|
26
|
-
setup(path)
|
27
|
-
end
|
28
|
-
|
29
|
-
def setup(path)
|
30
|
-
level_name = File.basename(path, File.extname(path))
|
31
|
-
#Remove .rb extension, WTB a better way to do this
|
32
|
-
level_path = path[0..-4]
|
33
|
-
level = new
|
34
|
-
return false unless File.exists?(path)
|
35
|
-
level.instance_eval(File.read(path))
|
36
|
-
level.level_no = LEVELS.index(level_name) || 1
|
37
|
-
level.level_path = level_path
|
38
|
-
level
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def init_from_level
|
44
|
-
FileUtils.cp_r("#{level_path}/.", ".")
|
45
|
-
FileUtils.mv(".githug", ".git")
|
46
|
-
end
|
47
|
-
|
48
|
-
def difficulty(num)
|
49
|
-
@difficulty = num
|
50
|
-
end
|
51
|
-
|
52
|
-
def description(description)
|
53
|
-
@description = description
|
54
|
-
end
|
55
|
-
|
56
|
-
def solution(&block)
|
57
|
-
@solution = block
|
58
|
-
end
|
59
|
-
|
60
|
-
def setup(&block)
|
61
|
-
@setup = block
|
62
|
-
end
|
63
|
-
|
64
|
-
def hint(&hint)
|
65
|
-
@hint = hint
|
66
|
-
end
|
67
|
-
|
68
|
-
def hints(hints)
|
69
|
-
@hints = hints
|
70
|
-
end
|
71
|
-
|
72
|
-
def full_description
|
73
|
-
UI.puts
|
74
|
-
UI.puts "Level: #{level_no}"
|
75
|
-
UI.puts "Difficulty: #{"*"*@difficulty}"
|
76
|
-
UI.puts
|
77
|
-
UI.puts @description
|
78
|
-
UI.puts
|
79
|
-
end
|
80
|
-
|
81
|
-
def setup_level
|
82
|
-
repo.reset
|
83
|
-
@setup.call if @setup
|
84
|
-
end
|
85
|
-
|
86
|
-
def repo(location = "")
|
87
|
-
@repo ||= Repository.new(location)
|
88
|
-
end
|
89
|
-
|
90
|
-
def solve
|
91
|
-
@solution.call
|
92
|
-
rescue
|
93
|
-
false
|
94
|
-
end
|
95
|
-
|
96
|
-
def test
|
97
|
-
@solution.call
|
98
|
-
end
|
99
|
-
|
100
|
-
def show_hint
|
101
|
-
UI.word_box("Githug")
|
102
|
-
profile = Profile.load
|
103
|
-
current_hint_index = profile.current_hint_index
|
104
|
-
if @hints
|
105
|
-
puts @hints[current_hint_index]
|
106
|
-
if current_hint_index < @hints.size - 1
|
107
|
-
profile.current_hint_index += 1
|
108
|
-
profile.save
|
109
|
-
else
|
110
|
-
profile.current_hint_index = 0
|
111
|
-
profile.save
|
112
|
-
end
|
113
|
-
elsif @hint
|
114
|
-
@hint.call
|
115
|
-
else
|
116
|
-
UI.puts("No hints available for this level")
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|