bigkeeper 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE.md +20 -0
  3. data/.gitignore +50 -0
  4. data/.travis.yml +17 -0
  5. data/CODE_OF_CONDUCT.md +46 -0
  6. data/CONTRIBUTING.md +70 -0
  7. data/Gemfile +10 -0
  8. data/Gemfile.lock +114 -0
  9. data/LICENSE +21 -0
  10. data/README.md +109 -0
  11. data/Rakefile +2 -0
  12. data/big_keeper.gemspec +47 -0
  13. data/bin/big +14 -0
  14. data/bin/setup +8 -0
  15. data/docs/en-US/FEATURE.md +0 -0
  16. data/docs/en-US/README.md +50 -0
  17. data/docs/zh-CN/BIGKEEPER_FILE.md +62 -0
  18. data/docs/zh-CN/FEATURE&HOTFIX.md +121 -0
  19. data/docs/zh-CN/PODFILE.md +43 -0
  20. data/docs/zh-CN/README.md +107 -0
  21. data/docs/zh-CN/RECOMMEND.md +22 -0
  22. data/docs/zh-CN/RELEASE.md +43 -0
  23. data/lib/big_keeper.rb +295 -0
  24. data/lib/big_keeper/command/feature&hotfix/delete.rb +33 -0
  25. data/lib/big_keeper/command/feature&hotfix/finish.rb +56 -0
  26. data/lib/big_keeper/command/feature&hotfix/pull.rb +24 -0
  27. data/lib/big_keeper/command/feature&hotfix/push.rb +25 -0
  28. data/lib/big_keeper/command/feature&hotfix/rebase.rb +27 -0
  29. data/lib/big_keeper/command/feature&hotfix/start.rb +67 -0
  30. data/lib/big_keeper/command/feature&hotfix/switch.rb +47 -0
  31. data/lib/big_keeper/command/feature&hotfix/update.rb +69 -0
  32. data/lib/big_keeper/command/pod/podfile.rb +69 -0
  33. data/lib/big_keeper/command/release/home.rb +66 -0
  34. data/lib/big_keeper/command/release/module.rb +106 -0
  35. data/lib/big_keeper/model/gitflow_type.rb +31 -0
  36. data/lib/big_keeper/model/operate_type.rb +19 -0
  37. data/lib/big_keeper/model/podfile_model.rb +33 -0
  38. data/lib/big_keeper/model/podfile_type.rb +44 -0
  39. data/lib/big_keeper/service/git_service.rb +186 -0
  40. data/lib/big_keeper/service/module_service.rb +124 -0
  41. data/lib/big_keeper/service/stash_service.rb +45 -0
  42. data/lib/big_keeper/util/bigkeeper_parser.rb +198 -0
  43. data/lib/big_keeper/util/git_operator.rb +142 -0
  44. data/lib/big_keeper/util/gitflow_operator.rb +51 -0
  45. data/lib/big_keeper/util/info_plist_operator.rb +46 -0
  46. data/lib/big_keeper/util/logger.rb +40 -0
  47. data/lib/big_keeper/util/pod_operator.rb +15 -0
  48. data/lib/big_keeper/util/podfile_detector.rb +108 -0
  49. data/lib/big_keeper/util/podfile_module.rb +64 -0
  50. data/lib/big_keeper/util/podfile_operator.rb +166 -0
  51. data/lib/big_keeper/util/xcode_operator.rb +13 -0
  52. data/lib/big_keeper/version.rb +3 -0
  53. data/resources/banner.png +0 -0
  54. data/resources/keynote/big-keeper-readme-example.key +0 -0
  55. data/resources/keynote/big-keeper-readme-feature.key +0 -0
  56. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.001.jpeg +0 -0
  57. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.002.jpeg +0 -0
  58. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.003.jpeg +0 -0
  59. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.004.jpeg +0 -0
  60. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.005.jpeg +0 -0
  61. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.006.jpeg +0 -0
  62. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.007.jpeg +0 -0
  63. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.008.jpeg +0 -0
  64. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.009.jpeg +0 -0
  65. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.010.jpeg +0 -0
  66. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.011.jpeg +0 -0
  67. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.012.jpeg +0 -0
  68. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.013.jpeg +0 -0
  69. data/resources/keynote/big-keeper-readme-feature/big-keeper-readme-feature.014.jpeg +0 -0
  70. data/resources/keynote/big-keeper-readme-release.key +0 -0
  71. data/resources/readme/big-keeper-readme.001.png +0 -0
  72. data/resources/readme/big-keeper-readme.002.png +0 -0
  73. data/resources/readme/big-keeper-readme.003.png +0 -0
  74. data/resources/readme/big-keeper-readme.004.png +0 -0
  75. data/resources/readme/big-keeper-readme.005.png +0 -0
  76. data/resources/readme/big-keeper-readme.006.png +0 -0
  77. data/resources/readme/big-keeper-readme.007.png +0 -0
  78. data/resources/readme/big-keeper-readme.008.png +0 -0
  79. data/resources/readme/big-keeper-readme.009.png +0 -0
  80. data/resources/readme/big-keeper-readme.010.png +0 -0
  81. data/resources/readme/big-keeper-readme.011.png +0 -0
  82. data/resources/readme/big-keeper-readme.012.png +0 -0
  83. metadata +311 -0
