- cmd = ['git', '--git-dir', rundir, 'gc', '--aggressive', '--prune=all']
- print('Repacking git repo: %s' % ' '.join(cmd))
- subprocess.check_call(cmd, cwd='/')
+ cmd = ['git', '--git-dir', str(rundir), 'gc', '--aggressive', '--prune=all']
+ print('Repacking git repo:', ' '.join(cmd))
+ subprocess.run(cmd, cwd='/', check=True)
+
+ # Clean empty dirs.
+ cmd = ['find', str(rundir), '-depth', '-type', 'd', '-exec', 'rmdir', '{}', '+']
+ subprocess.run(cmd, stderr=subprocess.DEVNULL, check=False)
+
+ # There's a few dirs we need to exist even if they're empty.
+ refdir = rundir / 'refs'
+ refdir.mkdir(exist_ok=True)