m-git 2.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +85 -0
  4. data/lib/m-git.rb +66 -0
  5. data/lib/m-git/argv.rb +170 -0
  6. data/lib/m-git/argv/opt.rb +38 -0
  7. data/lib/m-git/argv/opt_list.rb +71 -0
  8. data/lib/m-git/argv/parser.rb +66 -0
  9. data/lib/m-git/base_command.rb +271 -0
  10. data/lib/m-git/command/add.rb +41 -0
  11. data/lib/m-git/command/branch.rb +90 -0
  12. data/lib/m-git/command/checkout.rb +106 -0
  13. data/lib/m-git/command/clean.rb +64 -0
  14. data/lib/m-git/command/commit.rb +84 -0
  15. data/lib/m-git/command/config.rb +202 -0
  16. data/lib/m-git/command/delete.rb +99 -0
  17. data/lib/m-git/command/fetch.rb +32 -0
  18. data/lib/m-git/command/forall.rb +81 -0
  19. data/lib/m-git/command/info.rb +74 -0
  20. data/lib/m-git/command/init.rb +324 -0
  21. data/lib/m-git/command/log.rb +73 -0
  22. data/lib/m-git/command/merge.rb +381 -0
  23. data/lib/m-git/command/pull.rb +364 -0
  24. data/lib/m-git/command/push.rb +311 -0
  25. data/lib/m-git/command/rebase.rb +348 -0
  26. data/lib/m-git/command/reset.rb +31 -0
  27. data/lib/m-git/command/self.rb +223 -0
  28. data/lib/m-git/command/stash.rb +189 -0
  29. data/lib/m-git/command/status.rb +135 -0
  30. data/lib/m-git/command/sync.rb +327 -0
  31. data/lib/m-git/command/tag.rb +67 -0
  32. data/lib/m-git/command_manager.rb +24 -0
  33. data/lib/m-git/error.rb +20 -0
  34. data/lib/m-git/foundation.rb +25 -0
  35. data/lib/m-git/foundation/constants.rb +107 -0
  36. data/lib/m-git/foundation/dir.rb +25 -0
  37. data/lib/m-git/foundation/duration_recorder.rb +92 -0
  38. data/lib/m-git/foundation/git_message_parser.rb +50 -0
  39. data/lib/m-git/foundation/lock.rb +32 -0
  40. data/lib/m-git/foundation/loger.rb +129 -0
  41. data/lib/m-git/foundation/mgit_config.rb +222 -0
  42. data/lib/m-git/foundation/operation_progress_manager.rb +139 -0
  43. data/lib/m-git/foundation/timer.rb +74 -0
  44. data/lib/m-git/foundation/utils.rb +361 -0
  45. data/lib/m-git/hooks_manager.rb +96 -0
  46. data/lib/m-git/manifest.rb +181 -0
  47. data/lib/m-git/manifest/cache_manager.rb +44 -0
  48. data/lib/m-git/manifest/internal.rb +182 -0
  49. data/lib/m-git/manifest/light_repo.rb +108 -0
  50. data/lib/m-git/manifest/light_repo_generator.rb +87 -0
  51. data/lib/m-git/manifest/linter.rb +153 -0
  52. data/lib/m-git/open_api.rb +427 -0
  53. data/lib/m-git/open_api/script_download_info.rb +37 -0
  54. data/lib/m-git/output/output.rb +461 -0
  55. data/lib/m-git/plugin_manager.rb +112 -0
  56. data/lib/m-git/repo.rb +133 -0
  57. data/lib/m-git/repo/status.rb +481 -0
  58. data/lib/m-git/repo/sync_helper.rb +254 -0
  59. data/lib/m-git/template.rb +9 -0
  60. data/lib/m-git/template/local_manifest.rb +27 -0
  61. data/lib/m-git/template/manifest_hook.rb +28 -0
  62. data/lib/m-git/template/post_download_hook.rb +29 -0
  63. data/lib/m-git/template/post_hook.rb +31 -0
  64. data/lib/m-git/template/pre_exec_hook.rb +31 -0
  65. data/lib/m-git/template/pre_hook.rb +29 -0
  66. data/lib/m-git/template/pre_push_hook.rb +32 -0
  67. data/lib/m-git/version.rb +6 -0
  68. data/lib/m-git/workspace.rb +648 -0
  69. data/lib/m-git/workspace/path_helper.rb +56 -0
  70. data/lib/m-git/workspace/workspace_helper.rb +159 -0
  71. data/m-git +1 -0
  72. data/mgit +19 -0
  73. metadata +218 -0