@@ -0,0 +1,31 @@
1
+ module BigKeeper
2
+ module GitflowType
3
+ FEATURE = 1
4
+ HOTFIX = 2
5
+ RELEASE = 3
6
+
7
+ def self.name(type)
8
+ if FEATURE == type
9
+ "feature"
10
+ elsif HOTFIX == type
11
+ "hotfix"
12
+ elsif RELEASE == type
13
+ "release"
14
+ else
15
+ "feature"
16
+ end
17
+ end
18
+
19
+ def self.base_branch(type)
20
+ if FEATURE == type
21
+ "develop"
22
+ elsif HOTFIX == type
23
+ "master"
24
+ elsif RELEASE == type
25
+ "develop"
26
+ else
27
+ "master"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module BigKeeper
2
+ module OperateType
3
+ START = 1
4
+ UPDATE = 2
5
+ SWITCH = 3
6
+
7
+ def self.name(type)
8
+ if START == type
9
+ "start"
10
+ elsif UPDATE == type
11
+ "update"
12
+ elsif SWITCH == type
13
+ "switch"
14
+ else
15
+ name
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+
2
+ module BigKeeper
3
+
4
+ class Podfile_Modle
5
+ attr_accessor :name,:git,:path,:configurations,:branch,:tag,:comment
6
+ def initialize(sentence)
7
+ if sentence.include?('#')
8
+ list = sentence.split('#')
9
+ @comment = list[1]
10
+ sentence = list[0]
11
+ end
12
+
13
+ sentence_slip_list = sentence.split(',')
14
+ return if sentence_slip_list.size.zero?
15
+ for piece in sentence_slip_list do
16
+ if /:git =>/ =~ piece
17
+ @git = $~.post_match.strip
18
+ elsif /:path =>/ =~ piece
19
+ @path = $~.post_match.strip
20
+ elsif /:configurations =>/ =~ piece
21
+ @configurations = $~.post_match.strip
22
+ elsif /:branch =>/ =~ piece
23
+ @branch = $~.post_match.strip
24
+ elsif /:tag =>/ =~ piece
25
+ @tag = $~.post_match.strip
26
+ elsif /pod /=~ piece
27
+ @name = $~.post_match.delete("'\n ")
28
+ end
29
+ # p %Q{model name:#{@name},git:#{@git},path:#{@path},config:#{@configurations},branch:#{@branch},tag:#{@tag},comment:#{@comment}}
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,44 @@
1
+ module BigKeeper
2
+ module ModuleType
3
+ PATH = 1
4
+ GIT = 2
5
+ SPEC = 3
6
+
7
+ def self.regex(type)
8
+ if PATH == type
9
+ "\s*:path\s*=>\s*"
10
+ elsif GIT == type
11
+ "\s*:git\s*=>\s*"
12
+ elsif SPEC == type
13
+ "\s*'"
14
+ else
15
+ name
16
+ end
17
+ end
18
+ end
19
+
20
+ module GitType
21
+ MASTER = 1
22
+ BRANCH = 2
23
+ TAG = 3
24
+ COMMIT = 4
25
+ end
26
+
27
+ class GitInfo
28
+ def initialize(base, type, addition)
29
+ @base, @type, @addition = base, type, addition
30
+ end
31
+
32
+ def type
33
+ @type
34
+ end
35
+
36
+ def base
37
+ @base
38
+ end
39
+
40
+ def addition
41
+ @addition
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,186 @@
1
+ require 'big_keeper/util/git_operator'
2
+ require 'big_keeper/model/gitflow_type'
3
+ require 'big_keeper/model/operate_type'
4
+ require 'big_keeper/util/logger'
5
+
6
+ module BigKeeper
7
+ # Operator for got
8
+ class GitService
9
+ def start(path, name, type)
10
+ git = GitOperator.new
11
+
12
+ branch_name = "#{GitflowType.name(type)}/#{name}"
13
+ if !git.has_remote_branch(path, branch_name) && !git.has_local_branch(path, branch_name)
14
+
15
+ verify_special_branch(path, 'master')
16
+ verify_special_branch(path, 'develop')
17
+
18
+ GitflowOperator.new.start(path, name, type)
19
+ git.push_to_remote(path, branch_name)
20
+ else
21
+ verify_checkout(path, branch_name)
22
+
23
+ if !git.has_remote_branch(path, branch_name)
24
+ git.push_to_remote(path, branch_name)
25
+ end
26
+ end
27
+ end
28
+
29
+ def verify_checkout(path, branch_name)
30
+ Dir.chdir(path) do
31
+ cmd = "git checkout -b #{branch_name}"
32
+ if GitOperator.new.has_branch(path, branch_name)
33
+ cmd = "git checkout #{branch_name}"
34
+ end
35
+ IO.popen(cmd) do |io|
36
+ io.each do |line|
37
+ Logger.error("Checkout #{branch_name} failed.") if line.include? 'error'
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def verify_special_branch(path, name)
44
+ git = GitOperator.new
45
+
46
+ if git.has_remote_branch(path, name)
47
+ if git.has_local_branch(path, name)
48
+ if git.has_commits(path, name)
49
+ Logger.error(%Q('#{name}' has unpushed commits, you should fix it manually...))
50
+ end
51
+ pull(path, name)
52
+ else
53
+ git.checkout(path, name)
54
+ end
55
+ else
56
+ verify_checkout(path, name)
57
+ git.push_to_remote(path, name)
58
+ end
59
+ end
60
+
61
+ def verify_home_branch(path, branch_name, type)
62
+ Logger.highlight('Sync local branchs from remote, waiting...')
63
+ git = GitOperator.new
64
+
65
+ git.fetch(path)
66
+
67
+ if OperateType::START == type
68
+ if git.current_branch(path) == branch_name
69
+ Logger.error(%(Current branch is '#{branch_name}' already. Use 'update' please))
70
+ end
71
+ if git.has_branch(path, branch_name)
72
+ Logger.error(%(Branch '#{branch_name}' already exists. Use 'switch' please))
73
+ end
74
+ elsif OperateType::SWITCH == type
75
+ if !git.has_branch(path, branch_name)
76
+ Logger.error(%(Can't find a branch named '#{branch_name}'. Use 'start' please))
77
+ end
78
+ if git.current_branch(path) == branch_name
79
+ Logger.error(%(Current branch is '#{branch_name}' already. Use 'update' please))
80
+ end
81
+ elsif OperateType::UPDATE == type
82
+ if !git.has_branch(path, branch_name)
83
+ Logger.error(%(Can't find a branch named '#{branch_name}'. Use 'start' please))
84
+ end
85
+ if git.current_branch(path) != branch_name
86
+ Logger.error(%(Current branch is not '#{branch_name}'. Use 'switch' please))
87
+ end
88
+ else
89
+ Logger.error(%(Not a valid command for '#{branch_name}'.))
90
+ end
91
+ end
92
+
93
+ def branchs_with_type(path, type)
94
+ branchs = []
95
+ Dir.chdir(path) do
96
+ IO.popen('git branch -a') do |io|
97
+ io.each do |line|
98
+ branchs << line.rstrip if line =~ /(\* | )#{GitflowType.name(type)}*/
99
+ end
100
+ end
101
+ end
102
+ branchs
103
+ end
104
+
105
+ def pull(path, branch_name)
106
+ git = GitOperator.new
107
+ current_branch_name = git.current_branch(path)
108
+ if current_branch_name == branch_name
109
+ git.pull(path)
110
+ else
111
+ git.checkout(path, branch_name)
112
+ git.pull(path)
113
+ git.checkout(path, current_branch_name)
114
+ end
115
+ end
116
+
117
+ def verify_del(path, branch_name, name, type)
118
+ git = GitOperator.new
119
+
120
+ if git.has_local_branch(path, branch_name)
121
+ Logger.highlight("Delete local branch '#{branch_name}' for '#{name}'...")
122
+
123
+ if git.current_branch(path) == branch_name
124
+ git.dicard(path)
125
+ git.checkout(path, GitflowType.base_branch(type))
126
+ end
127
+ git.del_local(path, branch_name)
128
+ end
129
+
130
+ if git.has_remote_branch(path, branch_name)
131
+ Logger.highlight("Delete remote branch '#{branch_name}' for '#{name}'...")
132
+ git.del_remote(path, branch_name)
133
+ end
134
+ end
135
+
136
+ def verify_push(path, comment, branch_name, name)
137
+ git = GitOperator.new
138
+ if git.has_changes(path) || git.has_commits(path, branch_name)
139
+
140
+ git.commit(path, comment) if git.has_changes(path)
141
+
142
+ if git.has_remote_branch(path, branch_name)
143
+ Dir.chdir(path) do
144
+ `git push`
145
+ end
146
+ else
147
+ git.push_to_remote(path, branch_name)
148
+ end
149
+ else
150
+ Logger.default("Nothing to push for '#{name}'.")
151
+ end
152
+ end
153
+
154
+ def verify_rebase(path, branch_name, name)
155
+
156
+ # pull rebased branch
157
+ pull(path, branch_name)
158
+
159
+ Dir.chdir(path) do
160
+ IO.popen("git rebase #{branch_name} --ignore-whitespace") do |io|
161
+ unless io.gets
162
+ Logger.error("#{name} is already in a rebase-apply, Please:\n\
163
+ 1.Resolve it;\n\
164
+ 2.Commit the changes;\n\
165
+ 3.Push to remote;\n\
166
+ 4.Create a MR;\n\
167
+ 5.Run 'finish' again.")
168
+ end
169
+ io.each do |line|
170
+ next unless line.include? 'Merge conflict'
171
+ Logger.error("Merge conflict in #{name}, Please:\n\
172
+ 1.Resolve it;\n\
173
+ 2.Commit the changes;\n\
174
+ 3.Push to remote;\n\
175
+ 4.Create a MR;\n\
176
+ 5.Run 'finish' again.")
177
+ end
178
+ end
179
+ if GitOperator.new.current_branch(path) != 'develop' && GitOperator.new.current_branch(path) != 'master'
180
+ `git push -f`
181
+ GitOperator.new.checkout(path, branch_name)
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,124 @@
1
+ require 'big_keeper/service/git_service'
2
+ require 'big_keeper/util/logger'
3
+
4
+ module BigKeeper
5
+ # Operator for got
6
+ class ModuleService
7
+
8
+ def verify_module(path, user, module_name, home_branch_name, type)
9
+ name = home_branch_name.gsub(/#{GitflowType.name(type)}\//, '')
10
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
11
+
12
+ git = GitOperator.new
13
+ if !File.exist? module_full_path
14
+ Logger.default("No local repository for module '#{module_name}', clone it...")
15
+ module_git = BigkeeperParser.module_git(module_name)
16
+ git.new.clone(File.expand_path("#{module_full_path}/../"), module_git)
17
+ end
18
+
19
+ current_branch_name = git.current_branch(module_full_path)
20
+ if current_branch_name != home_branch_name
21
+ # stash current branch
22
+ StashService.new.stash(module_full_path, current_branch_name, module_name)
23
+
24
+ GitService.new.start(module_full_path, name, type)
25
+
26
+ StashService.new.pop_stash(module_full_path, home_branch_name, module_name)
27
+ end
28
+ end
29
+
30
+ def push(path, user, module_name, home_branch_name, type, comment)
31
+ Logger.highlight("Push branch '#{home_branch_name}' for module '#{module_name}'...")
32
+
33
+ verify_module(path, user, module_name, home_branch_name, type)
34
+
35
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
36
+ GitService.new.verify_push(module_full_path, comment, home_branch_name, module_name)
37
+ end
38
+
39
+ def rebase(path, user, module_name, home_branch_name, type)
40
+ Logger.highlight("Rebase '#{GitflowType.base_branch(type)}'\
41
+ to branch '#{home_branch_name}' for module \
42
+ '#{module_name}'...")
43
+
44
+ verify_module(path, user, module_name, home_branch_name, type)
45
+
46
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
47
+
48
+ Logger.error("You have some changes in branch \
49
+ '#{home_branch_name}' for module '#{module_name}'. \
50
+ Use 'push' first please") if GitOperator.new.has_changes(module_full_path)
51
+
52
+ GitService.new.verify_rebase(module_full_path, GitflowType.base_branch(type), module_name)
53
+ end
54
+
55
+ def pull(path, user, module_name, home_branch_name, type)
56
+ Logger.highlight("Pull branch '#{home_branch_name}' for module '#{module_name}'...")
57
+
58
+ verify_module(path, user, module_name, home_branch_name, type)
59
+
60
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
61
+ GitOperator.new.pull(module_full_path)
62
+ end
63
+
64
+ def switch_to(path, user, module_name, home_branch_name, type)
65
+ Logger.highlight("Switch to branch '#{home_branch_name}' for module '#{module_name}'...")
66
+
67
+ verify_module(path, user, module_name, home_branch_name, type)
68
+ end
69
+
70
+ def finish(path, user, module_name, home_branch_name, type)
71
+ Logger.highlight("Finish branch '#{home_branch_name}' for module '#{module_name}'...")
72
+
73
+ verify_module(path, user, module_name, home_branch_name, type)
74
+
75
+ module_git = BigkeeperParser.module_git(module_name)
76
+ PodfileOperator.new.find_and_replace("#{path}/Podfile",
77
+ module_name,
78
+ ModuleType::GIT,
79
+ GitInfo.new(module_git, GitType::BRANCH, home_branch_name))
80
+
81
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
82
+
83
+ GitService.new.verify_push(module_full_path, "finish branch #{home_branch_name}", home_branch_name, module_name)
84
+
85
+ GitService.new.verify_rebase(module_full_path, GitflowType.base_branch(type), module_name)
86
+
87
+ `open #{BigkeeperParser.module_pulls(module_name)}`
88
+ end
89
+
90
+ def add(path, user, module_name, name, type)
91
+ home_branch_name = "#{GitflowType.name(type)}/#{name}"
92
+ Logger.highlight("Add branch '#{home_branch_name}' for module '#{module_name}'...")
93
+
94
+
95
+ verify_module(path, user, module_name, home_branch_name, type)
96
+
97
+ module_path = BigkeeperParser.module_path(user, module_name)
98
+ PodfileOperator.new.find_and_replace("#{path}/Podfile",
99
+ module_name,
100
+ ModuleType::PATH,
101
+ module_path)
102
+ end
103
+
104
+ def del(path, user, module_name, name, type)
105
+ home_branch_name = "#{GitflowType.name(type)}/#{name}"
106
+
107
+ Logger.highlight("Delete branch '#{home_branch_name}' for module '#{module_name}'...")
108
+
109
+ module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
110
+
111
+ StashService.new.stash(module_full_path, home_branch_name, module_name)
112
+
113
+ GitOperator.new.checkout(module_full_path, GitflowType.base_branch(type))
114
+ # GitOperator.new.del(module_full_path, home_branch_name)
115
+
116
+ module_git = BigkeeperParser.module_git(module_name)
117
+
118
+ PodfileOperator.new.find_and_replace("#{path}/Podfile",
119
+ module_name,
120
+ ModuleType::GIT,
121
+ GitInfo.new(module_git, GitType::BRANCH, GitflowType.base_branch(type)))
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,45 @@
1
+ require 'big_stash/stash_operator'
2
+ require 'big_keeper/util/bigkeeper_parser'
3
+ require 'big_keeper/util/git_operator'
4
+ require 'big_keeper/util/logger'
5
+
6
+ module BigKeeper
7
+ # Operator for got
8
+ class StashService
9
+ def pop_stash(path, branch_name, name)
10
+ # pop stash
11
+ if BigStash::StashOperator.new(path).stash_for_name(branch_name)
12
+ Logger.highlight(%Q(Branch '#{branch_name}' of '#{name}' has stash , start to pop...))
13
+ BigStash::StashOperator.new(path).pop_stash(branch_name)
14
+ end
15
+ end
16
+
17
+ def stash(path, branch_name, name)
18
+ # stash
19
+ if GitOperator.new.has_changes(path)
20
+ Logger.highlight(%Q(Branch '#{branch_name}' of '#{name}' needs stash , start to stash...))
21
+ BigStash::StashOperator.new(path).stash(branch_name)
22
+ end
23
+ end
24
+
25
+ def stash_all(path, new_branch_name, user, modules)
26
+ # Stash modules
27
+ Logger.highlight('Stash for current workspace...')
28
+
29
+ modules.each do |module_name|
30
+ module_path = BigkeeperParser.module_full_path(path, user, module_name)
31
+ branch_name = GitOperator.new.current_branch(module_path)
32
+
33
+ if branch_name != new_branch_name
34
+ stash(module_path, branch_name, module_name)
35
+ end
36
+ end
37
+
38
+ # Stash home
39
+ branch_name = GitOperator.new.current_branch(path)
40
+ if branch_name != new_branch_name
41
+ stash(path, branch_name, 'Home')
42
+ end
43
+ end
44
+ end
45
+ end