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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0650631b8e3a436a49338b44bc12d3d6afbd43f9
4
- data.tar.gz: 8d67f8de34e9206de5e895b732277be32db9fbca
3
+ metadata.gz: 61dc29f7d047b967bef140e5e246cf7e46f4d899
4
+ data.tar.gz: 0e614ae2c7eee8efef06f79ab1ed7407a823d2f1
5
5
  SHA512:
6
- metadata.gz: 531e4bd37129eee6bd74cb313642aa32a64a32241fef5cb084af0b550d18f837795ce2549a10c80f65510e59707c8c34bdabeae72b2ff98825980ae059a64f40
7
- data.tar.gz: 9843fd85ae72ba12760685d64e9df4503e69f1c636926207ea9758cbd3d8019248248668107729ce89e5954ff2e40122376a9843fc8302ec87a4615ee1c8122b
6
+ metadata.gz: ae34fccda3f5e25e7e98bf85cf759cd9dec9a34eefefe041a52a21460ba7ce0ec3cc6980025bcd0da5bdb856f8b69b217a4c0b861e54ec01fe900fed41f6e283
7
+ data.tar.gz: 1ead678ba4cb8a723223eb5ddc4fa0e162fb8dd5e66ccc5c5d2328e6a9d08d273ed85e3b56bed8564820dd7abb2f3e4d71f31b11c8e3eafa4e9ddf41ceaf092c
data/bin/mg CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'githug/cli'
3
3
 
4
+ STDOUT.sync = true
5
+
4
6
  Githug::CLI.start