@@ -0,0 +1,56 @@
1
+
2
+ module MGit
3
+ class Workspace
4
+
5
+ # .mgit 目录下的文件路径
6
+ #
7
+ module PathHelper
8
+
9
+ # .mgit/config.yml
10
+ #
11
+ def config_file
12
+ File.join(root, Constants::MGIT_CONFIG_PATH)
13
+ end
14
+
15
+ # .mgit/hooks
16
+ #
17
+ def hooks_dir
18
+ File.join(root, Constants::PROJECT_DIR[:hooks])
19
+ end
20
+
21
+ # .mgit/snapshot
22
+ #
23
+ def snapshot_dir
24
+ File.join(root, Constants::PROJECT_DIR[:snapshot])
25
+ end
26
+
27
+ # .mgit/source-config
28
+ #
29
+ def source_config_dir
30
+ File.join(root, Constants::PROJECT_DIR[:source_config])
31
+ end
32
+
33
+ # .mgit/source-git
34
+ def source_git_dir
35
+ File.join(root, Constants::PROJECT_DIR[:source_git])
36
+ end
37
+ ########################### manifest ##########################
38
+
39
+ def manifest_path
40
+ manifest_name = Constants::CONFIG_FILE_NAME[:manifest]
41
+ File.join(source_config_dir, manifest_name)
42
+ end
43
+
44
+ def local_manifest_path
45
+ manifest_name = Constants::CONFIG_FILE_NAME[:local_manifest]
46
+ File.join(source_config_dir, manifest_name)
47
+ end
48
+
49
+ def cache_manifest_path
50
+ file_name = Constants::CONFIG_FILE_NAME[:manifest_cache]
51
+ File.join(source_config_dir, file_name)
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,159 @@
1
+ #coding=utf-8
2
+
3
+ module MGit
4
+ class Workspace
5
+ module WorkspaceHelper
6
+ # 弹出托管的.git实体
7
+ #
8
+ # @param root [String] mgit工程根目录
9
+ #
10
+ # @param light_repo [Manifest::LightRepo] 操作仓库的配置repo
11
+ #
12
+ def pop_git_entity(root, light_repo)
13
+ # 仓库工作区目录
14
+ repo_dir = light_repo.abs_dest(root)
15
+
16
+ # 仓库工作区.git软链接路径
17
+ workspace_git_link_path = File.join(repo_dir, '.git')
18
+
19
+ # 仓库.git实体托管路径
20
+ git_entity_path = File.join(light_repo.git_store_dir(root), '.git')
21
+
22
+ if Dir.exist?(git_entity_path) && Dir.exist?(workspace_git_link_path) && File.symlink?(workspace_git_link_path)
23
+ # 仓库工作区.git软链接指向路径
24
+ abs_link_point = File.join(repo_dir, File.readlink(workspace_git_link_path))
25
+
26
+ # 若指向路径就是.git实体托管路径,则删除工作区软链接,并把.git弹出
27
+ if Pathname.new(abs_link_point).realpath.to_s == git_entity_path
28
+ FileUtils.rm_f(workspace_git_link_path)
29
+ FileUtils.mv(git_entity_path, repo_dir)
30
+ end
31
+ end
32
+ end
33
+
34
+ # 压入(托管).git实体
35
+ #
36
+ # @param root [String] mgit工程根目录
37
+ #
38
+ # @param light_repo [Manifest::LightRepo] 操作仓库的配置repo
39
+ #
40
+ def push_git_entity(root, light_repo)
41
+ # 仓库工作区目录
42
+ repo_dir = light_repo.abs_dest(root)
43
+ git_store_dir = light_repo.git_store_dir(root)
44
+
45
+ # 仓库工作区.git实体路径
46
+ workspace_git_entity_path = File.join(repo_dir, '.git')
47
+
48
+ # 仓库.git实体托管路径
49
+ cache_git_entity_path = File.join(git_store_dir, '.git')
50
+
51
+ # 工作区.git存在,且mgit没有已存在的托管的.git
52
+ if Dir.exist?(workspace_git_entity_path) && !Dir.exist?(cache_git_entity_path)
53
+ # 移动并链接
54
+ Utils.link_git(repo_dir, git_store_dir)
55
+ end
56
+ end
57
+
58
+ # 将缓存的仓库移动到工作区
59
+ #
60
+ # @param root [String] mgit工程根目录
61
+ #
62
+ # @param light_repo [Manifest::LightRepo] 操作仓库的配置repo
63
+ #
64
+ def pop(root, light_repo)
65
+ cache_path = File.join(light_repo.cache_store_dir(root), light_repo.name)
66
+ workspace_path = light_repo.abs_dest(root)
67
+ workspace_dir = File.dirname(workspace_path)
68
+ return if invalid_move?(cache_path, workspace_dir)
69
+
70
+ if Dir.exist?(cache_path) && !Dir.exist?(workspace_path)
71
+
72
+ # 工作区目录不存在则创建
73
+ FileUtils.mkdir_p(workspace_dir) if !Dir.exist?(workspace_dir)
74
+
75
+ begin
76
+ # 【注意】 FileUtils.mv(a,b) 如果b路径的basename不存在,那么自动创建b并将【a文件夹内的所有文件】拷贝到b(b/<content of a>),如果basename存在,那么直接把a文件夹整个移动到b下(b/a/<content of a>)。
77
+ FileUtils.mv(cache_path, workspace_dir)
78
+ rescue => _
79
+ end
80
+ end
81
+ end
82
+
83
+ # 将工作区的仓库缓存起来
84
+ #
85
+ # @param root [String] mgit工程根目录
86
+ #
87
+ # @param light_repo [Manifest::LightRepo] 操作仓库的配置repo
88
+ #
89
+ def push(root, light_repo)
90
+ cache_dir = light_repo.cache_store_dir(root)
91
+ workspace_path = light_repo.abs_dest(root)
92
+ return if invalid_move?(workspace_path, cache_dir)
93
+
94
+ cache_path = File.join(cache_dir, light_repo.name)
95
+ if Dir.exist?(workspace_path)
96
+ # 缓存存在则删除缓存
97
+ FileUtils.rm_rf(cache_path) if Dir.exist?(cache_path)
98
+
99
+ # 缓存目录不存在则创建
100
+ FileUtils.mkdir_p(cache_dir) if !Dir.exist?(cache_dir)
101
+
102
+ begin
103
+ FileUtils.mv(workspace_path, cache_dir)
104
+ rescue => _
105
+ end
106
+ end
107
+ end
108
+
109
+ # 将工作区的仓库a替换为b
110
+ #
111
+ # @param root [String] mgit工程根目录
112
+ #
113
+ # @param light_repo_a [Manifest::LightRepo] 缓存仓库的配置repo
114
+ #
115
+ # @param light_repo_b [Manifest::LightRepo] 弹出仓库的配置repo
116
+ #
117
+ def replace(root, light_repo_a, light_repo_b)
118
+ push(root, light_repo_a)
119
+ pop(root, light_repo_b)
120
+ end
121
+
122
+ # 根据工作区仓库url和配置url来替换仓库
123
+ #
124
+ # @param root [String] mgit工程根目录
125
+ #
126
+ # @param light_repo [Manifest::LightRepo] 操作仓库的配置repo
127
+ #
128
+ def sync_workspace(root, light_repo)
129
+ name = light_repo.name
130
+ path = light_repo.abs_dest(root)
131
+
132
+ # 若工作区存在该仓库,且url与配置不匹配,则压入缓存,此时如果配置的url有对应缓存,则将其弹出
133
+ if Repo.is_git_repo?(path)
134
+ repo = Repo.new(name, path)
135
+ url = repo.status_checker.default_url
136
+ if !Utils.url_consist?(url, light_repo.url)
137
+ repo_config = Manifest::LightRepoGenerator.simple_init(name, path, url)
138
+ replace(root, repo_config, light_repo)
139
+ end
140
+
141
+ # 若工作区不存在该仓库,则弹出配置url对应缓存(如有缓存的话)
142
+ else
143
+ pop(root, light_repo)
144
+ end
145
+ end
146
+
147
+ # 判断是否可以移动目录,若目标目录包含源目录,则无法移动
148
+ #
149
+ # @param from_path [String] 源目录
150
+ #
151
+ # @param to_path [String] 目标目录
152
+ #
153
+ def invalid_move?(from_path, to_path)
154
+ return Pathname(to_path).cleanpath.to_s.include?(Pathname(from_path).cleanpath.to_s)
155
+ end
156
+
157
+ end
158
+ end
159
+ end
data/m-git ADDED
@@ -0,0 +1 @@
1
+ ./mgit
data/mgit ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby -W0
2
+ #coding=utf-8
3
+
4
+ #
5
+ # if $PROGRAM_NAME == __FILE__
6
+ # ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', __FILE__)
7
+ # require 'bundler/setup'
8
+ # end
9
+
10
+ require_relative 'lib/m-git'
11
+
12
+
13
+ module MGit
14
+ extend self
15
+
16
+ SRC_ROOT = __dir__
17
+ end
18
+
19
+ MGit.run(ARGV)
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: m-git
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.5.4
5
+ platform: ruby
6
+ authors:
7
+ - zhangyu81
8
+ autorequire:
9
+ bindir: "./"
10
+ cert_chain: []
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colored2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: peach
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-pager
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.12'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.17'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.17'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 5.14.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 5.14.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest-reporters
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.4.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.4.2
111
+ description: A multi-repository management tool integrated with git. for detail see
112
+ home page
113
+ email:
114
+ executables:
115
+ - mgit
116
+ - m-git
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - "./m-git"
121
+ - "./mgit"
122
+ - LICENSE
123
+ - README.md
124
+ - lib/m-git.rb
125
+ - lib/m-git/argv.rb
126
+ - lib/m-git/argv/opt.rb
127
+ - lib/m-git/argv/opt_list.rb
128
+ - lib/m-git/argv/parser.rb
129
+ - lib/m-git/base_command.rb
130
+ - lib/m-git/command/add.rb
131
+ - lib/m-git/command/branch.rb
132
+ - lib/m-git/command/checkout.rb
133
+ - lib/m-git/command/clean.rb
134
+ - lib/m-git/command/commit.rb
135
+ - lib/m-git/command/config.rb
136
+ - lib/m-git/command/delete.rb
137
+ - lib/m-git/command/fetch.rb
138
+ - lib/m-git/command/forall.rb
139
+ - lib/m-git/command/info.rb
140
+ - lib/m-git/command/init.rb
141
+ - lib/m-git/command/log.rb
142
+ - lib/m-git/command/merge.rb
143
+ - lib/m-git/command/pull.rb
144
+ - lib/m-git/command/push.rb
145
+ - lib/m-git/command/rebase.rb
146
+ - lib/m-git/command/reset.rb
147
+ - lib/m-git/command/self.rb
148
+ - lib/m-git/command/stash.rb
149
+ - lib/m-git/command/status.rb
150
+ - lib/m-git/command/sync.rb
151
+ - lib/m-git/command/tag.rb
152
+ - lib/m-git/command_manager.rb
153
+ - lib/m-git/error.rb
154
+ - lib/m-git/foundation.rb
155
+ - lib/m-git/foundation/constants.rb
156
+ - lib/m-git/foundation/dir.rb
157
+ - lib/m-git/foundation/duration_recorder.rb
158
+ - lib/m-git/foundation/git_message_parser.rb
159
+ - lib/m-git/foundation/lock.rb
160
+ - lib/m-git/foundation/loger.rb
161
+ - lib/m-git/foundation/mgit_config.rb
162
+ - lib/m-git/foundation/operation_progress_manager.rb
163
+ - lib/m-git/foundation/timer.rb
164
+ - lib/m-git/foundation/utils.rb
165
+ - lib/m-git/hooks_manager.rb
166
+ - lib/m-git/manifest.rb
167
+ - lib/m-git/manifest/cache_manager.rb
168
+ - lib/m-git/manifest/internal.rb
169
+ - lib/m-git/manifest/light_repo.rb
170
+ - lib/m-git/manifest/light_repo_generator.rb
171
+ - lib/m-git/manifest/linter.rb
172
+ - lib/m-git/open_api.rb
173
+ - lib/m-git/open_api/script_download_info.rb
174
+ - lib/m-git/output/output.rb
175
+ - lib/m-git/plugin_manager.rb
176
+ - lib/m-git/repo.rb
177
+ - lib/m-git/repo/status.rb
178
+ - lib/m-git/repo/sync_helper.rb
179
+ - lib/m-git/template.rb
180
+ - lib/m-git/template/local_manifest.rb
181
+ - lib/m-git/template/manifest_hook.rb
182
+ - lib/m-git/template/post_download_hook.rb
183
+ - lib/m-git/template/post_hook.rb
184
+ - lib/m-git/template/pre_exec_hook.rb
185
+ - lib/m-git/template/pre_hook.rb
186
+ - lib/m-git/template/pre_push_hook.rb
187
+ - lib/m-git/version.rb
188
+ - lib/m-git/workspace.rb
189
+ - lib/m-git/workspace/path_helper.rb
190
+ - lib/m-git/workspace/workspace_helper.rb
191
+ homepage: https://github.com/baidu/m-git
192
+ licenses:
193
+ - MIT
194
+ metadata:
195
+ allowed_push_host: https://rubygems.org
196
+ homepage_uri: https://github.com/baidu/m-git
197
+ source_code_uri: https://github.com/baidu/m-git/tree/master
198
+ changelog_uri: https://github.com/baidu/m-git/tree/master/CHANGELOG.md
199
+ post_install_message:
200
+ rdoc_options: []
201
+ require_paths:
202
+ - lib
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: 2.3.0
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ requirements: []
214
+ rubygems_version: 3.0.3
215
+ signing_key:
216
+ specification_version: 4
217
+ summary: A multi-repository management tool integrated with git.
218
+ test_files: []