ggsm 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edc278718389521b909307d6e17aa9c885a48dbb
4
- data.tar.gz: af4aaca2ad7a49360347f304dccf7fe75092760a
3
+ metadata.gz: 6047a2466f671d94d9ed1632af90fc1362c24a98
4
+ data.tar.gz: e171938265ea8db94e4b051e7ece45d1a9dec9e1
5
5
  SHA512:
6
- metadata.gz: 6131395780e5c21ac27c309ed2aea21891bd7f697c4babfcc74a7e1040e7f8b5a28a54ea6df981d29dbfda38383126221856fbfc61fc64d8b90685575d191b00
7
- data.tar.gz: 3884e4075320d1dd1607ebc01866a77399bef0399af6c6e877231dd9c8e9d75f2e8418e2663b8b2e2ab2b40b0b27278ab67e840b9b3bbd4ac01d0d9309a8de0e
6
+ metadata.gz: c2d39d480055c9ffcbc9ff9dc604ec7b6e635fc709b4c696a0a06e79fa1334729edff7a5d2f8bfe1fef1e1a47a9c2fa54e65391921c709aacded640453e0de91
7
+ data.tar.gz: be44fcddb27f8b8691f563124fc3dc3187db7993cabaa90479916ac53ec516f0b579e715fb4f997394ae813edf94a1e51ceb94cb9a91c7902ea3a7b6beb28949
data/README.md CHANGED
@@ -1,35 +1,28 @@
1
1
  # GGSM
2
- TODO
2
+ Gitsubmodule workflow
3
3
 
4
4
  ## Installation
5
5
 
6
- Add this line to your application's Gemfile:
7
-
8
- ```ruby
9
- gem 'ggsm'
10
- ```
11
-
12
- And then execute:
13
-
14
- $ bundle
15
-
16
- Or install it yourself as:
6
+ Install it yourself as:
17
7
 
18
8
  $ gem install ggsm
19
9
 
20
10
  ## Usage
21
-
22
- TODO: Write usage instructions here
23
-
24
- ## Development
25
-
26
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
-
28
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
11
+ ````
12
+ Commands:
13
+ ggsm [help] [COMMAND] # 帮助
14
+ ggsm sync # 同步(拉取)远程代码
15
+ ggsm start <branch> [<commit>] [<origin>] # 检出新分支,新功能、修bug务必使用该命令
16
+ ggsm switch <branch> # 切换分支
17
+ ggsm merge [<branch>] # Merge,开发完成后执行
18
+ ggsm finish # Merge后并解决冲突后执行
19
+ ggsm delete <branch> [-r|--remote] [-a|--all] # 删除指定分支
20
+ ggsm foreach [<commands>...] # 所有模块执行git命令(foreach后跟git命令)
21
+ ````
29
22
 
30
23
  ## Contributing
31
24
 
32
- Bug reports and pull requests are welcome on GitHub https://github.com/YoKeyword/ggsm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
25
+ Bug reports and pull requests are welcome on GitHub https://github.com/YoKeyword/ggsm. This project is intended to be a safe, welcoming space for collaboration.
33
26
 
34
27
 
35
28
  ## License
@@ -13,13 +13,9 @@ module GGSM
13
13
 
14
14
  delete_branch(all, branch, remote)
15
15
 
16
- subs = get_submodule
17
- subs.each do |sub|
18
- Dir.chdir sub
19
- puts "==> 进入#{sub}:".yellow
16
+ foreach_module {
20
17
  delete_branch(all, branch, remote)
21
- Dir.chdir '..'
22
- end
18
+ }
23
19
  end
24
20
 
25
21
  def delete_branch(all, branch, remote)
@@ -8,13 +8,9 @@ module GGSM
8
8
  def finish_flow
9
9
  check_submodule
10
10
 
11
- subs = get_submodule
12
- subs.each do |sub|
13
- Dir.chdir sub
14
- puts "==> 进入#{sub}:".yellow
11
+ foreach_module {
15
12
  system "git add .;git commit;git push origin #{get_current_branch}"
16
- Dir.chdir '..'
17
- end
13
+ }
18
14
 
19
15
  puts '==> 进入主工程:'.yellow
20
16
  system "git add .;git commit;git push origin #{get_current_branch}"
@@ -22,13 +22,9 @@ module GGSM
22
22
  cmd = "#{cmd} #{arg}"
23
23
  end
24
24
 
25
- subs = get_submodule
26
- subs.each do |sub|
27
- Dir.chdir sub
28
- puts "==> *进入#{sub}:".yellow
25
+ foreach_module {
29
26
  system "git #{cmd}"
30
- Dir.chdir '..'
31
- end
27
+ }
32
28
 
33
29
  puts '==> *进入主工程:'.yellow
34
30
  system "git #{cmd}"
@@ -11,13 +11,11 @@ module GGSM
11
11
 
12
12
  arry_conflict = []
13
13
 
14
- subs = get_submodule
15
- subs.each do |sub|
16
- Dir.chdir sub
14
+ foreach_module {|sub|
17
15
  process_merge(arry_conflict, sub, branch)
18
- Dir.chdir '..'
19
- end
16
+ }
20
17
 
18
+ puts '==> 进入主工程:'.yellow
21
19
  process_merge(arry_conflict, '主工程', branch)
22
20
  puts "Modules执行:git merge #{branch}".blue
23
21
 
@@ -31,7 +29,6 @@ module GGSM
31
29
  end
32
30
 
33
31
  def process_merge(arry_conflict, module_name, branch)
34
- puts "==> 进入#{module_name}:".yellow
35
32
  result_merge = `git merge #{branch}`