@@ -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
- `echo "Hello" >> README`
12
- `git add file2.txt && echo "NEWlINE" >> file2.txt`
13
-
14
- end
15
-
16
- solution do
17
- return false unless repo.status.files.keys.include?("README")
18
- return false if repo.status.files["README"].untracked
19
- return false if "1" == request("在工作区(Workspace)与Stage之间,file2.txt有哪些变化:
20
- 1. 无变化
21
- 2. 增加了一行:NEWLINE
22
- ")
23
- "2" == request("在HEAD与Stage之间,file2.txt有哪些变化:
24
- 1. 无变化
25
- 2. 新增了文件file2.txt
26
- ")
27
- end
28
-
29
- hint do
30
- puts "你需要使用`git add` 和`git diff`命令。必要时加上`--cached`参数."
31
- end
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
@@ -1,60 +1,67 @@
1
- # -*- encoding : utf-8 -*-
2
- difficulty 1
3
- description "使⽤`git lg`来查看带有树形结构的提交记录. 使用`git fl`查看单个文件的提交记录和变更历史。"
4
-
5
- setup do
6
- repo.init
7
-
8
- FileUtils.touch "file1"
9
- repo.add "file1"
10
- repo.commit_all "committed changes on master"
11
-
12
- # add another file.
13
- FileUtils.touch "file2"
14
- repo.add "file2"
15
- repo.commit_all "add another file: file2"
16
-
17
- `git checkout -b other_branch --quiet`
18
- # add another file
19
- FileUtils.touch "file3"
20
- repo.add "file3"
21
- # `echo "hello" >> file2`
22
- # repo.add "file2"
23
- repo.commit_all "add another file: file3"
24
-
25
- # `git checkout -b test_branch --quiet`
26
-
27
- # FileUtils.touch "file4"
28
- # repo.add "file4"
29
- # repo.commit_all "committed change on test_branch"
30
-
31
- `git checkout master`
32
-
33
- FileUtils.touch "file5"
34
- repo.add "file5"
35
- repo.commit_all "add another file: file5"
36
-
37
- `git merge other_branch -m "merge other_branch"`
38
- # `git merge test_branch`
39
-
40
- end
41
-
42
- solution do
43
- valid = true
44
-
45
- config_alias_lg = repo.config["alias.lg"]
46
- config_alias_filelg = repo.config["alias.fl"]
47
-
48
- return false unless "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
49
- return false unless "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
50
-
51
- valid
52
- end
53
-
54
- hint do
55
- puts "增加两个别名:git lg 和git fl,分别如下:
56
- 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'
57
- 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'
58
-
59
- "
60
- end
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
@@ -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 && git branch -m hotfix --quiet`
9
- `git checkout master --quiet`
10
- end
11
-
12
- solution do
13
- return false unless repo.commits[1].message == "Added fancy branded output"
14
- return false unless repo.commits[0].message == "Filled in README.md with proper input"
15
- true
16
- end
17
-
18
- hint do
19
- puts "Sneak a peek at the `cherry-pick` command."
20
- end
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
@@ -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
- end
8
-
9
- solution do
10
- solved = true
11
-
12
- solved = false unless repo.head.name == "master"
13
- solved = false unless repo.commits("master")[0].parents.length == 2
14
-
15
- txt = File.read("poem.txt")
16
- solved = false if txt =~ /[<>=|]/
17
- solved = false unless txt =~ /Sat on a wall/
18
-
19
- solved
20
- end
21
-
22
- hint do
23
- puts ["首先,你要merge,然后解决冲突。最后别忘了commit."]
24
- end
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
@@ -1,23 +1,25 @@
1
- # -*- encoding : utf-8 -*-
2
- difficulty 2
3
-
4
- description "你需要提供最近一次提交的commit id,并找出新增的内容是什么。"
5
-
6
- setup do
7
- repo.init
8
- file = File.new("newfile.txt", "w")
9
- repo.add("newfile.txt")
10
-
11
- `echo "Hello" >> newfile.txt`
12
-
13
- repo.commit_all("THIS IS THE COMMIT YOU ARE LOOKING FOR!")
14
- end
15
-
16
- solution do
17
- repo.commits.last.id_abbrev == request("最近一次提交的commit id是多少?")[0..6]
18
- "Hello" == request("最近一次提交时,文件newfile.txt中新增的内容是什么?")
19
- end
20
-
21
- hint do
22
- puts "你需要查看提交日志."
23
- end
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
@@ -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
- # change back to original repo to set up a remote
24
- Dir.chdir cwd
25
- `git remote add origin #{tmpdir}/.git 2> /dev/null`
26
- `git fetch origin 2> /dev/null`
27
- `git branch -u origin/master master 2> /dev/null`
28
-
29
- # 处理本地repo
30
- `git pull origin master --quiet`
31
- `echo "Hello" >> file1 && git add file1 2> /dev/null && git commit -m "Second commit" 2> /dev/null`
32
-
33
- Dir.chdir tmpdir
34
- FileUtils.touch "file2"
35
- `echo "Hello" >> file2 && git add file2 2> /dev/null && git commit -m "Third commit" 2> /dev/null`
36
-
37
- Dir.chdir cwd
38
- FileUtils.touch "file3"
39
- `echo "Hello" >> file3 && git add file3 2> /dev/null && git commit -m "Forth commit" 2> /dev/null`
40
- `git branch --set-upstream-to=origin/master master 2> /dev/null`
41
-
42
- end
43
-
44
- solution do
45
- 1 == repo.commits("master")[0].parents.length
46
- end
47
-
48
- hint do
49
- puts "Take a look at `git fetch`, `git pull`, and `git push`."
50
- 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
+
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
@@ -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 2> /dev/null`
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
@@ -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 2> /dev/null`
26
- `git fetch origin 2> /dev/null`
27
- `git branch -u origin/master master 2> /dev/null`
28
-
29
- # 处理本地repo
30
- `git pull origin master --quiet`
31
- `echo "My Hello" >> file1 && git add file1 2> /dev/null && git commit -m "Second commit" 2> /dev/null`
32
-
33
- Dir.chdir tmpdir
34
- FileUtils.touch "file1"
35
- `echo "My teammate say Hello" >> file1 && git add file1 2> /dev/null && git commit -m "Third commit" 2> /dev/null`
36
-
37
- #制造冲突
38
- Dir.chdir cwd
39
- FileUtils.touch "file1"
40
- `echo "Hello" >> file1 && git add file1 2> /dev/null && git commit -m "Forth commit" 2> /dev/null`
41
- `git branch --set-upstream-to=origin/master master 2> /dev/null`
42
-
43
-
44
- end
45
-
46
- solution do
47
- return false if 1 != repo.commits("master")[0].parents.length
48
-
49
- txt = File.read("file1")
50
- return false if txt =~ /[<>=|]/
51
- true
52
- end
53
-
54
- hint do
55
- puts "Take a look at `git fetch`, `git pull`, and `git rebase` 你的日志应该只有4条记录,并且file1的冲突已经解决"
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
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Githug
3
- VERSION = "0.5.5"
3
+ VERSION = "0.5.6"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mygithug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Rennie & Mei Xuesong