commit-updater 0.4.0__tar.gz → 0.6.0__tar.gz

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.
@@ -44,16 +44,25 @@ class ComponentGitFinder:
44
44
  normalized_paths.append(normalized_path)
45
45
  return normalized_paths
46
46
 
47
- def _extract_pathes_body(self, content: str) -> Optional[str]:
47
+ @staticmethod
48
+ def _extract_pathes_body(content: str) -> Optional[str]:
48
49
  """
49
50
  Extract text inside :pathes => [ ... ].
50
51
  Handles multiline arrays and nested brackets safely.
51
52
  """
52
- match = self.PATHES_START_PATTERN.search(content)
53
+ match = ComponentGitFinder.PATHES_START_PATTERN.search(content)
53
54
  if not match:
54
55
  return None
55
56
 
56
57
  start_idx = match.end() - 1 # index of '['
58
+ return ComponentGitFinder._extract_bracket_body(content, start_idx)
59
+
60
+ @staticmethod
61
+ def _extract_bracket_body(content: str, start_idx: int) -> Optional[str]:
62
+ """
63
+ Extract text between the bracket at start_idx and its matching bracket.
64
+ Handles multiline arrays and nested brackets safely.
65
+ """
57
66
  bracket_depth = 0
58
67
  in_single_quote = False
59
68
  in_double_quote = False
@@ -90,7 +99,8 @@ class ComponentGitFinder:
90
99
 
91
100
  return None
92
101
 
93
- def _strip_ruby_comments(self, text: str) -> str:
102
+ @staticmethod
103
+ def _strip_ruby_comments(text: str) -> str:
94
104
  """
95
105
  Strip '#' comments from ruby snippet, ignoring hashes inside quotes.
96
106
  """
