From 0c06524e4e3176d30f2885b3355d4876f2d8558b Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sun, 24 May 2026 12:25:18 -0500 Subject: [PATCH] luarocks-packages-updater: commit updates separately --- .../lu/luarocks-packages-updater/updater.py | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/lu/luarocks-packages-updater/updater.py b/pkgs/by-name/lu/luarocks-packages-updater/updater.py index 2d9accce0351..2cff160066e2 100755 --- a/pkgs/by-name/lu/luarocks-packages-updater/updater.py +++ b/pkgs/by-name/lu/luarocks-packages-updater/updater.py @@ -105,6 +105,26 @@ def extract_rev(nix_expr: str) -> str | None: return None +def commit_files(repo, message: str, files: list[Path]) -> None: + worktree = repo.working_tree_dir + paths = [str(path) for path in files] + + subprocess.run(["git", "add", "--", *paths], cwd=worktree, check=True) + diff_result = subprocess.run( + ["git", "diff", "--cached", "--quiet", "--", *paths], + cwd=worktree, + check=False, + ) + if diff_result.returncode == 0: + print("no changes in working tree to commit") + return + if diff_result.returncode != 1: + raise RuntimeError("Could not inspect staged changes") + + print(f'committing to nixpkgs "{message}"') + subprocess.run(["git", "commit", "-m", message, "--", *paths], cwd=worktree, check=True) + + # rename Editor to LangUpdate/ EcosystemUpdater class LuaEditor(nixpkgs_plugin_update.Editor): def create_parser(self): @@ -131,7 +151,42 @@ class LuaEditor(nixpkgs_plugin_update.Editor): return luaPackages def update(self, args): - update_plugins(self, args) + if args.no_commit: + update_plugins(self, args) + return + + fetch_config = FetchConfig(args.proc, args.github_token) + specs = self.load_plugin_spec(fetch_config, args.input_file) + specs = sorted(specs, key=lambda v: v.name.lower()) + + if args.update_only: + specs = [ + p + for p in specs + if p.normalized_name in args.update_only or p.name in args.update_only + ] + + if not specs: + log.error("No matching Lua packages to update") + return + + assert self.nixpkgs_repo is not None + for spec in specs: + update = self.get_update( + str(args.input_file), + str(args.outfile), + fetch_config, + to_update=[spec.name], + ) + _redirects, updated_plugins = update() + + for name, old_ver, new_ver in updated_plugins: + if old_ver == "init": + msg = f"{self.attr_path}.{name}: init at {new_ver}" + else: + msg = f"{self.attr_path}.{name}: {old_ver} -> {new_ver}" + + commit_files(self.nixpkgs_repo, msg, [args.outfile]) def generate_nix(self, results: list[tuple[LuaPlugin, str]], outfilename: str): with tempfile.NamedTemporaryFile("w+") as f: