mygithug 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/mg +2 -0
- data/levels/add.rb +38 -31
- data/levels/alias_lg.rb +67 -60
- data/levels/cherry-pick.rb +22 -20
- data/levels/conflict.rb +27 -24
- data/levels/log.rb +25 -23
- data/levels/pull_rebase.rb +67 -50
- data/levels/push_branch.rb +89 -89
- data/levels/rebase_conflict.rb +68 -56
- data/lib/githug/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61dc29f7d047b967bef140e5e246cf7e46f4d899
|
4
|
+
data.tar.gz: 0e614ae2c7eee8efef06f79ab1ed7407a823d2f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae34fccda3f5e25e7e98bf85cf759cd9dec9a34eefefe041a52a21460ba7ce0ec3cc6980025bcd0da5bdb856f8b69b217a4c0b861e54ec01fe900fed41f6e283
|
7
|
+
data.tar.gz: 1ead678ba4cb8a723223eb5ddc4fa0e162fb8dd5e66ccc5c5d2328e6a9d08d273ed85e3b56bed8564820dd7abb2f3e4d71f31b11c8e3eafa4e9ddf41ceaf092c
|
data/bin/mg
CHANGED
data/levels/add.rb
CHANGED
@@ -1,31 +1,38 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
difficulty 1
|
3
|
-
description "你已经创建了文件 README, 请把它加到Stage区,注意保持另一个文件file2不变。观察file2.txt在工作区-Stage-Head间有哪些变化。
|
4
|
-
Note: You start each level with a new repo. Don't look for files from the previous one."
|
5
|
-
|
6
|
-
setup do
|
7
|
-
repo.init
|
8
|
-
FileUtils.touch("README")
|
9
|
-
FileUtils.touch("file2.txt")
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
difficulty 1
|
3
|
+
description "你已经创建了文件 README, 请把它加到Stage区,注意保持另一个文件file2不变。观察file2.txt在工作区-Stage-Head间有哪些变化。
|
4
|
+
Note: You start each level with a new repo. Don't look for files from the previous one."
|
5
|
+
|
6
|
+
setup do
|
7
|
+
repo.init
|
8
|
+
FileUtils.touch("README")
|
9
|
+
FileUtils.touch("file2.txt")
|
10
|
+
|
11
|
+
File.open("README", "w") do | f |
|
12
|
+
f.write "Hello\n"
|
13
|
+
end
|
14
|
+
|
15
|
+
repo.add("file2.txt")
|
16
|
+
|
17
|
+
File.open("file2.txt", "w") do | f |
|
18
|
+
f.write "NEWlINE\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
solution do
|
24
|
+
return false unless repo.status.files.keys.include?("README")
|
25
|
+
return false if repo.status.files["README"].untracked
|
26
|
+
return false if "1" == request("在工作区(Workspace)与Stage之间,file2.txt有哪些变化:
|
27
|
+
1. 无变化
|
28
|
+
2. 增加了一行:NEWLINE
|
29
|
+
")
|
30
|
+
"2" == request("在HEAD与Stage之间,file2.txt有哪些变化:
|
31
|
+
1. 无变化
|
32
|
+
2. 新增了文件file2.txt
|
33
|
+
")
|
34
|
+
end
|
35
|
+
|
36
|
+
hint do
|
37
|
+
puts "你需要使用`git add` 和`git diff`命令。必要时加上`--cached`参数."
|
38
|
+
end
|
data/levels/alias_lg.rb
CHANGED
@@ -1,60 +1,67 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
difficulty 1
|
3
|
-
description "
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
repo.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
repo.commit_all "add another file:
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
valid
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
difficulty 1
|
3
|
+
description "本关不做考核,仅用于提示您增加两个查看日志的别名,以方便查看日志。
|
4
|
+
增加两个别名:git lg 和git fl,命令分别如下:
|
5
|
+
git config --global alias.lg \"log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(dim)%ad%C(reset) %C(cyan)%s%C(reset) %C(dim)- %an%C(reset)%C(auto)%d%C(reset)' --date=format:'%Y-%m-%d %H:%M:%S'\"
|
6
|
+
git config --global alias.fl \"log -M --follow --stat --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(dim)%ad%C(reset) %C(cyan)%s%C(reset) %C(dim)- %an%C(reset)%C(auto)%d%C(reset)' --date=format:'%Y-%m-%d %H:%M:%S'\"
|
7
|
+
|
8
|
+
之后,您可以通过`git lg` 查看日志,或者 `git lg -p`查看包括变更内容的日志。
|
9
|
+
通过`git fl <filename>` 或 `git fl -p <filename> 查看某个文件的日志。
|
10
|
+
|
11
|
+
"
|
12
|
+
|
13
|
+
setup do
|
14
|
+
repo.init
|
15
|
+
|
16
|
+
FileUtils.touch "file1"
|
17
|
+
repo.add "file1"
|
18
|
+
repo.commit_all "committed changes on master"
|
19
|
+
|
20
|
+
# add another file.
|
21
|
+
FileUtils.touch "file2"
|
22
|
+
repo.add "file2"
|
23
|
+
repo.commit_all "add another file: file2"
|
24
|
+
|
25
|
+
`git checkout -b other_branch --quiet`
|
26
|
+
# add another file
|
27
|
+
FileUtils.touch "file3"
|
28
|
+
repo.add "file3"
|
29
|
+
# `echo "hello" >> file2`
|
30
|
+
# repo.add "file2"
|
31
|
+
repo.commit_all "add another file: file3"
|
32
|
+
|
33
|
+
# `git checkout -b test_branch --quiet`
|
34
|
+
|
35
|
+
# FileUtils.touch "file4"
|
36
|
+
# repo.add "file4"
|
37
|
+
# repo.commit_all "committed change on test_branch"
|
38
|
+
|
39
|
+
`git checkout master --quiet`
|
40
|
+
|
41
|
+
FileUtils.touch "file5"
|
42
|
+
repo.add "file5"
|
43
|
+
repo.commit_all "add another file: file5"
|
44
|
+
|
45
|
+
`git merge other_branch -m "merge other_branch"`
|
46
|
+
# `git merge test_branch`
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
solution do
|
51
|
+
valid = true
|
52
|
+
|
53
|
+
# config_alias_lg = repo.config["alias.lg"]
|
54
|
+
# config_alias_filelg = repo.config["alias.fl"]
|
55
|
+
# valid = "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(dim)%ad%C(reset) %C(cyan)%s%C(reset) %C(dim)- %an%C(reset)%C(auto)%d%C(reset)' --date=format:'%Y-%m-%d %H:%M:%S'" == config_alias_lg
|
56
|
+
# valid2 = "log -M --follow --stat --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(dim)%ad%C(reset) %C(cyan)%s%C(reset) %C(dim)- %an%C(reset)%C(auto)%d%C(reset)' --date=format:'%Y-%m-%d %H:%M:%S'" == config_alias_filelg
|
57
|
+
|
58
|
+
# valid && valid2
|
59
|
+
end
|
60
|
+
|
61
|
+
hint do
|
62
|
+
puts "增加两个别名:git lg 和git fl,分别如下:
|
63
|
+
lg: log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(dim)%ad%C(reset) %C(cyan)%s%C(reset) %C(dim)- %an%C(reset)%C(auto)%d%C(reset)' --date=format:'%Y-%m-%d %H:%M:%S'
|
64
|
+
fl: log -M --follow --stat --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(dim)%ad%C(reset) %C(cyan)%s%C(reset) %C(dim)- %an%C(reset)%C(auto)%d%C(reset)' --date=format:'%Y-%m-%d %H:%M:%S'
|
65
|
+
|
66
|
+
"
|
67
|
+
end
|
data/levels/cherry-pick.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
difficulty 3
|
3
|
-
description "你在hotfix分支修复生产环境的紧急问题,现在你已经修复完成,需要单独将这个修复(Filled in README.md with proper input) 合并到master分支."
|
4
|
-
|
5
|
-
setup do
|
6
|
-
init_from_level
|
7
|
-
`git stash` #fix for README.md being in githug root an the level
|
8
|
-
`git checkout new-feature --quiet
|
9
|
-
`git
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
difficulty 3
|
3
|
+
description "你在hotfix分支修复生产环境的紧急问题,现在你已经修复完成,需要单独将这个修复(Filled in README.md with proper input) 合并到master分支."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
init_from_level
|
7
|
+
`git stash` #fix for README.md being in githug root an the level
|
8
|
+
`git checkout new-feature --quiet`
|
9
|
+
`git branch -m hotfix --quiet`
|
10
|
+
`git checkout master --quiet`
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
solution do
|
15
|
+
return false unless repo.commits[1].message == "Added fancy branded output"
|
16
|
+
return false unless repo.commits[0].message == "Filled in README.md with proper input"
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
hint do
|
21
|
+
puts "Sneak a peek at the `cherry-pick` command."
|
22
|
+
end
|
data/levels/conflict.rb
CHANGED
@@ -1,24 +1,27 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
difficulty 4
|
3
|
-
description "你需要将 `mybranch`分支的变更merge到当前分支 (master). 如果有冲突,请把它搞定."
|
4
|
-
|
5
|
-
setup do
|
6
|
-
init_from_level
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
solved =
|
14
|
-
|
15
|
-
|
16
|
-
solved = false
|
17
|
-
|
18
|
-
|
19
|
-
solved
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
difficulty 4
|
3
|
+
description "你需要将 `mybranch`分支的变更merge到当前分支 (master). 如果有冲突,请把它搞定."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
init_from_level
|
7
|
+
|
8
|
+
`git add .`
|
9
|
+
`git commit -m "fix a bug" --quiet`
|
10
|
+
end
|
11
|
+
|
12
|
+
solution do
|
13
|
+
solved = true
|
14
|
+
|
15
|
+
solved = false unless repo.head.name == "master"
|
16
|
+
solved = false unless repo.commits("master")[0].parents.length == 2
|
17
|
+
|
18
|
+
txt = File.read("poem.txt")
|
19
|
+
solved = false if txt =~ /[<>=|]/
|
20
|
+
solved = false unless txt =~ /Sat on a wall/
|
21
|
+
|
22
|
+
solved
|
23
|
+
end
|
24
|
+
|
25
|
+
hint do
|
26
|
+
puts ["首先,你要merge,然后解决冲突。最后别忘了commit."]
|
27
|
+
end
|
data/levels/log.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
difficulty 2
|
3
|
-
|
4
|
-
description "你需要提供最近一次提交的commit id,并找出新增的内容是什么。"
|
5
|
-
|
6
|
-
setup do
|
7
|
-
repo.init
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
difficulty 2
|
3
|
+
|
4
|
+
description "你需要提供最近一次提交的commit id,并找出新增的内容是什么。"
|
5
|
+
|
6
|
+
setup do
|
7
|
+
repo.init
|
8
|
+
|
9
|
+
# begin
|
10
|
+
File.open("newfile.txt", "w") do | f |
|
11
|
+
f.write "Hello\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
repo.add("newfile.txt")
|
15
|
+
repo.commit_all("THIS IS THE COMMIT YOU ARE LOOKING FOR!")
|
16
|
+
end
|
17
|
+
|
18
|
+
solution do
|
19
|
+
repo.commits.last.id_abbrev == request("最近一次提交的commit id是多少?")[0..6]
|
20
|
+
"Hello" == request("最近一次提交时,文件newfile.txt中新增的内容是什么?")
|
21
|
+
end
|
22
|
+
|
23
|
+
hint do
|
24
|
+
puts "你需要查看提交日志."
|
25
|
+
end
|
data/levels/pull_rebase.rb
CHANGED
@@ -1,50 +1,67 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
difficulty 2
|
3
|
-
description "你需获取远程所有分⽀最新代码,并让版本树尽量整洁(只有⼀个树⼲)."
|
4
|
-
|
5
|
-
setup do
|
6
|
-
# remember the working directory so we can come back to it later
|
7
|
-
cwd = Dir.pwd
|
8
|
-
repo.init
|
9
|
-
|
10
|
-
# initialize another git repo to be used as a "remote"
|
11
|
-
# remote repo
|
12
|
-
tmpdir = Dir.mktmpdir
|
13
|
-
Dir.chdir tmpdir
|
14
|
-
repo.init
|
15
|
-
# make a 'non-bare' repo accept pushes
|
16
|
-
`git config receive.denyCurrentBranch ignore`
|
17
|
-
|
18
|
-
# add a different file and commit so remote and local would diverge
|
19
|
-
FileUtils.touch "file1"
|
20
|
-
repo.add "file1"
|
21
|
-
repo.commit_all "first commit"
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
`git
|
28
|
-
|
29
|
-
|
30
|
-
`git
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
`
|
40
|
-
`git
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
difficulty 2
|
3
|
+
description "你需获取远程所有分⽀最新代码,并让版本树尽量整洁(只有⼀个树⼲)."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
# remember the working directory so we can come back to it later
|
7
|
+
cwd = Dir.pwd
|
8
|
+
repo.init
|
9
|
+
|
10
|
+
# initialize another git repo to be used as a "remote"
|
11
|
+
# remote repo
|
12
|
+
tmpdir = Dir.mktmpdir
|
13
|
+
Dir.chdir tmpdir
|
14
|
+
repo.init
|
15
|
+
# make a 'non-bare' repo accept pushes
|
16
|
+
`git config receive.denyCurrentBranch ignore`
|
17
|
+
|
18
|
+
# add a different file and commit so remote and local would diverge
|
19
|
+
FileUtils.touch "file1"
|
20
|
+
repo.add "file1"
|
21
|
+
repo.commit_all "first commit"
|
22
|
+
|
23
|
+
|
24
|
+
# change back to original repo to set up a remote
|
25
|
+
Dir.chdir cwd
|
26
|
+
|
27
|
+
`git remote add origin #{tmpdir}/.git `
|
28
|
+
|
29
|
+
`git fetch origin --quiet`
|
30
|
+
# `git branch -u origin/master master`
|
31
|
+
|
32
|
+
# 处理本地repo
|
33
|
+
`git pull origin master --quiet`
|
34
|
+
|
35
|
+
File.open("file1", "a") do | f |
|
36
|
+
f.write "Hello\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
`git add file1`
|
40
|
+
`git commit -m "Second commit" --quiet`
|
41
|
+
|
42
|
+
Dir.chdir tmpdir
|
43
|
+
FileUtils.touch "file2"
|
44
|
+
File.open("#{tmpdir}/file2", "w") do | f |
|
45
|
+
f.write "Hello\n"
|
46
|
+
end
|
47
|
+
`git add file2`
|
48
|
+
`git commit -m "Third commit" --quiet`
|
49
|
+
|
50
|
+
Dir.chdir cwd
|
51
|
+
FileUtils.touch "file3"
|
52
|
+
File.open("#{cwd}/file3", "w") do | f |
|
53
|
+
f.write "Hello\n"
|
54
|
+
end
|
55
|
+
`git add file3`
|
56
|
+
`git commit -m "Forth commit" --quiet`
|
57
|
+
`git branch --set-upstream-to=origin/master master`
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
solution do
|
62
|
+
1 == repo.commits("master")[0].parents.length
|
63
|
+
end
|
64
|
+
|
65
|
+
hint do
|
66
|
+
puts "Take a look at `git fetch`, `git pull`, and `git push`."
|
67
|
+
end
|
data/levels/push_branch.rb
CHANGED
@@ -1,89 +1,89 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
difficulty 2
|
3
|
-
description "你已经创建了本地分支 `test_branch`,开发已经完成,你需要将此分支 push 到远程代码库。
|
4
|
-
注意:只能push `test_branch` 分支,不能push其它分支。"
|
5
|
-
|
6
|
-
setup do
|
7
|
-
|
8
|
-
# remember the working directory so we can come back to it later
|
9
|
-
cwd = Dir.pwd
|
10
|
-
# initialize another git repo to be used as a "remote"
|
11
|
-
tmpdir = Dir.mktmpdir
|
12
|
-
|
13
|
-
# local repo
|
14
|
-
repo.init
|
15
|
-
|
16
|
-
FileUtils.touch "file1"
|
17
|
-
repo.add "file1"
|
18
|
-
repo.commit_all "committed changes on master"
|
19
|
-
|
20
|
-
# copy the repo to remote
|
21
|
-
FileUtils.cp_r ".", tmpdir
|
22
|
-
|
23
|
-
# add another file. If successful this file won't be pushed to the remote repository
|
24
|
-
FileUtils.touch "file2"
|
25
|
-
repo.add "file2"
|
26
|
-
repo.commit_all "If this commit gets pushed to repo, then you have lost the level :( "
|
27
|
-
|
28
|
-
#This branch should not be pushed to to the remote repository
|
29
|
-
`git checkout -b other_branch --quiet`
|
30
|
-
# add another file
|
31
|
-
FileUtils.touch "file3"
|
32
|
-
repo.add "file3"
|
33
|
-
repo.commit_all "If this commit gets pushed to repo, then you have lost the level :( "
|
34
|
-
|
35
|
-
`git checkout -b test_branch --quiet`
|
36
|
-
|
37
|
-
#This file should get pushed if the level is successful
|
38
|
-
FileUtils.touch "file4"
|
39
|
-
repo.add "file4"
|
40
|
-
repo.commit_all "committed change on test_branch"
|
41
|
-
|
42
|
-
# remote repo
|
43
|
-
Dir.chdir tmpdir
|
44
|
-
|
45
|
-
repo.init
|
46
|
-
|
47
|
-
# make a 'non-bare' repo accept pushes
|
48
|
-
`git config receive.denyCurrentBranch ignore`
|
49
|
-
|
50
|
-
# change back to original repo to set up a remote
|
51
|
-
Dir.chdir cwd
|
52
|
-
`git remote add origin #{tmpdir}/.git`
|
53
|
-
`git fetch --quiet origin`
|
54
|
-
`git branch -u origin/master master
|
55
|
-
|
56
|
-
`git checkout master --quiet` #return to master branch
|
57
|
-
end
|
58
|
-
|
59
|
-
solution do
|
60
|
-
repo.init
|
61
|
-
result = false
|
62
|
-
|
63
|
-
#each branch consits of one line, `wc -l counts the number of lines in order to get the number of remote branches`
|
64
|
-
#At the moment Grit doesn't support remote branch references but is on the ToDo list. This should be revisited when Grit implements the change
|
65
|
-
num_remote_branches = `git branch -r`.split("\n").count
|
66
|
-
|
67
|
-
# counts the number of commits in the remote master branch'
|
68
|
-
remote_master_commits = repo.commits('origin/master').count
|
69
|
-
remote_test_branch_commits = repo.commits('origin/test_branch').count #if returns 0 indicates that the remote test_branch doesn't exist
|
70
|
-
|
71
|
-
#Level will be successful if the remote master branch remains at 1 commit, the remote test_branch exits and the number of remote branches
|
72
|
-
if remote_master_commits == 1 and remote_test_branch_commits > 0 and num_remote_branches == 2
|
73
|
-
result = true
|
74
|
-
|
75
|
-
#User pushed up too many branches, level failed
|
76
|
-
elsif num_remote_branches > 2
|
77
|
-
puts "*** It looks like you pushed up too many branches. You need to make sure only 'test_branch' gets pushed. Please try again! ***"
|
78
|
-
|
79
|
-
#User pushed up the master banch, level failed
|
80
|
-
elsif remote_master_commits > 1
|
81
|
-
puts "*** It looks like you pushed up new master branch changes. You need to make sure only 'test_branch' gets pushed. Please try again! ***"
|
82
|
-
end
|
83
|
-
|
84
|
-
result
|
85
|
-
end
|
86
|
-
|
87
|
-
hint do
|
88
|
-
puts "研究一下 `git push` 命令吧,可以使用 `git push --help`"
|
89
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
difficulty 2
|
3
|
+
description "你已经创建了本地分支 `test_branch`,开发已经完成,你需要将此分支 push 到远程代码库。
|
4
|
+
注意:只能push `test_branch` 分支,不能push其它分支。"
|
5
|
+
|
6
|
+
setup do
|
7
|
+
|
8
|
+
# remember the working directory so we can come back to it later
|
9
|
+
cwd = Dir.pwd
|
10
|
+
# initialize another git repo to be used as a "remote"
|
11
|
+
tmpdir = Dir.mktmpdir
|
12
|
+
|
13
|
+
# local repo
|
14
|
+
repo.init
|
15
|
+
|
16
|
+
FileUtils.touch "file1"
|
17
|
+
repo.add "file1"
|
18
|
+
repo.commit_all "committed changes on master"
|
19
|
+
|
20
|
+
# copy the repo to remote
|
21
|
+
FileUtils.cp_r ".", tmpdir
|
22
|
+
|
23
|
+
# add another file. If successful this file won't be pushed to the remote repository
|
24
|
+
FileUtils.touch "file2"
|
25
|
+
repo.add "file2"
|
26
|
+
repo.commit_all "If this commit gets pushed to repo, then you have lost the level :( "
|
27
|
+
|
28
|
+
#This branch should not be pushed to to the remote repository
|
29
|
+
`git checkout -b other_branch --quiet`
|
30
|
+
# add another file
|
31
|
+
FileUtils.touch "file3"
|
32
|
+
repo.add "file3"
|
33
|
+
repo.commit_all "If this commit gets pushed to repo, then you have lost the level :( "
|
34
|
+
|
35
|
+
`git checkout -b test_branch --quiet`
|
36
|
+
|
37
|
+
#This file should get pushed if the level is successful
|
38
|
+
FileUtils.touch "file4"
|
39
|
+
repo.add "file4"
|
40
|
+
repo.commit_all "committed change on test_branch"
|
41
|
+
|
42
|
+
# remote repo
|
43
|
+
Dir.chdir tmpdir
|
44
|
+
|
45
|
+
repo.init
|
46
|
+
|
47
|
+
# make a 'non-bare' repo accept pushes
|
48
|
+
`git config receive.denyCurrentBranch ignore`
|
49
|
+
|
50
|
+
# change back to original repo to set up a remote
|
51
|
+
Dir.chdir cwd
|
52
|
+
`git remote add origin #{tmpdir}/.git`
|
53
|
+
`git fetch --quiet origin`
|
54
|
+
`git branch -u origin/master master`
|
55
|
+
|
56
|
+
`git checkout master --quiet` #return to master branch
|
57
|
+
end
|
58
|
+
|
59
|
+
solution do
|
60
|
+
repo.init
|
61
|
+
result = false
|
62
|
+
|
63
|
+
#each branch consits of one line, `wc -l counts the number of lines in order to get the number of remote branches`
|
64
|
+
#At the moment Grit doesn't support remote branch references but is on the ToDo list. This should be revisited when Grit implements the change
|
65
|
+
num_remote_branches = `git branch -r`.split("\n").count
|
66
|
+
|
67
|
+
# counts the number of commits in the remote master branch'
|
68
|
+
remote_master_commits = repo.commits('origin/master').count
|
69
|
+
remote_test_branch_commits = repo.commits('origin/test_branch').count #if returns 0 indicates that the remote test_branch doesn't exist
|
70
|
+
|
71
|
+
#Level will be successful if the remote master branch remains at 1 commit, the remote test_branch exits and the number of remote branches
|
72
|
+
if remote_master_commits == 1 and remote_test_branch_commits > 0 and num_remote_branches == 2
|
73
|
+
result = true
|
74
|
+
|
75
|
+
#User pushed up too many branches, level failed
|
76
|
+
elsif num_remote_branches > 2
|
77
|
+
puts "*** It looks like you pushed up too many branches. You need to make sure only 'test_branch' gets pushed. Please try again! ***"
|
78
|
+
|
79
|
+
#User pushed up the master banch, level failed
|
80
|
+
elsif remote_master_commits > 1
|
81
|
+
puts "*** It looks like you pushed up new master branch changes. You need to make sure only 'test_branch' gets pushed. Please try again! ***"
|
82
|
+
end
|
83
|
+
|
84
|
+
result
|
85
|
+
end
|
86
|
+
|
87
|
+
hint do
|
88
|
+
puts "研究一下 `git push` 命令吧,可以使用 `git push --help`"
|
89
|
+
end
|
data/levels/rebase_conflict.rb
CHANGED
@@ -1,56 +1,68 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
difficulty 2
|
3
|
-
description "你需获取远程的最新代码,请让版本树尽量整洁(只有⼀个树⼲).过程中如果有冲突,请解决掉它!"
|
4
|
-
|
5
|
-
setup do
|
6
|
-
# remember the working directory so we can come back to it later
|
7
|
-
cwd = Dir.pwd
|
8
|
-
repo.init
|
9
|
-
|
10
|
-
# initialize another git repo to be used as a "remote"
|
11
|
-
# remote repo
|
12
|
-
tmpdir = Dir.mktmpdir
|
13
|
-
Dir.chdir tmpdir
|
14
|
-
repo.init
|
15
|
-
# make a 'non-bare' repo accept pushes
|
16
|
-
`git config receive.denyCurrentBranch ignore`
|
17
|
-
|
18
|
-
# add a different file and commit so remote and local would diverge
|
19
|
-
FileUtils.touch "file1"
|
20
|
-
repo.add "file1"
|
21
|
-
repo.commit_all "first commit"
|
22
|
-
|
23
|
-
# change back to original repo to set up a remote
|
24
|
-
Dir.chdir cwd
|
25
|
-
`git remote add origin #{tmpdir}/.git
|
26
|
-
`git fetch origin
|
27
|
-
`git branch -u origin/master master 2> /dev/null`
|
28
|
-
|
29
|
-
# 处理本地repo
|
30
|
-
`git pull origin master --quiet`
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
`
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
difficulty 2
|
3
|
+
description "你需获取远程的最新代码,请让版本树尽量整洁(只有⼀个树⼲).过程中如果有冲突,请解决掉它!"
|
4
|
+
|
5
|
+
setup do
|
6
|
+
# remember the working directory so we can come back to it later
|
7
|
+
cwd = Dir.pwd
|
8
|
+
repo.init
|
9
|
+
|
10
|
+
# initialize another git repo to be used as a "remote"
|
11
|
+
# remote repo
|
12
|
+
tmpdir = Dir.mktmpdir
|
13
|
+
Dir.chdir tmpdir
|
14
|
+
repo.init
|
15
|
+
# make a 'non-bare' repo accept pushes
|
16
|
+
`git config receive.denyCurrentBranch ignore`
|
17
|
+
|
18
|
+
# add a different file and commit so remote and local would diverge
|
19
|
+
FileUtils.touch "file1"
|
20
|
+
repo.add "file1"
|
21
|
+
repo.commit_all "first commit"
|
22
|
+
|
23
|
+
# change back to original repo to set up a remote
|
24
|
+
Dir.chdir cwd
|
25
|
+
`git remote add origin #{tmpdir}/.git`
|
26
|
+
`git fetch origin --quiet`
|
27
|
+
# `git branch -u origin/master master 2> /dev/null`
|
28
|
+
|
29
|
+
# 处理本地repo
|
30
|
+
`git pull origin master --quiet`
|
31
|
+
File.open("#{cwd}/file1", "a") do | f |
|
32
|
+
f.write "My Hello\n"
|
33
|
+
end
|
34
|
+
`git add file1`
|
35
|
+
`git commit -m "Second commit" --quiet`
|
36
|
+
|
37
|
+
Dir.chdir tmpdir
|
38
|
+
FileUtils.touch "file1"
|
39
|
+
File.open("#{tmpdir}/file1", "a") do | f |
|
40
|
+
f.write "My teammate say Hello\n"
|
41
|
+
end
|
42
|
+
`git add file1`
|
43
|
+
`git commit -m "Third commit" --quiet`
|
44
|
+
|
45
|
+
#制造冲突
|
46
|
+
Dir.chdir cwd
|
47
|
+
FileUtils.touch "file1"
|
48
|
+
File.open("#{cwd}/file1", "a") do | f |
|
49
|
+
f.write "Hello\n"
|
50
|
+
end
|
51
|
+
`git add file1`
|
52
|
+
`git commit -m "Forth commit" --quiet`
|
53
|
+
`git branch --set-upstream-to=origin/master master`
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
solution do
|
59
|
+
return false if 1 != repo.commits("master")[0].parents.length
|
60
|
+
|
61
|
+
txt = File.read("file1")
|
62
|
+
return false if txt =~ /[<>=|]/
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
hint do
|
67
|
+
puts "Take a look at `git fetch`, `git pull`, and `git rebase` 你的日志应该只有4条记录,并且file1的冲突已经解决"
|
68
|
+
end
|
data/lib/githug/version.rb
CHANGED