m-git 2.5.5 → 2.5.8

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
  SHA256:
3
- metadata.gz: 232bed3ac9b0a7f3afe26d8e7796ce9131b4e7c2880aaafcb063c3ba909d4d14
4
- data.tar.gz: 9f87f16862c5b7b63e7d37c46fcb4b84305794b93465b63c844c41851d999255
3
+ metadata.gz: 77220cb1407e06eff83ee8f4fe617c34355301b5928ce67d4c82c0ae23402d4c
4
+ data.tar.gz: 93a2f2eafc405eab27aaf420967e7a791c6e62baeba93e6c35efc847822d5b57
5
5
  SHA512:
6
- metadata.gz: 81c73e2475e07efbaa1ae6dd218797bbef22e0f8b79ab07965bcdbb902b08bb407d5c91967178fcc4361568f89884a4b952bb9669c2d7bd5bed4a9947913f889
7
- data.tar.gz: 2ac247bc413df36213b3dd3a0081893c416050f9cffc50cbd8df5494cfecb0955fdaf2ca37b86eb9219878d2753f7820fc787288fb0a22f4312c39f33e4ee0fb
6
+ metadata.gz: e0d257a7e6844cffbae5af66ed7584b7c828236555967101188eaf283e0591498a6c8494cefa2d5a492bef9692d6f51dd4450e28cc0c549e026af8cbeb7604e4
7
+ data.tar.gz: ead3235aae1f1f720da6ae6466107393f74e7668990fcc649aa8f8157e81a04af6610a112fdb204b213f86d596293864f2f04193d9d3ab0457335271f5c25c7d
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # MGit
2
2
 
3
- MGit 是一款 Ruby 封装的基于 Git 的多仓库管理工具,可以高效的、同时的对多个 Git 仓库执行 Git 命令。
4
- 适合于在多个仓库中进行关联开发的项目,提高 Git 操作的效率,避免逐个执行 Git 命令带来的误操作风险。
3
+ MGit是一款ruby封装的基于Git的多仓库管理工具,可以高效的、同时的对多个Git仓库执行Git命令。
4
+ 适合于在多个仓库中进行关联开发的项目,提高git操作的效率,避免逐个执行Git命令带来的误操作风险。
5
5
 
6
6
  - **易用的命令**
7
- 封装 Git 命令,命令和参数均由 Git 衍生而来,会使用 Git 就可以成本低上手 MGit。
7
+ 封装Git命令,命令和参数均由Git衍生而来,会使用Git就可以成本低上手MGit。
8
8
 
9
9
  - **直观高效的执行命令**
10
10
  提供图表化的结果展示,开发者可以快速查看命令在多个仓库的执行结果;
@@ -12,20 +12,20 @@ MGit 是一款 Ruby 封装的基于 Git 的多仓库管理工具,可以高效
12
12
 
13
13
  - **安全的执行命令**
14
14
  在执行命令前对多仓库状态进行安全检查:分支是否异常,工作区是否未提交代码等;
15
- 对 .git 进行托管与 Git 工作区分类,避免误删丢失改动或提交;
15
+ 对.git进行托管与Git工作区分类,避免误删丢失改动或提交;
16
16
  执行存在风险的操作时,会给与风险操作提示,避免误操作;
17
17
 
18
18
  - **方便扩展**
19
- 支持加载 ruby-gem 包作为插件,gem 包名格式 `m-git-${suffix}`和`mgit-${suffix}`
20
- 快速的扩展 MGit 的命令,增加自定义命令,扩展已有命令的功能;
21
- 提供类似`git hook`的 hook 点,方便开发者实现自定义逻辑;
19
+ 支持加载ruby-gem包作为插件,gem包名格式 `m-git-${suffix}`和`mgit-${suffix}`
20
+ 快速的扩展MGit的命令,增加自定义命令,扩展已有命令的功能;
21
+ 提供类似`git hook`的 hook点,方便开发者实现自定义逻辑;
22
22
 
23
23
  ## 快速开始
24
- #### 1、安装 MGit 工具
24
+ #### 1、安装MGit工具
25
25
 
26
26
  环境要求:
27
27
 
28
- - 系统:支持 macOS、Ubuntu,暂时不支持 Windows
28
+ - 系统:支持 macOS、Ubuntu,暂时不支持 window-
29
29
  - Ruby版本: >= 2.3.7
30
30
 
31
31
  ```ruby
@@ -38,45 +38,21 @@ $ gem install m-git
38
38
 
39
39
  类似于 Git 从远程 clone 新仓库, 会将多个仓库 clone 到本地;
40
40
 
41
- 下面通过一个 demo 体验一下 MGit 命令:
41
+ 下面通过一个demo体验一下MGit命令:
42
42
 
43
43
  ```ruby
