githug 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/README.md +15 -18
- data/levels/fetch.rb +2 -2
- data/levels/push.rb +1 -1
- data/levels/push_branch.rb +1 -1
- data/levels/rebase.rb +16 -0
- data/levels/rebase/.githug/COMMIT_EDITMSG +1 -0
- data/levels/rebase/.githug/HEAD +1 -0
- data/levels/rebase/.githug/ORIG_HEAD +1 -0
- data/levels/rebase/.githug/config +7 -0
- data/levels/rebase/.githug/index +0 -0
- data/levels/rebase/.githug/logs/HEAD +13 -0
- data/levels/rebase/.githug/logs/refs/heads/feature +4 -0
- data/levels/rebase/.githug/logs/refs/heads/master +2 -0
- data/levels/rebase/.githug/objects/0c/d212c5b28da2e65ed4900712dd36c8adce48ad +0 -0
- data/levels/rebase/.githug/objects/44/19b972c0cd1b346ac90332aa7c5cc949589f78 +0 -0
- data/levels/rebase/.githug/objects/54/3b9bebdc6bd5c4b22136034a95dd097a57d3dd +0 -0
- data/levels/rebase/.githug/objects/81/78c76d627cade75005b40711b92f4177bc6cfc +0 -0
- data/levels/rebase/.githug/objects/98/205e9faf10cf33d2ef7c0f66e402540c62613a +2 -0
- data/levels/rebase/.githug/objects/a7/8bcab6232e9382a86436cdfcb2ed0391b1f0ac +4 -0
- data/levels/rebase/.githug/objects/b7/7313d7be366609dd2e77aa96d7fd73f4e27853 +0 -0
- data/levels/rebase/.githug/objects/b9/2d5d55d379cfb90b750e6472fc983f32ad9a71 +0 -0
- data/levels/rebase/.githug/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- data/levels/rebase/.githug/objects/ed/0fdcf366b21b8984fb37ea34106978a2e5c5ba +0 -0
- data/levels/rebase/.githug/refs/heads/feature +1 -0
- data/levels/rebase/.githug/refs/heads/master +1 -0
- data/levels/rebase/README +1 -0
- data/levels/reorder.rb +1 -4
- data/levels/restructure.rb +1 -1
- data/lib/githug/cli.rb +30 -15
- data/lib/githug/level.rb +1 -1
- data/lib/githug/profile.rb +21 -12
- data/lib/githug/ui.rb +6 -12
- data/lib/githug/version.rb +1 -1
- data/spec/githug/cli_spec.rb +47 -46
- data/spec/githug/game_spec.rb +12 -12
- data/spec/githug/level_spec.rb +64 -93
- data/spec/githug/profile_spec.rb +34 -28
- data/spec/githug/repository_spec.rb +37 -38
- data/spec/githug/ui_spec.rb +51 -51
- data/spec/githug_spec.rb +60 -53
- data/spec/support/files/test_level.rb +16 -0
- metadata +26 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90475cdbf217159f69447674586c43346ec23bca
|
4
|
+
data.tar.gz: 3f6ae08fcf6e630fe0ff4e15734481660b5c3de0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 921a1e7f8e9bec2f4b26ae4a7530fac8e0e3cce43ba4dec7aae6dbf7ed593835e2b2c48ada93c3ed3dfda806d5388e8280fef4b999acb4715e0fc053d8443f80
|
7
|
+
data.tar.gz: 17b1d9dc8d7f5c2c82dfabdf946fc7664048f36a1c5049eddc2484e5a0631273ec209f2c3edbd7541a9a394d9198c61ae8a20889bd22d07818fca67bc2e5810e
|
data/.travis.yml
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
2
3
|
rvm:
|
3
4
|
- 1.8.7
|
4
5
|
- 1.9.2
|
5
6
|
- 1.9.3
|
6
7
|
- 2.0.0
|
8
|
+
- 2.1
|
9
|
+
- ruby-head
|
10
|
+
|
11
|
+
matrix:
|
12
|
+
allow_failures:
|
13
|
+
- rvm: ruby-head
|
14
|
+
|
7
15
|
before_install:
|
8
16
|
- gem update --system 2.1.11
|
9
17
|
- git config --global user.email 'user@example.com'
|
data/README.md
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# Githug
|
2
2
|
Git Your Game On [![Build Status](https://travis-ci.org/Gazler/githug.png?branch=master)](https://travis-ci.org/Gazler/githug) [![Code Climate](https://codeclimate.com/github/Gazler/githug.png)](https://codeclimate.com/github/Gazler/githug)
|
3
3
|
## About
|
4
|
-
Githug is designed to give you a practical way of learning git. It has a series of levels, each
|
4
|
+
Githug is designed to give you a practical way of learning git. It has a series of levels, each requiring you to use git commands to arrive at a correct answer.
|
5
5
|
|
6
6
|
## Installation
|
7
|
-
To install Githug
|
7
|
+
To install Githug, run
|
8
8
|
|
9
9
|
gem install githug
|
10
10
|
|
11
|
-
After the gem is installed,
|
11
|
+
After the gem is installed, run `githug`. You will be prompted to create a directory. Githug should work on Linux, OS X and Windows.
|
12
12
|
|
13
13
|
## Commands
|
14
14
|
|
15
15
|
Githug has 5 commands:
|
16
16
|
|
17
|
-
* play -
|
17
|
+
* play - The default command, checks your solution for the current level
|
18
18
|
* hint - Gives you a hint (if available) for the current level
|
19
19
|
* reset - Reset the current level or reset the level to a given name or path
|
20
|
-
* levels - List all
|
21
|
-
* test -
|
20
|
+
* levels - List all the levels
|
21
|
+
* test - Test levels in development (please see the "Testing Levels" section below)
|
22
22
|
|
23
23
|
## Change Log
|
24
24
|
|
@@ -27,7 +27,7 @@ The change log is available on the wiki. [Change log](https://github.com/Gazler
|
|
27
27
|
|
28
28
|
## Contributing
|
29
29
|
|
30
|
-
|
30
|
+
To suggest a level or create a level that has been suggested, check out [the wiki](https://github.com/Gazler/githug/wiki).
|
31
31
|
|
32
32
|
Get yourself on the [contributors list](https://github.com/Gazler/githug/contributors) by doing the following:
|
33
33
|
|
@@ -39,14 +39,12 @@ If you want to suggest a level or make a level that has been suggested, check ou
|
|
39
39
|
|
40
40
|
## Todo List
|
41
41
|
|
42
|
-
* A follow
|
42
|
+
* A follow-up to the level, more information on a specific command, etc.
|
43
43
|
* More levels!
|
44
44
|
|
45
45
|
## Writing Levels
|
46
46
|
|
47
|
-
Githug has a DSL for writing levels
|
48
|
-
|
49
|
-
An example level:
|
47
|
+
Githug has a DSL for writing levels. Here is an example:
|
50
48
|
|
51
49
|
```ruby
|
52
50
|
difficulty 1
|
@@ -71,7 +69,7 @@ end
|
|
71
69
|
|
72
70
|
`difficulty`, `description` and `solution` are required.
|
73
71
|
|
74
|
-
You can
|
72
|
+
You can include multiple hints like this:
|
75
73
|
|
76
74
|
```ruby
|
77
75
|
hints [
|
@@ -83,8 +81,7 @@ hints [
|
|
83
81
|
|
84
82
|
You can call `repo.init` to initialize an empty repository.
|
85
83
|
|
86
|
-
All methods called on `repo` are sent to the [grit gem](https://github.com/mojombo/grit) if the method does not exist, and you can use that for most git related commands (`repo.add`, `repo.commit`, etc.)
|
87
|
-
|
84
|
+
All methods called on `repo` are sent to the [grit gem](https://github.com/mojombo/grit) if the method does not exist, and you can use that for most git related commands (`repo.add`, `repo.commit`, etc.).
|
88
85
|
|
89
86
|
Another method exists called `init_from_level` and it is used like so:
|
90
87
|
|
@@ -94,23 +91,23 @@ setup do
|
|
94
91
|
end
|
95
92
|
```
|
96
93
|
|
97
|
-
This will copy the contents of a repository specified in the levels folder for your level. For example, if your level is called "merge" then it will copy the contents of the "merge" folder.
|
94
|
+
This will copy the contents of a repository specified in the levels folder for your level. For example, if your level is called "merge" then it will copy the contents of the "merge" folder. It is recommended that you perform the following steps:
|
98
95
|
|
99
96
|
* mkdir "yourlevel"
|
100
97
|
* cd "yourlevel"
|
101
98
|
* git init
|
102
99
|
* some git stuff
|
103
|
-
* **important** rename ".git" to ".githug" so it
|
100
|
+
* **important** rename ".git" to ".githug" so that it isn't treated as a submodule
|
104
101
|
* cd "../"
|
105
102
|
* git add "yourlevel"
|
106
103
|
|
107
|
-
After doing this, your level should be able to copy the contents from that git repository and use those for your level.
|
104
|
+
After doing this, your level should be able to copy the contents from that git repository and use those for your level. See the "blame" level for an example of this.
|
108
105
|
|
109
106
|
## Testing Levels
|
110
107
|
|
111
108
|
The easiest way to test a level is:
|
112
109
|
|
113
|
-
*
|
110
|
+
* Change into your git_hug repository
|
114
111
|
* Run `githug reset PATH_TO_YOUR_LEVEL`
|
115
112
|
* Solve the level
|
116
113
|
* Run `githug test PATH_TO_YOUR_LEVEL`
|
data/levels/fetch.rb
CHANGED
@@ -28,7 +28,7 @@ setup do
|
|
28
28
|
Dir.chdir cwd
|
29
29
|
`git remote add origin #{tmpdir}/.git`
|
30
30
|
`git fetch origin --quiet`
|
31
|
-
`git branch -u origin/master master`
|
31
|
+
`git branch -u origin/master master 2> /dev/null`
|
32
32
|
|
33
33
|
Dir.chdir tmpdir
|
34
34
|
# create a new branch in the remote repo
|
@@ -67,4 +67,4 @@ end
|
|
67
67
|
|
68
68
|
hint do
|
69
69
|
puts "Look up the 'git fetch' command"
|
70
|
-
end
|
70
|
+
end
|
data/levels/push.rb
CHANGED
data/levels/push_branch.rb
CHANGED
data/levels/rebase.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
difficulty 2
|
2
|
+
|
3
|
+
description "We are using a git rebase workflow and the feature branch is ready to go into master. Let's rebase the master branch into our feature branch."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
init_from_level
|
7
|
+
end
|
8
|
+
|
9
|
+
solution do
|
10
|
+
return repo.commits('feature').last.id_abbrev != "ed0fdcf" &&
|
11
|
+
repo.commits("feature").map(&:message) == ['add feature','add content','init commit']
|
12
|
+
end
|
13
|
+
|
14
|
+
hint do
|
15
|
+
puts "You want to research the `git rebase` command"
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
add content
|
@@ -0,0 +1 @@
|
|
1
|
+
ref: refs/heads/master
|
@@ -0,0 +1 @@
|
|
1
|
+
4419b972c0cd1b346ac90332aa7c5cc949589f78
|
Binary file
|
@@ -0,0 +1,13 @@
|
|
1
|
+
0000000000000000000000000000000000000000 a78bcab6232e9382a86436cdfcb2ed0391b1f0ac ipmsteven <steven.lyl147@gmail.com> 1418373185 -0800 commit (initial): init commit
|
2
|
+
a78bcab6232e9382a86436cdfcb2ed0391b1f0ac a78bcab6232e9382a86436cdfcb2ed0391b1f0ac ipmsteven <steven.lyl147@gmail.com> 1418373194 -0800 checkout: moving from master to feature
|
3
|
+
a78bcab6232e9382a86436cdfcb2ed0391b1f0ac ed0fdcf366b21b8984fb37ea34106978a2e5c5ba ipmsteven <steven.lyl147@gmail.com> 1418373239 -0800 commit: add feature
|
4
|
+
ed0fdcf366b21b8984fb37ea34106978a2e5c5ba a78bcab6232e9382a86436cdfcb2ed0391b1f0ac ipmsteven <steven.lyl147@gmail.com> 1418373246 -0800 checkout: moving from feature to master
|
5
|
+
a78bcab6232e9382a86436cdfcb2ed0391b1f0ac 98205e9faf10cf33d2ef7c0f66e402540c62613a ipmsteven <steven.lyl147@gmail.com> 1418373270 -0800 commit: add content
|
6
|
+
98205e9faf10cf33d2ef7c0f66e402540c62613a ed0fdcf366b21b8984fb37ea34106978a2e5c5ba ipmsteven <steven.lyl147@gmail.com> 1418373282 -0800 checkout: moving from master to feature
|
7
|
+
ed0fdcf366b21b8984fb37ea34106978a2e5c5ba 98205e9faf10cf33d2ef7c0f66e402540c62613a ipmsteven <steven.lyl147@gmail.com> 1418373314 -0800 rebase: checkout master
|
8
|
+
98205e9faf10cf33d2ef7c0f66e402540c62613a 4419b972c0cd1b346ac90332aa7c5cc949589f78 ipmsteven <steven.lyl147@gmail.com> 1418373314 -0800 rebase: add feature
|
9
|
+
4419b972c0cd1b346ac90332aa7c5cc949589f78 4419b972c0cd1b346ac90332aa7c5cc949589f78 ipmsteven <steven.lyl147@gmail.com> 1418373314 -0800 rebase finished: returning to refs/heads/feature
|
10
|
+
4419b972c0cd1b346ac90332aa7c5cc949589f78 98205e9faf10cf33d2ef7c0f66e402540c62613a ipmsteven <steven.lyl147@gmail.com> 1418373423 -0800 checkout: moving from feature to master
|
11
|
+
98205e9faf10cf33d2ef7c0f66e402540c62613a 4419b972c0cd1b346ac90332aa7c5cc949589f78 ipmsteven <steven.lyl147@gmail.com> 1418373435 -0800 checkout: moving from master to feature
|
12
|
+
4419b972c0cd1b346ac90332aa7c5cc949589f78 ed0fdcf366b21b8984fb37ea34106978a2e5c5ba ipmsteven <steven.lyl147@gmail.com> 1418373492 -0800 reset: moving to ed0fdcf
|
13
|
+
ed0fdcf366b21b8984fb37ea34106978a2e5c5ba 98205e9faf10cf33d2ef7c0f66e402540c62613a ipmsteven <steven.lyl147@gmail.com> 1418373509 -0800 checkout: moving from feature to master
|
@@ -0,0 +1,4 @@
|
|
1
|
+
0000000000000000000000000000000000000000 a78bcab6232e9382a86436cdfcb2ed0391b1f0ac ipmsteven <steven.lyl147@gmail.com> 1418373194 -0800 branch: Created from HEAD
|
2
|
+
a78bcab6232e9382a86436cdfcb2ed0391b1f0ac ed0fdcf366b21b8984fb37ea34106978a2e5c5ba ipmsteven <steven.lyl147@gmail.com> 1418373239 -0800 commit: add feature
|
3
|
+
ed0fdcf366b21b8984fb37ea34106978a2e5c5ba 4419b972c0cd1b346ac90332aa7c5cc949589f78 ipmsteven <steven.lyl147@gmail.com> 1418373314 -0800 rebase finished: refs/heads/feature onto 98205e9faf10cf33d2ef7c0f66e402540c62613a
|
4
|
+
4419b972c0cd1b346ac90332aa7c5cc949589f78 ed0fdcf366b21b8984fb37ea34106978a2e5c5ba ipmsteven <steven.lyl147@gmail.com> 1418373492 -0800 reset: moving to ed0fdcf
|
@@ -0,0 +1,2 @@
|
|
1
|
+
0000000000000000000000000000000000000000 a78bcab6232e9382a86436cdfcb2ed0391b1f0ac ipmsteven <steven.lyl147@gmail.com> 1418373185 -0800 commit (initial): init commit
|
2
|
+
a78bcab6232e9382a86436cdfcb2ed0391b1f0ac 98205e9faf10cf33d2ef7c0f66e402540c62613a ipmsteven <steven.lyl147@gmail.com> 1418373270 -0800 commit: add content
|
@@ -0,0 +1 @@
|
|
1
|
+
ed0fdcf366b21b8984fb37ea34106978a2e5c5ba
|
@@ -0,0 +1 @@
|
|
1
|
+
98205e9faf10cf33d2ef7c0f66e402540c62613a
|
@@ -0,0 +1 @@
|
|
1
|
+
readme
|
data/levels/reorder.rb
CHANGED
@@ -22,10 +22,7 @@ setup do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
solution do
|
25
|
-
|
26
|
-
return false unless repo.commits[1].message == "Second commit"
|
27
|
-
return false unless repo.commits[0].message == "Third commit"
|
28
|
-
true
|
25
|
+
`git log --format="%s"`.split.join("").match /Third.*Second.*First.*Initial/
|
29
26
|
end
|
30
27
|
|
31
28
|
hint do
|
data/levels/restructure.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
difficulty 3
|
2
2
|
|
3
|
-
description "You added some files to your repository, but now realize that your project needs to be restructured. Make a new folder named `src
|
3
|
+
description "You added some files to your repository, but now realize that your project needs to be restructured. Make a new folder named `src` and using Git move all of the .html files into this folder."
|
4
4
|
|
5
5
|
setup do
|
6
6
|
repo.init
|
data/lib/githug/cli.rb
CHANGED
@@ -10,9 +10,8 @@ module Githug
|
|
10
10
|
|
11
11
|
def play
|
12
12
|
UI.word_box("Githug")
|
13
|
-
make_directory
|
14
|
-
|
15
|
-
game.play_level
|
13
|
+
make_directory!
|
14
|
+
Game.new.play_level
|
16
15
|
end
|
17
16
|
|
18
17
|
desc :test, "Test a level from a file path"
|
@@ -20,10 +19,9 @@ module Githug
|
|
20
19
|
|
21
20
|
def test(path)
|
22
21
|
UI.word_box("Githug")
|
23
|
-
make_directory
|
22
|
+
make_directory!
|
24
23
|
level = Level.load_from_file(path)
|
25
|
-
|
26
|
-
game.test_level(level, options[:errors])
|
24
|
+
Game.new.test_level(level, options[:errors])
|
27
25
|
end
|
28
26
|
|
29
27
|
desc :hint, "Get a hint for the current level"
|
@@ -35,7 +33,15 @@ module Githug
|
|
35
33
|
end
|
36
34
|
|
37
35
|
desc :reset, "Reset the current level"
|
36
|
+
long_desc <<-LONGDESC
|
37
|
+
`githug reset` will reset the current level. You can optionally specify a
|
38
|
+
LEVEL parameter which will reset the game to a specific level. For
|
39
|
+
example:
|
38
40
|
|
41
|
+
> $ githug reset merge_squash
|
42
|
+
|
43
|
+
Will reset githug to level '#45: merge_squash'
|
44
|
+
LONGDESC
|
39
45
|
def reset(path = nil)
|
40
46
|
level = load_level(path)
|
41
47
|
UI.word_box("Githug")
|
@@ -77,23 +83,32 @@ module Githug
|
|
77
83
|
end
|
78
84
|
|
79
85
|
|
80
|
-
def make_directory
|
86
|
+
def make_directory!
|
87
|
+
return if File.basename(Dir.pwd) == "git_hug"
|
88
|
+
check_githug_directory!
|
89
|
+
prompt_githug_directory!
|
90
|
+
make_githug_directory!
|
91
|
+
end
|
92
|
+
|
93
|
+
def check_githug_directory!
|
81
94
|
if File.exists?("./git_hug")
|
82
95
|
UI.puts "Please change into the git_hug directory"
|
83
96
|
exit
|
84
97
|
end
|
98
|
+
end
|
85
99
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
else
|
91
|
-
UI.puts("Exiting")
|
92
|
-
exit
|
93
|
-
end
|
100
|
+
def prompt_githug_directory!
|
101
|
+
unless UI.ask("No githug directory found, do you wish to create one?")
|
102
|
+
UI.puts("Exiting")
|
103
|
+
exit
|
94
104
|
end
|
95
105
|
end
|
96
106
|
|
107
|
+
def make_githug_directory!
|
108
|
+
Dir.mkdir("./git_hug")
|
109
|
+
Dir.chdir("git_hug")
|
110
|
+
end
|
111
|
+
|
97
112
|
end
|
98
113
|
|
99
114
|
end
|
data/lib/githug/level.rb
CHANGED
@@ -9,7 +9,7 @@ module Githug
|
|
9
9
|
"commit_in_future", "reset", "reset_soft", "checkout_file", "remote",
|
10
10
|
"remote_url", "pull", "remote_add", "push", "diff", "blame", "branch",
|
11
11
|
"checkout", "checkout_tag", "checkout_tag_over_branch", "branch_at",
|
12
|
-
"delete_branch", "push_branch", "merge", "fetch", "repack", "cherry-pick",
|
12
|
+
"delete_branch", "push_branch", "merge", "fetch", "rebase", "repack", "cherry-pick",
|
13
13
|
"grep", "rename_commit", "squash", "merge_squash", "reorder", "bisect",
|
14
14
|
"stage_lines", "find_old_branch", "revert", "restore", "conflict", "contribute"]
|
15
15
|
|
data/lib/githug/profile.rb
CHANGED
@@ -7,18 +7,26 @@ module Githug
|
|
7
7
|
|
8
8
|
class << self
|
9
9
|
def load
|
10
|
-
settings
|
10
|
+
self.new(settings)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def settings
|
16
|
+
return defaults unless File.exists?(PROFILE_FILE)
|
17
|
+
defaults.merge(YAML::load(File.open(PROFILE_FILE)))
|
18
|
+
end
|
19
|
+
|
20
|
+
def defaults
|
21
|
+
{
|
11
22
|
:level => nil,
|
12
23
|
:current_attempts => 0,
|
13
24
|
:current_hint_index => 0,
|
14
25
|
:current_levels => [],
|
15
26
|
:completed_levels => []
|
16
27
|
}
|
17
|
-
|
18
|
-
settings.merge! YAML::load(File.open(PROFILE_FILE)) if File.exists?(PROFILE_FILE)
|
19
|
-
|
20
|
-
self.new(settings)
|
21
28
|
end
|
29
|
+
|
22
30
|
end
|
23
31
|
|
24
32
|
|
@@ -48,24 +56,25 @@ module Githug
|
|
48
56
|
end
|
49
57
|
|
50
58
|
def level_bump
|
51
|
-
levels = Level::LEVELS
|
52
|
-
level_no = levels.index(settings[:level])
|
53
|
-
|
54
59
|
settings[:completed_levels] << level
|
55
60
|
settings[:current_levels] = levels
|
56
|
-
next_level = (levels - settings[:completed_levels]).first || levels.last
|
57
|
-
|
58
61
|
set_level(next_level)
|
59
|
-
next_level
|
60
62
|
end
|
61
63
|
|
62
64
|
private
|
63
65
|
|
66
|
+
def levels
|
67
|
+
Level::LEVELS
|
68
|
+
end
|
69
|
+
|
70
|
+
def next_level
|
71
|
+
(levels - settings[:completed_levels]).first || levels.last
|
72
|
+
end
|
73
|
+
|
64
74
|
def reset!
|
65
75
|
settings[:current_attempts] = 0
|
66
76
|
settings[:current_hint_index] = 0
|
67
77
|
end
|
68
78
|
|
69
|
-
|
70
79
|
end
|
71
80
|
end
|