两个 mirror clone 去掉内部 .git,内容真正入库(原来只记了 gitlink)
This commit is contained in:
1 parent
1bd15c5d59
commit
185148ab7c
3 files changed
+49
-2
No files matched your search
Submodule _归档/_待删_20261022/staging/运行批次/parallel_sources/qoder_2025_2026_bulk_source_hunt_20260927/logs/repo_mirrors/Laz8Noy__kaoyan408-share deleted from baf124bdec.
Submodule _归档/_待删_20261022/staging/运行批次/parallel_sources/qoder_2025_2026_bulk_source_hunt_20260927/logs/repo_mirrors/zhwen2703-hash__kaoyan-recommendation-platform deleted from bf7a9c69fe.
@@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""把两个被当成 submodule 的目录还原成普通目录,让内容真正进仓库。
|
||||
|
||||
它们在 _归档/_待删_20261022/.../logs/repo_mirrors/ 下,是别人仓库的 mirror clone,
|
||||
git 只记了个 gitlink,不删内部 .git 的话内容永远进不去。
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
ROOT = r'D:\择校'
|
||||
BASE = os.path.join(ROOT, '_归档', '_待删_20261022', 'staging', '运行批次', 'parallel_sources',
|
||||
'qoder_2025_2026_bulk_source_hunt_20260927', 'logs', 'repo_mirrors')
|
||||
TARGETS = ['Laz8Noy__kaoyan408-share', 'zhwen2703-hash__kaoyan-recommendation-platform']
|
||||
|
||||
|
||||
def run(args):
|
||||
r = subprocess.run(args, cwd=ROOT, capture_output=True)
|
||||
return r.returncode, (r.stdout + r.stderr).decode('utf-8', 'replace')
|
||||
|
||||
|
||||
for name in TARGETS:
|
||||
p = os.path.join(BASE, name)
|
||||
g = os.path.join(p, '.git')
|
||||
if not os.path.isdir(p):
|
||||
print('%s 不存在,跳过' % name)
|
||||
continue
|
||||
size = 0
|
||||
for root, dirs, files in os.walk(p):
|
||||
for f in files:
|
||||
try:
|
||||
size += os.path.getsize(os.path.join(root, f))
|
||||
except OSError:
|
||||
pass
|
||||
print('%s:%.1f MB' % (name, size / 1048576))
|
||||
if os.path.isdir(g):
|
||||
shutil.rmtree(g, ignore_errors=True)
|
||||
print(' 已删除内部 .git')
|
||||
|
||||
code, out = run(['git', 'rm', '--cached', '-q', '--ignore-unmatch', '-r', '--'] +
|
||||
[os.path.relpath(os.path.join(BASE, n), ROOT).replace('\\', '/') for n in TARGETS])
|
||||
print('rm --cached exit=%d' % code)
|
||||
|
||||
code, out = run(['git', 'add', '-A'])
|
||||
print('add exit=%d' % code)
|
||||
if code != 0:
|
||||
print(out[-800:])
|
||||
code, out = run(['git', 'diff', '--cached', '--shortstat'])
|
||||
print('暂存:%s' % out.strip())
|
||||
Reference in new issue
Block a user