44
44
  # 2.1 建议在一个新文件夹中拉取demo
45
45
  $ mgit init -g https://github.com/baidu/m-git.git
46
46
 
47
47
  # 2.2 体验一下mgit命令
48
- $ mgit -l 显示所有mgit管理的仓库
48
+ $ mgit -l 显示所有migt管理的仓库
49
49
  $ mgit branch --compact 查看多仓库的分支
50
50
  $ mgit status 产看仓库分支超前/落后情况
51
51
  ```
52
52
 
53
53
 
54
- #### 3、已有多仓库如何迁移到 MGit 管理
55
54
 
56
- - 根据文档[配置 manifest.json](docs/config/manifest.md)
57
-
58
- 将要管理的仓库都配置到 manifest.json 中
59
-
60
- - 将 manifest.json 放到一个仓库中管理
61
-
62
- 这个仓库同样会在 manifest.json 中描述,并且需要配置 "config-repo": true
63
-
64
- 这个仓库称为配置仓库,也叫做**主仓库**,其他仓库叫做**子仓库**
65
-
66
- - 使用 `mgit init -f manifest文件路径` 初始化多仓库,命令测试 manifest.json 配置是否正常
67
-
68
- 注意这个命令不会重复拉取主仓库,只会拉取所有的子仓库到当前目录,并在当前目录创建一个.mgit
69
-
70
- 你可以在当前目录中看到每个仓库的源码,他们的路径可以通过 manifest.json 的 dest字段配置
71
-
72
- 你也可以在 .mgit/source-git/ 下看到所有仓库的.git, 这是 MGit 对所有仓库的托管
73
-
74
- - 本地测试成功后,你可以提交主仓库中的 manifest.json,推送主仓库的变更到远端
75
-
76
- - 通过 `mgit init -g 主仓库地址` 命令初始化多仓库
77
-
78
-
79
- #### 4、进一步了解 MGit
55
+ #### 3、进一步了解MGit
80
56
 
81
57
  [常用命令](docs/use/common-commands.md)
82
58
 
@@ -84,26 +60,24 @@ $ mgit status 产看仓库分支超前/落后情况
84
60
 
85
61
  [配置多仓库](docs/config/config-env.md)
86
62
 
87
- [使用 MGit 管理多仓库的案例](docs/use/how-to-start.md#4-mgit-)
88
-
89
63
  [了解更多](docs/references.md)
90
64
 
91
65
 
92
66
  ## 测试
93
67
 
94
68
  单测在MGit仓库内的test文件夹下
95
- 新建单测文件,必须以‘test_’开头
69
+ 新建单测文件,必须以‘test_’开头,
96
70
  执行单测:rake (如果报错尝试执行 bundle install)
97
71
 
98
72
 
99
73
  ## 如何贡献
100
74
 
101
- 欢迎开发者向 MGit 贡献代码。如果您开发了新功能或发现了 bug,欢迎给我们提交PR。
75
+ 欢迎开发者向MGit贡献代码。如果您开发了新功能或发现了bug,欢迎给我们提交PR。
102
76
 
103
77
  代码贡献要求:
104
78
  1. 功能和实现应该具有通用性, 不是为了解决某个具体业务而定制的代码逻辑
105
- 2. 代码质量高,符合 Ruby 编码规范
106
- 3. 需要补充对应的单测 case
79
+ 2. 代码质量高,符合Ruby编码规范
80
+ 3. 需要补充对应的单测case
107
81
 
108
82
  issues贡献: 如在使用中遇到问题,请在 https://github.com/baidu/m-git/issues 新建 issues 反馈问题。
109
83
 
@@ -297,7 +297,7 @@ module MGit
297
297
  def move_project_to_root
298
298
  Dir.foreach(Workspace.root) { |item|
299
299
  if item != '.' && item != '..' && item != '.DS_Store'
300
- FileUtils.mv(File.join(Workspace.root, item), @origin_root)
300
+ FileUtils.mv(File.join(Workspace.root, item), @origin_root, force: true)
301
301
  end
302
302
  }
303
303
  FileUtils.remove_dir(Workspace.root, true) if Dir.exist?(Workspace.root)
@@ -23,10 +23,10 @@ module MGit
23
23
  def options
24
24
  [
25
25
  ARGV::Opt.new(OPT_LIST[:gerrit],
26
- info:"开启gerrit功能,如果没有对应远程分支则推送新分支,否则推送到审查分支(refs/for/**),默认未开启",
26
+ info:"开启gerrit功能,如果没有对应远程分支则推送新分支,否则推送到审查分支(refs/for/**),默认#{MGIT_PUSH_GERRIT_ENABLED ? '已开启' : '未开启' }",
27
27
  type: :boolean),
28
28
  ARGV::Opt.new(OPT_LIST[:topic_id],
29
- info:"指定一组变更的分类topic,若未指定则自动生成,默认未开启,开启后强制开启Gerrit功能。mgit push --topic 12345 = git push origin HEAD:refs/for/<branch>%topic=12345",
29
+ info:"指定一组变更的分类topic,若未指定则自动生成,默认#{MGIT_PUSH_TOPIC_ENABLED ? '已开启' : '未开启'},开启后强制开启Gerrit功能。mgit push --topic 12345 = git push origin HEAD:refs/for/<branch>%topic=12345",
30
30
  type: :string),
31
31
  ].concat(super)
32
32
  end
@@ -77,7 +77,8 @@ module MGit
77
77
  REPO_CONFIG_LOCK_KEY = {
78
78
  :branch => 'branch',
79
79
  :commit_id => 'commit-id',
80
- :tag => 'tag'
80
+ :tag => 'tag',
81
+ :change_ref => 'change-ref'
81
82
  }.freeze
82
83
 
83
84
  SNAPSHOT_KEY = {
@@ -179,7 +179,7 @@ module MGit
179
179
  #
180
180
  def __load_file(root)
181
181
  config_path = File.join(root, Constants::MGIT_CONFIG_PATH)
182
- if File.exists?(config_path)
182
+ if File.exist?(config_path)
183
183
  begin
184
184
  return YAML.load_file(config_path), nil
185
185
  rescue => e
@@ -83,7 +83,7 @@ module MGit
83
83
  # block
84
84
  def __execute_hook_file(file_name, hook_class)
85
85
  file_path = File.join(Workspace.hooks_dir, file_name)
86
- if File.exists?(file_path)
86
+ if File.exist?(file_path)
87
87
  require file_path
88
88
  end
89
89
  if Object.const_defined?(hook_class) && hook = Object.const_get(hook_class)
@@ -19,6 +19,9 @@ module MGit
19
19
  # [String] 仓库配置分支
20
20
  :branch,
21
21
 
22
+ # [String] 未合入的提交 change ref
23
+ :change_ref,
24
+
22
25
  # [String] 仓库配置commit id
23
26
  :commit_id,
24
27
 
@@ -16,7 +16,7 @@ module MGit
16
16
  # @return [LightRepo] 配置对象
17
17
  #
18
18
  def self.simple_init(name, path, url)
19
- LightRepo.new(name, path, nil, nil, nil, url, false, false, false, false)
19
+ LightRepo.new(name, path, nil, nil, nil, nil, url, false, false, false, false)
20
20
  end
21
21
 
22
22
  def self.light_repo_with(name, config_json, parent_json)
@@ -30,6 +30,7 @@ module MGit
30
30
  light_repo.commit_id = lock_info[Constants::REPO_CONFIG_LOCK_KEY[:commit_id]]
31
31
  light_repo.tag = lock_info[Constants::REPO_CONFIG_LOCK_KEY[:tag]]
32
32
  light_repo.branch = lock_info[Constants::REPO_CONFIG_LOCK_KEY[:branch]]
33
+ light_repo.change_ref = lock_info[Constants::REPO_CONFIG_LOCK_KEY[:change_ref]]
33
34
  end
34
35
  light_repo.url = __parse_url(config_json, parent_json)
35
36
 
@@ -12,7 +12,7 @@ module MGit
12
12
  def lint_manifest_path(path)
13
13
  manifest_name = Constants::CONFIG_FILE_NAME[:manifest]
14
14
 
15
- if !File.exists?(path)
15
+ if !File.exist?(path)
16
16
  if File.symlink?(path)
17
17
  terminate!("配置文件软链接#{path}失效,请执行\"mgit config -m <new_path>/manifest.json\"更新!")
18
18
  else
@@ -59,7 +59,7 @@ module MGit
59
59
  with_name ||= plugin_root
60
60
  glob = "#{plugin_prefix}_plugin#{Gem.suffix_pattern}"
61
61
  glob = File.join(plugin_root, '**', glob)
62
- plugin_files = Dir[glob].map { |f| f.untaint }
62
+ plugin_files = Dir[glob]
63
63
  return if loaded_plugins[with_name] || plugin_files.nil? || plugin_files.empty?
64
64
  safe_activate_plugin_files(with_name, plugin_files)
65
65
  loaded_plugins[with_name] = plugin_files
@@ -70,6 +70,7 @@ module MGit
70
70
  def self.load_gem_plugins(plugin_prefix)
71
71
  glob = "#{plugin_prefix}_plugin#{Gem.suffix_pattern}"
72
72
  gem_plugins = Gem::Specification.latest_specs.map do |spec|
73
+ spec = spec.to_spec unless spec.is_a?(Gem::Specification)
73
74
  matches = spec.matches_for_glob(glob)
74
75
  [spec, matches] unless matches.empty?
75
76
  end.compact
@@ -91,7 +92,7 @@ module MGit
91
92
  message << "\n#{exception.class} - #{exception.message}"
92
93
  message << "\n#{exception.backtrace.join("\n")}"
93
94
  message << "\n---------------------------------------------\n"
94
- warn message.ansi.yellow
95
+ warn message
95
96
  false
96
97
  end
97
98
 
@@ -104,7 +105,7 @@ module MGit
104
105
  message << "\n#{exception.class} - #{exception.message}"
105
106
  message << "\n#{exception.backtrace.join("\n")}"
106
107
  message << "\n---------------------------------------------\n"
107
- warn message.ansi.yellow
108
+ warn message
108
109
  false
109
110
  end
110
111
 
@@ -134,6 +134,8 @@ module MGit
134
134
  return sync_tag(repo, light_repo)
135
135
  elsif !light_repo.branch.nil?
136
136
  return sync_branch(repo, light_repo)
137
+ elsif !light_repo.change_ref.nil?
138
+ return sync_change_ref(repo, light_repo)
137
139
  end
138
140
  end
139
141
 
@@ -210,6 +212,45 @@ module MGit
210
212
 
211
213
  end
212
214
 
215
+ # 同步 change ref
216
+ #
217
+ # @param repo [Repo] Repo对象
218
+ #
219
+ # @param light_repo [Manifest::LightRepo] LightRepo对象
220
+ #
221
+ # @return [Boolean] 执行结果,成功返回nil,错误返回错误信息
222
+ #
223
+ def sync_change_ref(repo, light_repo)
224
+ current_branch = repo.status_checker.current_branch(strict_mode:false)
225
+ local_branch_exist = repo.status_checker.local_branch_exist?(light_repo.branch)
226
+ remote_branch_exist = repo.status_checker.remote_branch_exist?(light_repo.branch)
227
+ is_dirty = repo.status_checker.status == Status::GIT_REPO_STATUS[:dirty]
228
+
229
+ # 当前已在目标切换分支则不操作
230
+ if current_branch == light_repo.branch
231
+ return nil
232
+ # 本地或远程存在目标分支则切换
233
+ # elsif local_branch_exist || remote_branch_exist || Utils.branch_exist_on_remote?(light_repo.branch, light_repo.url)
234
+
235
+ else
236
+ # return "仓库change_ref \"#{light_repo.change_ref}\"不存在,请检查是否拼写错误!"
237
+ # 本地无目标分支则先拉取
238
+ if !local_branch_exist && !remote_branch_exist
239
+ success, error = repo.execute_git_cmd('fetch origin', light_repo.change_ref)
240
+ puts error
241
+ return error if !success
242
+ end
243
+
244
+ if !is_dirty
245
+ success, output = repo.execute_git_cmd('checkout', 'FETCH_HEAD')
246
+ puts output
247
+ return output if !success
248
+ else
249
+ return "本地有改动, 无法切换到\"#{light_repo.change_ref}\", 请处理后重试!"
250
+ end
251
+ end
252
+ end
253
+
213
254
  # 同步remote url
214
255
  #
215
256
  # @param repo [Repo] Repo对象
data/lib/m-git/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module MGit
3
- VERSION = "2.5.5".freeze
3
+ VERSION = "2.5.8".freeze
4
4
  end
5
5
 
6
6
 
data/m-git CHANGED
@@ -1 +1 @@
1
- ./mgit
1
+ mgit
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: m-git
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.5
4
+ version: 2.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - zhangyu81
8
8
  autorequire:
9
9
  bindir: "./"
10
10
  cert_chain: []
11
- date: 2021-08-12 00:00:00.000000000 Z
11
+ date: 2023-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: logger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.4.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.4.2
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +84,16 @@ dependencies:
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ">="
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 12.3.3
89
+ version: '10.0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 12.3.3
96
+ version: '10.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: minitest
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -211,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
225
  - !ruby/object:Gem::Version
212
226
  version: '0'
213
227
  requirements: []
214
- rubygems_version: 3.0.3
228
+ rubygems_version: 3.4.13
215
229
  signing_key:
216
230
  specification_version: 4
217
231
  summary: A multi-repository management tool integrated with git.