36
33
  puts result_merge
37
34
 
@@ -32,17 +32,13 @@ module GGSM
32
32
  return
33
33
  end
34
34
 
35
- subs = get_submodule
36
- subs.each do |sub|
37
- Dir.chdir sub
38
- puts "==> 进入#{sub}:".yellow
35
+ foreach_module {|sub|
39
36
  need_stash = try_stash
40
37
  system "git checkout -b #{branch}"
41
38
  if need_stash
42
39
  stash_pop(arry_conflict, sub)
43
40
  end
44
- Dir.chdir '..'
45
- end
41
+ }
46
42
 
47
43
  if arry_conflict.size > 0
48
44
  tip = "==> #{arry_conflict.size}个模块冲突:"
@@ -27,29 +27,9 @@ module GGSM
27
27
 
28
28
  sub_commits = get_submodule_commit
29
29
 
30
- subs = get_submodule
31
- subs.each do |sub|
32
- Dir.chdir sub
33
- puts "==> 进入#{sub}:".yellow
34
- need_stash = try_stash
35
- result = system "git checkout #{branch}"
36
-
37
- if result
38
- commit = sub_commits.fetch(subs.index(sub));
39
- commit_exist = system "git reset --hard #{commit}"
40
- unless commit_exist
41
- arry_commit_not_exist.push("==> #{sub}模块不存在远程commit:#{commit}")
42
- end
43
- else
44
- puts "[#{sub}] 没有#{branch}分支,创建并切换到#{branch}".blue
45
- system "git checkout -b #{branch}"
46
- end
47
-
48
- if need_stash
49
- stash_pop(arry_conflict, sub)
50
- end
51
- Dir.chdir '..'
52
- end
30
+ foreach_module {|sub, index|
31
+ process_switch(arry_commit_not_exist, arry_conflict, branch, index, sub, sub_commits)
32
+ }
53
33
 
54
34
  if arry_conflict.size > 0
55
35
  tip = "==> #{arry_conflict.size}个模块冲突:"
@@ -66,5 +46,25 @@ module GGSM
66
46
  tip_contact_author
67
47
  end
68
48
  end
49
+
50
+ def process_switch(commit_not_exist, arry_conflict, branch, index, sub, sub_commits)
51
+ need_stash = try_stash
52
+ result = system "git checkout #{branch}"
53
+
54
+ if result
55
+ commit = sub_commits.fetch(index);
56
+ commit_exist = system "git reset --hard #{commit}"
57
+ unless commit_exist
58
+ commit_not_exist.push("==> #{sub}模块不存在远程commit:#{commit}")
59
+ end
60
+ else
61
+ puts "[#{sub}] 没有#{branch}分支,创建并切换到#{branch}".blue
62
+ system "git checkout -b #{branch}"
63
+ end
64
+
65
+ if need_stash
66
+ stash_pop(arry_conflict, sub)
67
+ end
68
+ end
69
69
  end
70
70
  end
@@ -9,7 +9,7 @@ module GGSM
9
9
  end
10
10
 
11
11
  def get_submodule
12
- pattern = /(?<=\s)[0-9a-zA-Z]*(?=\s)/
12
+ pattern = /(?<=\s)[\/0-9a-zA-Z]*(?=\s)/
13
13
 
14
14
  sub_status = `git submodule`
15
15
  sub_status = sub_status.split(/\n/)
@@ -31,7 +31,13 @@ module GGSM
31
31
  end
32
32
 
33
33
  def get_submodule_commit
34
- sub_commits = `git ls-tree HEAD | grep "160000"`
34
+ sub_tree = 'git ls-tree HEAD | grep "160000"'
35
+ sub_commits = `#{sub_tree}`
36
+ if sub_commits.strip == '' && (File.directory? 'submodules')
37
+ Dir.chdir 'submodules'
38
+ sub_commits = `#{sub_tree}`
39
+ Dir.chdir '..'
40
+ end
35
41
  pattern = /(?<=\s)[0-9a-zA-Z]{40}(?=\s)/
36
42
  sub_commits = sub_commits.split(/\n/)
37
43
  result = []
@@ -44,6 +50,7 @@ module GGSM
44
50
 
45
51
  def check_un_commit_code
46
52
  subs = get_submodule
53
+ project_path = Dir.pwd
47
54
  subs.each do |sub|
48
55
  Dir.chdir sub
49
56
  status = `git status --ignore-submodules | grep 'nothing to commit'`
@@ -51,7 +58,7 @@ module GGSM
51
58
  puts "#{sub} 有未提交的代码".red
52
59
  exit 1
53
60
  end
54
- Dir.chdir '..'
61
+ Dir.chdir project_path
55
62
  end
56
63
 
57
64
  status = `git status --ignore-submodules | grep 'nothing to commit'`
@@ -61,6 +68,17 @@ module GGSM
61
68
  end
62
69
  end
63
70
 
71
+ def foreach_module
72
+ subs = get_submodule
73
+ project_path = Dir.pwd
74
+ subs.each do |sub|
75
+ Dir.chdir sub
76
+ puts "==> 进入#{sub}:".yellow
77
+ yield sub, subs.index(sub)
78
+ Dir.chdir project_path
79
+ end
80
+ end
81
+
64
82
  def get_current_branch
65
83
  `git branch | grep "*"`.split('* ')[1].split("\n")[0]
66
84
  end
data/lib/ggsm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GGSM
2
- VERSION = '1.3.0'
2
+ VERSION = '1.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ggsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - YoKey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-07 00:00:00.000000000 Z
11
+ date: 2017-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler