tooling(restep): fixes
This commit is contained in:
parent
711ae7ab01
commit
5ff8feb53b
1 changed files with 39 additions and 39 deletions
78
sync.py
78
sync.py
|
@ -239,6 +239,9 @@ def generate_sotaignore(large_files: list[Path]) -> None:
|
||||||
"# .sotaignore file generated by sota staircase ReStepper",
|
"# .sotaignore file generated by sota staircase ReStepper",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if new_sotaignore == []:
|
||||||
|
return
|
||||||
|
|
||||||
REPO_SOTAIGNORE.touch(exist_ok=True)
|
REPO_SOTAIGNORE.touch(exist_ok=True)
|
||||||
REPO_SOTAIGNORE.write_text("\n".join(new_sotaignore) + "\n", encoding="utf-8")
|
REPO_SOTAIGNORE.write_text("\n".join(new_sotaignore) + "\n", encoding="utf-8")
|
||||||
|
|
||||||
|
@ -254,13 +257,7 @@ def rewrite_gitattributes(target_dir: Path) -> None:
|
||||||
|
|
||||||
# recursively search for .gitattributes files
|
# recursively search for .gitattributes files
|
||||||
for repo_file in target_dir.rglob(".gitattributes"):
|
for repo_file in target_dir.rglob(".gitattributes"):
|
||||||
# print(repo_file)
|
repo_file.write_text(NEUTERED_GITATTRIBUTES, encoding="utf-8")
|
||||||
try:
|
|
||||||
repo_file.write_text(NEUTERED_GITATTRIBUTES, encoding="utf-8")
|
|
||||||
except Exception as exc:
|
|
||||||
print(f"error writing to {repo_file}: {exc} ({exc.__class__.__name__})")
|
|
||||||
else:
|
|
||||||
print(f"success to {repo_file}")
|
|
||||||
|
|
||||||
|
|
||||||
# helper function for running steps
|
# helper function for running steps
|
||||||
|
@ -472,6 +469,7 @@ def main() -> None:
|
||||||
f"critical error (whuh? internal?): not inside the temp dir '{str(Path(dir_temp).absolute())}'"
|
f"critical error (whuh? internal?): not inside the temp dir '{str(Path(dir_temp).absolute())}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# check for forge and github remotes
|
||||||
step(
|
step(
|
||||||
func=cmd("git remote -v"),
|
func=cmd("git remote -v"),
|
||||||
post_func=post_remote_v,
|
post_func=post_remote_v,
|
||||||
|
@ -479,11 +477,20 @@ def main() -> None:
|
||||||
if "remote/forge" not in r:
|
if "remote/forge" not in r:
|
||||||
err("critical error (whuh?): no forge remote found")
|
err("critical error (whuh?): no forge remote found")
|
||||||
|
|
||||||
|
# get the current branch
|
||||||
step(
|
step(
|
||||||
func=cmd(f"git fetch {r['remote/forge']} --dry-run"),
|
func=cmd("git branch --show-current"),
|
||||||
)
|
)
|
||||||
if (not r["blank"]) and ("--dirty" not in argv):
|
branch = r["stdout"].strip()
|
||||||
err("critical error (whuh?): not up to date with forge... sync your changes first?")
|
if r.get("errored", "yes") or branch == "":
|
||||||
|
err("critical error (whuh?): couldn't get current branch")
|
||||||
|
|
||||||
|
step(func=cmd(f"git fetch {r['remote/forge']}"))
|
||||||
|
step(func=cmd(f"git rev-list HEAD...{r['remote/forge']}/{branch} --count"))
|
||||||
|
if (r.get("stdout", "").strip() != "0") and ("--dirty" not in argv):
|
||||||
|
err(
|
||||||
|
"critical error (whuh?): not up to date with forge... sync your changes first?"
|
||||||
|
)
|
||||||
|
|
||||||
step(desc="3 lfs\tfetch lfs objects", func=cmd("git lfs fetch"))
|
step(desc="3 lfs\tfetch lfs objects", func=cmd("git lfs fetch"))
|
||||||
|
|
||||||
|
@ -507,33 +514,31 @@ def main() -> None:
|
||||||
"critical error (whuh? internal?): lfs objects still exist post-migrate and uninstall"
|
"critical error (whuh? internal?): lfs objects still exist post-migrate and uninstall"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
temp_sotaignore = Path(dir_temp).joinpath(".sotaignore")
|
||||||
sotaignore = (
|
|
||||||
Path(dir_temp)
|
|
||||||
.joinpath(".sotaignore")
|
|
||||||
.read_text(encoding="utf-8")
|
|
||||||
.strip()
|
|
||||||
)
|
|
||||||
except Exception as exc:
|
|
||||||
err("critical error: couldn't read .sotaignore file", exc=exc)
|
|
||||||
|
|
||||||
sotaignore_large_files: list[str] = [
|
if temp_sotaignore.exists():
|
||||||
line
|
try:
|
||||||
for line in sotaignore.splitlines()
|
sotaignore = temp_sotaignore.read_text(encoding="utf-8").strip()
|
||||||
if not line.startswith("#") and line.strip() != ""
|
except Exception as exc:
|
||||||
]
|
err("critical error: couldn't read .sotaignore file", exc=exc)
|
||||||
|
|
||||||
# FUTURE: if this becomes slow, start chunking --path arguments
|
sotaignore_large_files: list[str] = [
|
||||||
# https://stackoverflow.com/questions/43762338/how-to-remove-file-from-git-history
|
line
|
||||||
|
for line in sotaignore.splitlines()
|
||||||
|
if not line.startswith("#") and line.strip() != ""
|
||||||
|
]
|
||||||
|
|
||||||
for n, lf in enumerate(sotaignore_large_files, start=1):
|
# FUTURE: if this becomes slow, start chunking --path arguments
|
||||||
step(
|
# https://stackoverflow.com/questions/43762338/how-to-remove-file-from-git-history
|
||||||
desc=f"6 lfs\tfilter ({n}/{len(sotaignore_large_files)}) - {lf}",
|
|
||||||
func=cmd(f'git filter-repo --force --invert-paths --path "{lf}"'),
|
for n, lf in enumerate(sotaignore_large_files, start=1):
|
||||||
)
|
step(
|
||||||
|
desc=f"6 lfs\tfilter ({n}/{len(sotaignore_large_files)}) - {lf}",
|
||||||
|
func=cmd(f'git filter-repo --force --invert-paths --path "{lf}"'),
|
||||||
|
)
|
||||||
|
|
||||||
step(
|
step(
|
||||||
desc="7 lfs\tneuter .gitattributes",
|
desc="7 fin\tneuter .gitattributes",
|
||||||
func=lambda: rewrite_gitattributes(Path(dir_temp)),
|
func=lambda: rewrite_gitattributes(Path(dir_temp)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -552,15 +557,10 @@ def main() -> None:
|
||||||
err("critical error (whuh?): couldn't add github remote")
|
err("critical error (whuh?): couldn't add github remote")
|
||||||
r["remote/github"] = "github"
|
r["remote/github"] = "github"
|
||||||
|
|
||||||
# get current branch
|
|
||||||
step(
|
step(
|
||||||
func=cmd("git branch --show-current"),
|
desc=f"9 fin\tpushing to github/{branch}",
|
||||||
)
|
|
||||||
|
|
||||||
step(
|
|
||||||
desc=f"9 fin\tpushing to github/{r['stdout'].strip()}",
|
|
||||||
func=cmd(
|
func=cmd(
|
||||||
f"git push {r['remote/github']} {r['stdout'].strip()} --force"
|
f"git push {r['remote/github']} {branch} --force"
|
||||||
if ("--test" not in argv)
|
if ("--test" not in argv)
|
||||||
else "git --version"
|
else "git --version"
|
||||||
),
|
),
|
||||||
|
|
Reference in a new issue