@@ -0,0 +1,375 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: UTF-8 -*-
3
+ """
4
+ @Project :BBScriptToolBundle
5
+ @File :LocalModulesUpdater.py
6
+ @Author :Aron
7
+ """
8
+ import os
9
+ import re
10
+ import subprocess
11
+ from typing import List, Optional, Tuple
12
+
13
+ from CommitUpdater.ComponentGitFinder import ComponentGitFinder
14
+
15
+
16
+ class MemberConfigParser:
17
+ """解析成员配置文件:提取 :pathes 搜索路径与 :method => LOCAL 的组件条目"""
18
+
19
+ QUOTED_PATTERN = re.compile(r"""['"]([^'"]+)['"]""")
20
+ CONFIG_DEF_PATTERN = re.compile(r"def\s+(\w+_config)\b")
21
+ MODULES_DEF_PATTERN = re.compile(r"def\s+(\w+_modules)\b")
22
+ CONFIG_NAME_PATTERN = re.compile(r":name\s*=>\s*:(\w+)")
23
+ METHOD_PATTERN = re.compile(r":method\s*=>\s*(\w+)")
24
+ EXPLICIT_PATH_PATTERN = re.compile(r":path\s*=>\s*['\"]([^'\"]+)['\"]")
25
+
26
+ LOCAL = "LOCAL"
27
+
28
+ def __init__(self, file_path: str):
29
+ self.file_path = file_path
30
+ try:
31
+ with open(file_path, "r", encoding="utf-8") as f:
32
+ self.content = f.read()
33
+ except (OSError, UnicodeDecodeError):
34
+ self.content = ""
35
+
36
+ def config_name(self) -> Optional[str]:
37
+ """配置里 :name => :xxx 的成员名,用于对应同名 xxx_modules 方法"""
38
+ match = self.CONFIG_NAME_PATTERN.search(self.content)
39
+ return match.group(1) if match else None
40
+
41
+ def config_pathes(self) -> List[str]:
42
+ """提取 :pathes => [ ... ](兼容多行/嵌套括号/引号内#),返回本机路径列表"""
43
+ body = ComponentGitFinder._extract_pathes_body(self.content)
44
+ if body is None:
45
+ return []
46
+ stripped = ComponentGitFinder._strip_ruby_comments(body)
47
+ return [
48
+ os.path.abspath(os.path.expanduser(path.strip()))
49
+ for path in self.QUOTED_PATTERN.findall(stripped)
50
+ ]
51
+
52
+ def local_module_entries(self) -> List[Tuple[str, Optional[str]]]:
53
+ """解析生效条目(剥离注释后),返回 [(仓库名, 显式:path或None)];子 Pod 名取首段"""
54
+ modules_match = self.MODULES_DEF_PATTERN.search(self.content)
55
+ if not modules_match:
56
+ return []
57
+ body = self.content[modules_match.end():]
58
+ # 方法体截断到下一个顶格 def,避免把其他方法内容卷进来
59
+ next_def = re.search(r"^def\s", body, re.MULTILINE)
60
+ if next_def:
61
+ body = body[:next_def.start()]
62
+ body = ComponentGitFinder._strip_ruby_comments(body)
63
+
64
+ entries: List[Tuple[str, Optional[str]]] = []
65
+ for block in self._split_hash_blocks(body):
66
+ method = self.METHOD_PATTERN.search(block)
67
+ if not method or method.group(1) != self.LOCAL:
68
+ continue
69
+ explicit_path = None
70
+ path_match = self.EXPLICIT_PATH_PATTERN.search(block)
71
+ if path_match:
72
+ explicit_path = path_match.group(1).strip()
73
+ for name in self._entry_names(block):
74
+ git_name = name.split("/")[0]
75
+ if git_name and all(git_name != existing for existing, _ in entries):
76
+ entries.append((git_name, explicit_path))
77
+ return entries
78
+
79
+ def _entry_names(self, block: str) -> List[str]:
80
+ """条目内组件名:优先 :names => [...] 数组,兼容 :name => 'X' 单数写法"""
81
+ names_match = re.search(r":names\s*=>\s*\[", block)
82
+ if names_match:
83
+ array_body = ComponentGitFinder._extract_bracket_body(block, names_match.end() - 1)
84
+ if array_body is not None:
85
+ return self.QUOTED_PATTERN.findall(array_body)
86
+ single = re.search(r":name\s*=>\s*['\"]([^'\"]+)['\"]", block)
87
+ return [single.group(1)] if single else []
88
+
89
+ @staticmethod
90
+ def _split_hash_blocks(text: str) -> List[str]:
91
+ """按顶层 {} 拆分 ruby 数组体为条目块(引号内的括号不计数)"""
92
+ blocks: List[str] = []
93
+ depth, start = 0, None
94
+ in_single = in_double = escape_next = False
95
+ for idx, ch in enumerate(text):
96
+ if escape_next:
97
+ escape_next = False
98
+ continue
99
+ if (in_single or in_double) and ch == "\\":
100
+ escape_next = True
101
+ continue
102
+ if ch == "'" and not in_double:
103
+ in_single = not in_single
104
+ elif ch == '"' and not in_single:
105
+ in_double = not in_double
106
+ if in_single or in_double:
107
+ continue
108
+ if ch == "{":
109
+ if depth == 0:
110
+ start = idx
111
+ depth += 1
112
+ elif ch == "}" and depth > 0:
113
+ depth -= 1
114
+ if depth == 0:
115
+ blocks.append(text[start + 1:idx])
116
+ return blocks
117
+
118
+
119
+ class RepoUpdater:
120
+ """单个组件仓库的拉取更新:只做快进合并,异常仓库安全跳过"""
121
+
122
+ GIT_TIMEOUT = 300
123
+
124
+ GREEN = "\033[0;32m"
125
+ YELLOW = "\033[0;33m"
126
+ RED = "\033[0;31m"
127
+ CYAN = "\033[0;36m"
128
+ NC = "\033[0m"
129
+
130
+ def __init__(self, name: str, repo_path: Optional[str]):
131
+ self.name = name
132
+ self.repo_path = repo_path
133
+
134
+ def _git(self, *args: str) -> Tuple[bool, str]:
135
+ try:
136
+ proc = subprocess.run(
137
+ ["git", "-C", self.repo_path, *args],
138
+ capture_output=True, text=True, timeout=self.GIT_TIMEOUT,
139
+ )
140
+ except (subprocess.TimeoutExpired, OSError) as exc:
141
+ return False, str(exc)
142
+ return proc.returncode == 0, (proc.stdout + proc.stderr).strip()
143
+
144
+ def update(self, branch: Optional[str] = None, dry_run: bool = False, no_fetch: bool = False) -> Tuple[str, str]:
145
+ """执行更新或检查,返回 (状态 ok/skip/fail, 说明)"""
146
+ if not self.repo_path:
147
+ print(f"{self.RED}[缺失]{self.NC} {self.name} 未在成员 :pathes 下找到本地目录")
148
+ return "fail", "未找到本地目录"
149
+ if not os.path.exists(os.path.join(self.repo_path, ".git")):
150
+ print(f"{self.RED}[缺失]{self.NC} {self.name} 不是 git 仓库: {self.repo_path}")
151
+ return "fail", "不是 git 仓库"
152
+
153
+ ok, out = self._git("rev-parse", "--abbrev-ref", "HEAD")
154
+ current = out if ok else "HEAD"
155
+ print(f"{self.CYAN}==>{self.NC} {self.name} ({self.repo_path})")
156
+ print(f" 当前分支: {current}")
157
+
158
+ _, dirty = self._git("status", "--porcelain")
159
+ if dirty:
160
+ print(f" {self.YELLOW}跳过: 工作区有未提交改动{self.NC}")
161
+ return "skip", f"工作区有未提交改动 ({current})"
162
+
163
+ if branch and current != branch:
164
+ if dry_run:
165
+ print(f" {self.CYAN}dry-run: 不切换分支(当前 {current},目标 {branch}){self.NC}")
166
+ return "skip", f"dry-run 不切换分支 (当前 {current},目标 {branch})"
167
+ has_local, _ = self._git("show-ref", "--verify", "--quiet", f"refs/heads/{branch}")
168
+ has_remote, _ = self._git("show-ref", "--verify", "--quiet", f"refs/remotes/origin/{branch}")
169
+ if not (has_local or has_remote):
170
+ print(f" {self.YELLOW}跳过: 不存在分支 {branch}{self.NC}")
171
+ return "skip", f"不存在分支 {branch}"
172
+ if not self._git("checkout", branch)[0]:
173
+ print(f" {self.RED}失败: 无法切换到 {branch}{self.NC}")
174
+ return "fail", f"checkout {branch} 失败"
175
+ current = branch
176
+ print(f" 已切换到: {current}")
177
+
178
+ # 只 fetch 目标分支引用,避开远端大小写冲突引用导致的全量 fetch 失败
179
+ target = branch or current
180
+ if no_fetch:
181
+ print(f" {self.CYAN}离线检查: 基于上次 fetch 的缓存引用{self.NC}")
182
+ elif target != "HEAD":
183
+ fetch_ok, fetch_out = self._git(
184
+ "fetch", "origin", f"+refs/heads/{target}:refs/remotes/origin/{target}")
185
+ if not fetch_ok:
186
+ print(f" {self.RED}失败: git fetch{self.NC}")
187
+ if fetch_out:
188
+ print(f" {fetch_out}")
189
+ return "fail", "git fetch 失败"
190
+
191
+ if not self._git("rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}")[0]:
192
+ print(f" {self.YELLOW}跳过: 当前分支没有上游{self.NC}")
193
+ return "skip", f"无上游分支 ({current})"
194
+
195
+ _, behind_out = self._git("rev-list", "--count", "HEAD..@{u}")
196
+ _, ahead_out = self._git("rev-list", "--count", "@{u}..HEAD")
197
+ try:
198
+ behind = int(behind_out.split()[-1])
199
+ ahead = int(ahead_out.split()[-1])
200
+ except (ValueError, IndexError):
201
+ print(f" {self.RED}失败: 无法统计领先/落后提交{self.NC}")
202
+ return "fail", "无法统计领先/落后提交"
203
+
204
+ if behind == 0 and ahead == 0:
205
+ print(f" {self.GREEN}已是最新{self.NC} {current}")
206
+ return "ok", f"已是最新 ({current})"
207
+
208
+ if ahead > 0:
209
+ print(f" {self.YELLOW}跳过: 本地领先 {ahead} 个提交,避免非快进更新{self.NC}")
210
+ return "skip", f"本地领先 {ahead} ({current})"
211
+
212
+ if dry_run:
213
+ print(f" {self.GREEN}有更新{self.NC} 落后 {behind} 个提交(dry-run 未拉取)")
214
+ return "ok", f"有更新: 落后 {behind} 个提交 ({current})"
215
+
216
+ # merge 为纯本地快进(引用已由上面的单分支 fetch 更新),避免 pull 内置全量 fetch 触发大小写冲突
217
+ ok, out = self._git("merge", "--ff-only", "--quiet", "@{u}")
218
+ if ok:
219
+ print(f" {self.GREEN}已更新{self.NC} 快进 {behind} 个提交 → {current}")
220
+ return "ok", f"快进 {behind} 个提交 ({current})"
221
+ print(f" {self.RED}失败: git merge --ff-only{self.NC}")
222
+ if out:
223
+ print(f" {out}")
224
+ return "fail", "git merge --ff-only 失败"
225
+
226
+
227
+ class LocalModulesUpdater:
228
+ """批量拉取更新当前成员 :method => LOCAL 的本地组件仓库"""
229
+
230
+ GREEN = RepoUpdater.GREEN
231
+ YELLOW = RepoUpdater.YELLOW
232
+ RED = RepoUpdater.RED
233
+ CYAN = RepoUpdater.CYAN
234
+ NC = RepoUpdater.NC
235
+
236
+ def __init__(self, project_dir: str):
237
+ self.project_dir = project_dir
238
+ self.member_dir = os.path.join(project_dir, "cocoapods", "Member_modules")
239
+ self.finder = ComponentGitFinder(current_proj_dir=project_dir)
240
+
241
+ def run(self, target_components: Optional[List[str]] = None, branch: Optional[str] = None,
242
+ config_path: Optional[str] = None, dry_run: bool = False, no_fetch: bool = False) -> bool:
243
+ """主流程:识别成员 → 定位组件 → 逐仓库更新/检查 → 汇总,返回是否全部成功"""
244
+ member_file, pathes, targets = self.resolve_targets(config_path)
245
+ if member_file is None:
246
+ print(f"[!] 未匹配到当前开发者配置:没有任何成员 :pathes 在本机存在 ({self.member_dir})")
247
+ return False
248
+
249
+ print(f"当前成员配置: {member_file}")
250
+ print(f"搜索路径: {' '.join(pathes) if pathes else '(无)'}")
251
+ if branch:
252
+ print(f"目标分支: {branch}")
253
+ if dry_run:
254
+ print("模式: dry-run(只定位与检查更新,不改动工作区与本地分支)")
255
+ if no_fetch:
256
+ print("模式: 离线检查(--no-fetch,基于上次 fetch 的缓存引用,结果可能过期)")
257
+ if not targets:
258
+ print("该成员没有开启 :method => LOCAL 的组件。")
259
+ return True
260
+ print(f"本地组件: {' '.join(name for name, _ in targets)}")
261
+ print()
262
+
263
+ filtered = self._filter_targets(targets, target_components)
264
+ if filtered is None:
265
+ return False
266
+
267
+ results = {"ok": [], "skip": [], "fail": []}
268
+ for name, repo_path in filtered:
269
+ status, message = RepoUpdater(name, repo_path).update(branch=branch, dry_run=dry_run, no_fetch=no_fetch)
270
+ results[status].append((name, message))
271
+ print()
272
+ self._print_summary(results, dry_run, no_fetch)
273
+ return not results["fail"]
274
+
275
+ def resolve_targets(self, config_path: Optional[str] = None):
276
+ """确定成员配置与组件定位,返回 (成员文件, pathes, [(组件名, 定位路径), ...])"""
277
+ if config_path:
278
+ parser = MemberConfigParser(config_path)
279
+ if not parser.content:
280
+ raise FileNotFoundError(f"无法读取成员配置: {config_path}")
281
+ else:
282
+ parser = self._find_current_member()
283
+ if parser is None:
284
+ return None, [], []
285
+
286
+ pathes = parser.config_pathes()
287
+ targets = []
288
+ for git_name, explicit_path in parser.local_module_entries():
289
+ targets.append((git_name, self._locate_repo(git_name, explicit_path, pathes)))
290
+ return parser.file_path, pathes, targets
291
+
292
+ def _find_current_member(self) -> Optional[MemberConfigParser]:
293
+ """按 configs.rb 的 member_configs 顺序,找第一份 :pathes 在本机存在的成员配置"""
294
+ parsers = self._load_member_parsers()
295
+ for config_name in self._member_config_order():
296
+ parser = parsers.get(config_name)
297
+ if parser and any(os.path.exists(path) for path in parser.config_pathes()):
298
+ return parser
299
+ # configs.rb 缺失或未定义顺序时兜底:按文件顺序找第一份命中本机的配置
300
+ for parser in parsers.values():
301
+ if any(os.path.exists(path) for path in parser.config_pathes()):
302
+ return parser
303
+ return None
304
+
305
+ def _load_member_parsers(self) -> dict:
306
+ """加载 Member_modules 下所有成员文件,按 xxx_config 方法名索引"""
307
+ parsers = {}
308
+ if not os.path.isdir(self.member_dir):
309
+ return parsers
310
+ for file_name in sorted(os.listdir(self.member_dir)):
311
+ if not file_name.endswith(".rb"):
312
+ continue
313
+ parser = MemberConfigParser(os.path.join(self.member_dir, file_name))
314
+ match = MemberConfigParser.CONFIG_DEF_PATTERN.search(parser.content)
315
+ if match:
316
+ parsers[match.group(1)] = parser
317
+ return parsers
318
+
319
+ def _member_config_order(self) -> List[str]:
320
+ """解析 configs.rb 中 member_configs 引用的成员配置方法顺序"""
321
+ path = os.path.join(self.member_dir, "config", "configs.rb")
322
+ parser = MemberConfigParser(path)
323
+ match = re.search(r"def\s+member_configs\b(.*?)\bend\b", parser.content, re.DOTALL)
324
+ if not match:
325
+ return []
326
+ body = ComponentGitFinder._strip_ruby_comments(match.group(1))
327
+ return re.findall(r"(\w+_config)\b", body)
328
+
329
+ def _locate_repo(self, git_name: str, explicit_path: Optional[str], pathes: List[str]) -> Optional[str]:
330
+ """定位组件仓库目录:显式 :path 优先,其次当前成员 pathes,最后回退 bbcu 全量配置搜索"""
331
+ candidates = []
332
+ if explicit_path:
333
+ expanded = explicit_path.replace("#{git_name}", git_name)
334
+ candidates.append(os.path.dirname(expanded) if os.path.isfile(expanded) else expanded)
335
+ candidates += [os.path.join(path, git_name) for path in pathes]
336
+ for candidate in candidates:
337
+ if candidate and os.path.isdir(candidate):
338
+ return os.path.abspath(candidate)
339
+ return self.finder.find_git_root(git_name)
340
+
341
+ def _filter_targets(self, targets, selected):
342
+ """按命令行参数过滤组件;指定的组件不在 LOCAL 列表时报错返回 None"""
343
+ if not selected:
344
+ return targets
345
+ mapping = dict(targets)
346
+ missing = [name for name in selected if name not in mapping]
347
+ if missing:
348
+ print(f"[!] 组件不在当前成员 LOCAL 列表中: {', '.join(missing)}")
349
+ print(f" 可选: {', '.join(name for name, _ in targets)}")
350
+ return None
351
+ return [(name, mapping[name]) for name in selected]
352
+
353
+ def _print_summary(self, results, dry_run: bool, no_fetch: bool = False):
354
+ print("---------- 汇总 ----------")
355
+ ok_title = "检查" if dry_run else "成功"
356
+ for title, key, color in ((ok_title, "ok", self.GREEN), ("跳过", "skip", self.YELLOW), ("失败", "fail", self.RED)):
357
+ items = results[key]
358
+ print(f"{color}{title} {len(items)}{self.NC}")
359
+ for name, message in items:
360
+ print(f" - {name}: {message}")
361
+ if dry_run:
362
+ # dry-run 不产生真实更新,改为标记存在更新的组件清单
363
+ pending = []
364
+ for name, message in results["ok"]:
365
+ match = re.search(r"落后 (\d+) 个提交", message)
366
+ if match:
367
+ pending.append(f"{name}(落后 {match.group(1)})")
368
+ if pending:
369
+ print(f"\n{self.YELLOW}提示: 存在更新的组件: {'、'.join(pending)} —— 执行 bbpull 拉取{self.NC}")
370
+ elif no_fetch:
371
+ print(f"\n{self.CYAN}提示: 离线模式未发现可更新组件(缓存引用可能过期,可去掉 --no-fetch 联网复查){self.NC}")
372
+ return
373
+ updated = [name for name, message in results["ok"] if "快进" in message]
374
+ if updated:
375
+ print(f"\n{self.YELLOW}提示: {'、'.join(updated)} 拉取到新代码,需手动执行 bundle exec pod install 同步主工程{self.NC}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commit-updater
3
- Version: 0.4.0
3
+ Version: 0.6.0
4
4
  Summary: Update Podfile.lock component commits from local git repos and push
5
5
  Author: Aron
6
6
  License: MIT
@@ -29,6 +29,8 @@ Description-Content-Type: text/markdown
29
29
  - 更新 `Podfile.lock` 中对应组件的 `:commit:`
30
30
  - 自动提交并推送主工程改动
31
31
 
32
+ 另有 `bbpull` 命令:自动识别当前开发者配置,批量拉取更新 `:method => LOCAL` 的本地组件仓库代码(不做任何 lock 文件改动)。
33
+
32
34
  ## 安装
33
35
 
34
36
  ### 本地安装
@@ -38,7 +40,7 @@ cd CommitUpdater
38
40
  pip install -e .
39
41
  ```
40
42
 
41
- 安装后会提供命令:`bbcu`
43
+ 安装后会提供命令:`bbcu`、`bbpull`
42
44
 
43
45
  ### 外网安装
44
46
 
@@ -71,6 +73,30 @@ python3 -m pip show commit-updater
71
73
  bbcu BBUnlock
72
74
  ```
73
75
 
76
+ ## bbpull:批量拉取本地组件
77
+
78
+ 在主工程目录下执行,自动识别当前机器对应的成员配置(`:pathes` 在本机存在的第一份配置),
79
+ 更新其中 `:method => LOCAL` 的组件仓库:
80
+
81
+ ```bash
82
+ bbpull # 更新全部 LOCAL 组件
83
+ bbpull BBUIKit BRUserModule # 只更新指定组件
84
+ bbpull --branch develop # 先切分支再更新
85
+ bbpull --dry-run # 检查并标记每个组件是否有更新,不改动工作区与本地分支
86
+ bbpull --dry-run --no-fetch # 离线检查:基于上次 fetch 的缓存引用判断更新
87
+ bbpull --config cocoapods/Member_modules/zyt_modules.rb # 指定成员配置
88
+ ```
89
+
90
+ 拉取策略与 `scripts/update_local_modules.sh` 一致:
91
+
92
+ - 工作区有未提交改动的仓库跳过,不做任何改动
93
+ - 只 fetch 当前目标分支引用(`+refs/heads/<分支>:refs/remotes/origin/<分支>`,避开远端
94
+ 大小写冲突引用导致的全量 fetch 失败),再 `git merge --ff-only` 纯本地快进更新,本地领先时跳过
95
+ - 无上游分支的仓库跳过
96
+ - `--dry-run` 模式:执行 fetch 后按领先/落后标记各组件(有更新 N 个提交 / 已是最新 / 本地领先),
97
+ 不执行 checkout/pull;结尾列出存在更新的组件清单
98
+ - 有组件拉到新代码时,结尾提示需手动执行 `bundle exec pod install`
99
+
74
100
  ## 适用场景
75
101
 
76
102
  适用于基于 CocoaPods 管理组件依赖、并使用 `Podfile.lock` 锁定 commit 的工程。
@@ -0,0 +1,86 @@
1
+ # CommitUpdater
2
+
3
+ 用于在主工程中批量更新 `Podfile.lock` 里的组件 commit,并自动提交推送主工程仓库。
4
+
5
+ ## 功能概述
6
+
7
+ - 拉取主工程最新代码
8
+ - 获取组件仓库最新 commit
9
+ - 更新 `Podfile.lock` 中对应组件的 `:commit:`
10
+ - 自动提交并推送主工程改动
11
+
12
+ 另有 `bbpull` 命令:自动识别当前开发者配置,批量拉取更新 `:method => LOCAL` 的本地组件仓库代码(不做任何 lock 文件改动)。
13
+
14
+ ## 安装
15
+
16
+ ### 本地安装
17
+
18
+ ```bash
19
+ cd CommitUpdater
20
+ pip install -e .
21
+ ```
22
+
23
+ 安装后会提供命令:`bbcu`、`bbpull`
24
+
25
+ ### 外网安装
26
+
27
+ 发布到 PyPI 后,可直接安装:
28
+
29
+ ```bash
30
+ # 跟新pip源
31
+ python -m pip install --upgrade pip
32
+ # pip安装
33
+ pip install commit-updater
34
+ # pip命令没有找到,使用 python3 -m pip 命令安装
35
+ python3 -m pip install commit-updater
36
+ # 更新
37
+ python3 -m pip install -U commit-updater
38
+ ```
39
+
40
+ ## 使用方式
41
+
42
+ 进入包含 `Podfile.lock` 的主工程目录后执行:
43
+
44
+ ```bash
45
+ bbcu BBUnlock BBEngine
46
+ # 如果命令没有找到,查询安装位置,把安装路径中lib文件夹平级的bin文件夹添加到PATH中重新试下
47
+ python3 -m pip show commit-updater
48
+ ```
49
+
50
+ 也可以更新单个组件:
51
+
52
+ ```bash
53
+ bbcu BBUnlock
54
+ ```
55
+
56
+ ## bbpull:批量拉取本地组件
57
+
58
+ 在主工程目录下执行,自动识别当前机器对应的成员配置(`:pathes` 在本机存在的第一份配置),
59
+ 更新其中 `:method => LOCAL` 的组件仓库:
60
+
61
+ ```bash
62
+ bbpull # 更新全部 LOCAL 组件
63
+ bbpull BBUIKit BRUserModule # 只更新指定组件
64
+ bbpull --branch develop # 先切分支再更新
65
+ bbpull --dry-run # 检查并标记每个组件是否有更新,不改动工作区与本地分支
66
+ bbpull --dry-run --no-fetch # 离线检查:基于上次 fetch 的缓存引用判断更新
67
+ bbpull --config cocoapods/Member_modules/zyt_modules.rb # 指定成员配置
68
+ ```
69
+
70
+ 拉取策略与 `scripts/update_local_modules.sh` 一致:
71
+
72
+ - 工作区有未提交改动的仓库跳过,不做任何改动
73
+ - 只 fetch 当前目标分支引用(`+refs/heads/<分支>:refs/remotes/origin/<分支>`,避开远端
74
+ 大小写冲突引用导致的全量 fetch 失败),再 `git merge --ff-only` 纯本地快进更新,本地领先时跳过
75
+ - 无上游分支的仓库跳过
76
+ - `--dry-run` 模式:执行 fetch 后按领先/落后标记各组件(有更新 N 个提交 / 已是最新 / 本地领先),
77
+ 不执行 checkout/pull;结尾列出存在更新的组件清单
78
+ - 有组件拉到新代码时,结尾提示需手动执行 `bundle exec pod install`
79
+
80
+ ## 适用场景
81
+
82
+ 适用于基于 CocoaPods 管理组件依赖、并使用 `Podfile.lock` 锁定 commit 的工程。
83
+
84
+ ## 更多说明
85
+
86
+ 实现细节、PyCharm 运行说明、提交规则、发布流程和维护注意事项见:`DEVELOPMENT.md`
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commit-updater
3
- Version: 0.4.0
3
+ Version: 0.6.0
4
4
  Summary: Update Podfile.lock component commits from local git repos and push
5
5
  Author: Aron
6
6
  License: MIT
@@ -29,6 +29,8 @@ Description-Content-Type: text/markdown
29
29
  - 更新 `Podfile.lock` 中对应组件的 `:commit:`
30
30
  - 自动提交并推送主工程改动
31
31
 
32
+ 另有 `bbpull` 命令:自动识别当前开发者配置,批量拉取更新 `:method => LOCAL` 的本地组件仓库代码(不做任何 lock 文件改动)。
33
+
32
34
  ## 安装
33
35
 
34
36
  ### 本地安装
@@ -38,7 +40,7 @@ cd CommitUpdater
38
40
  pip install -e .
39
41
  ```
40
42
 
41
- 安装后会提供命令:`bbcu`
43
+ 安装后会提供命令:`bbcu`、`bbpull`
42
44
 
43
45
  ### 外网安装
44
46
 
@@ -71,6 +73,30 @@ python3 -m pip show commit-updater
71
73
  bbcu BBUnlock
72
74
  ```
73
75
 
76
+ ## bbpull:批量拉取本地组件
77
+
78
+ 在主工程目录下执行,自动识别当前机器对应的成员配置(`:pathes` 在本机存在的第一份配置),
79
+ 更新其中 `:method => LOCAL` 的组件仓库:
80
+
81
+ ```bash
82
+ bbpull # 更新全部 LOCAL 组件
83
+ bbpull BBUIKit BRUserModule # 只更新指定组件
84
+ bbpull --branch develop # 先切分支再更新
85
+ bbpull --dry-run # 检查并标记每个组件是否有更新,不改动工作区与本地分支
86
+ bbpull --dry-run --no-fetch # 离线检查:基于上次 fetch 的缓存引用判断更新
87
+ bbpull --config cocoapods/Member_modules/zyt_modules.rb # 指定成员配置
88
+ ```
89
+
90
+ 拉取策略与 `scripts/update_local_modules.sh` 一致:
91
+
92
+ - 工作区有未提交改动的仓库跳过,不做任何改动
93
+ - 只 fetch 当前目标分支引用(`+refs/heads/<分支>:refs/remotes/origin/<分支>`,避开远端
94
+ 大小写冲突引用导致的全量 fetch 失败),再 `git merge --ff-only` 纯本地快进更新,本地领先时跳过
95
+ - 无上游分支的仓库跳过
96
+ - `--dry-run` 模式:执行 fetch 后按领先/落后标记各组件(有更新 N 个提交 / 已是最新 / 本地领先),
97
+ 不执行 checkout/pull;结尾列出存在更新的组件清单
98
+ - 有组件拉到新代码时,结尾提示需手动执行 `bundle exec pod install`
99
+
74
100
  ## 适用场景
75
101
 
76
102
  适用于基于 CocoaPods 管理组件依赖、并使用 `Podfile.lock` 锁定 commit 的工程。
@@ -1,17 +1,21 @@
1
1
  CommitFetcher.py
2
2
  ComponentGitFinder.py
3
+ LocalModulesUpdater.py
3
4
  LockFileUpdater.py
4
5
  MainProjUpdater.py
5
6
  README.md
6
7
  __init__.py
7
8
  main.py
9
+ pull_main.py
8
10
  pyproject.toml
9
11
  ./CommitFetcher.py
10
12
  ./ComponentGitFinder.py
13
+ ./LocalModulesUpdater.py
11
14
  ./LockFileUpdater.py
12
15
  ./MainProjUpdater.py
13
16
  ./__init__.py
14
17
  ./main.py
18
+ ./pull_main.py
15
19
  commit_updater.egg-info/PKG-INFO
16
20
  commit_updater.egg-info/SOURCES.txt
17
21
  commit_updater.egg-info/dependency_links.txt
@@ -1,2 +1,3 @@
1
1
  [console_scripts]
2
2
  bbcu = CommitUpdater.main:main
3
+ bbpull = CommitUpdater.pull_main:main
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: UTF-8 -*-
3
+ """
4
+ @Project :BBScriptToolBundle
5
+ @File :pull_main.py
6
+ @Author :Aron
7
+ """
8
+ import argparse
9
+ import os
10
+ import sys
11
+
12
+ from CommitUpdater.LocalModulesUpdater import LocalModulesUpdater
13
+
14
+
15
+ def main():
16
+ parser = argparse.ArgumentParser(
17
+ prog="bbpull",
18
+ description="批量拉取更新本地组件仓库(自动识别当前成员配置中 :method => LOCAL 的组件)",
19
+ )
20
+ parser.add_argument("components", nargs="*", help="可选,只更新指定组件(默认全部 LOCAL 组件)")
21
+ parser.add_argument("-b", "--branch", default=None, help="先切换到指定分支再更新")
22
+ parser.add_argument("--config", default=None, help="指定成员配置文件(默认自动识别当前机器对应的成员)")
23
+ parser.add_argument("--project", default=os.getcwd(), help="主工程根目录(默认当前目录)")
24
+ parser.add_argument("--dry-run", action="store_true",
25
+ help="只定位与检查更新并标记结果,不改动工作区与本地分支")
26
+ parser.add_argument("--no-fetch", action="store_true",
27
+ help="离线检查:不联网 fetch,基于上次 fetch 的缓存引用判断更新")
28
+ args = parser.parse_args()
29
+
30
+ try:
31
+ updater = LocalModulesUpdater(args.project)
32
+ success = updater.run(
33
+ target_components=args.components,
34
+ branch=args.branch,
35
+ config_path=args.config,
36
+ dry_run=args.dry_run,
37
+ no_fetch=args.no_fetch,
38
+ )
39
+ except FileNotFoundError as exc:
40
+ print(f"[!] {exc}")
41
+ sys.exit(1)
42
+ sys.exit(0 if success else 1)
43
+
44
+
45
+ if __name__ == "__main__":
46
+ main()
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "commit-updater"
7
- version = "0.4.0"
7
+ version = "0.6.0"
8
8
  description = "Update Podfile.lock component commits from local git repos and push"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -26,6 +26,7 @@ classifiers = [
26
26
 
27
27
  [project.scripts]
28
28
  bbcu = "CommitUpdater.main:main"
29
+ bbpull = "CommitUpdater.pull_main:main"
29
30
 
30
31
  [tool.setuptools]
31
32
  packages = ["CommitUpdater"]
@@ -1,60 +0,0 @@
1
- # CommitUpdater
2
-
3
- 用于在主工程中批量更新 `Podfile.lock` 里的组件 commit,并自动提交推送主工程仓库。
4
-
5
- ## 功能概述
6
-
7
- - 拉取主工程最新代码
8
- - 获取组件仓库最新 commit
9
- - 更新 `Podfile.lock` 中对应组件的 `:commit:`
10
- - 自动提交并推送主工程改动
11
-
12
- ## 安装
13
-
14
- ### 本地安装
15
-
16
- ```bash
17
- cd CommitUpdater
18
- pip install -e .
19
- ```
20
-
21
- 安装后会提供命令:`bbcu`
22
-
23
- ### 外网安装
24
-
25
- 发布到 PyPI 后,可直接安装:
26
-
27
- ```bash
28
- # 跟新pip源
29
- python -m pip install --upgrade pip
30
- # pip安装
31
- pip install commit-updater
32
- # pip命令没有找到,使用 python3 -m pip 命令安装
33
- python3 -m pip install commit-updater
34
- # 更新
35
- python3 -m pip install -U commit-updater
36
- ```
37
-
38
- ## 使用方式
39
-
40
- 进入包含 `Podfile.lock` 的主工程目录后执行:
41
-
42
- ```bash
43
- bbcu BBUnlock BBEngine
44
- # 如果命令没有找到,查询安装位置,把安装路径中lib文件夹平级的bin文件夹添加到PATH中重新试下
45
- python3 -m pip show commit-updater
46
- ```
47
-
48
- 也可以更新单个组件:
49
-
50
- ```bash
51
- bbcu BBUnlock
52
- ```
53
-
54
- ## 适用场景
55
-
56
- 适用于基于 CocoaPods 管理组件依赖、并使用 `Podfile.lock` 锁定 commit 的工程。
57
-
58
- ## 更多说明
59
-
60
- 实现细节、PyCharm 运行说明、提交规则、发布流程和维护注意事项见:`DEVELOPMENT.md`
File without changes
File without changes