{"thread":{"id":"66462","subject":"[BUG] repack --drop-filtered --dry-run writes packs and honors -d in Git 2.56.0","startedAt":"2026-10-04T23:47:50Z","lastAt":"2026-10-08T02:25:34Z","messageCount":3,"participants":["Coy Geek","D. Ben Knoble","Siddharth Shrimali"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"554135","messageId":"CACgTecOm+=vbf50tZNXhcYvRi1ZTsQwbjVoJAbQqs2CmXdJCxg@mail.gmail.com","threadId":"66462","inReplyTo":null,"subject":"[BUG] repack --drop-filtered --dry-run writes packs and honors -d in Git 2.56.0","fromName":"Coy Geek","fromEmail":"coygeek@gmail.com","sentAt":"2026-10-04T23:47:37Z","receivedAt":"2026-10-04T23:47:50Z","isPatch":false,"sender":{"key":"coygeek@gmail.com","avatar":null},"body":"fix(repack): --drop-filtered --dry-run writes packs and deletes old\npacks with -d\n\n## Summary\n\nOn Git 2.56.0, `git repack -a --filter=blob:limit=1m --drop-filtered\n--dry-run` prints the candidate blob but also writes a new promisor\npack and its sidecar files. Adding explicit `-d` also removes the old\nredundant packs and their sidecar files. Both commands exit\nsuccessfully despite the documented promise to list candidates without\nrebuilding packs or deleting anything.\n\nThis makes the advertised preview mutate repository storage. The\ntested blob remains available after both commands; this report does\nnot demonstrate loss of object content.\n\n## Steps to reproduce\n\nThe following Python 3 script was executed with Git 2.56.0 on macOS.\nIt requires `git` on `PATH`, creates only disposable local\nrepositories, disables ambient Git configuration and hooks, and uses a\nsynthetic commit identity. It creates a 2,200,000-byte historical blob\nabsent from the current index, makes a filtered clone through a local\npromisor remote, fetches that blob into a promisor pack, and snapshots\nthe pack directory before each preview. Each variant uses its own\nfresh partial clone. The script removes its fixture after a successful\nrun.\n\n```python\nimport hashlib\nimport os\nfrom pathlib import Path\nimport subprocess\nimport shutil\nimport tempfile\n\nwork = Path(tempfile.mkdtemp(prefix='agent-work.', dir='/tmp'))\nenv = {k: v for k, v in os.environ.items() if not k.startswith('GIT_')}\nenv.update(GIT_CONFIG_NOSYSTEM='1', GIT_CONFIG_GLOBAL=os.devnull,\n           LC_ALL='C', GIT_TERMINAL_PROMPT='0')\n\ndef git(repo, *args):\n    command = ['git', '-c', 'gc.auto=0', '-c', 'core.hooksPath=' + os.devnull,\n               '-c', 'user.name=Fixture', '-c',\n'user.email=fixture@example.invalid',\n               '-C', str(repo), *args]\n    return subprocess.run(command, env=env, check=True, text=True,\n                          stdout=subprocess.PIPE,\nstderr=subprocess.PIPE).stdout.strip()\n\ndef inventory(repo):\n    packdir = repo / '.git' / 'objects' / 'pack'\n    return {p.name: hashlib.sha256(p.read_bytes()).hexdigest()\n            for p in packdir.iterdir() if p.is_file()}\n\nprint(git(work, '--version'))\nsource = work / 'source'\nsource.mkdir()\ngit(source, 'init', '--template=', '-b', 'main')\n(source / 'large.bin').write_bytes(b'LARGE BLOB\\n' * 200000)\ngit(source, 'add', 'large.bin')\ngit(source, 'commit', '-m', 'Add historical blob')\nblob = git(source, 'rev-parse', 'HEAD:large.bin')\ngit(source, 'rm', 'large.bin')\n(source / 'tip.txt').write_text('tip\\n')\ngit(source, 'add', 'tip.txt')\ngit(source, 'commit', '-m', 'Remove historical blob')\nremote = work / 'remote.git'\ngit(work, 'clone', '--bare', str(source), str(remote))\ngit(remote, 'config', 'uploadpack.allowFilter', 'true')\n\nfor label, extra in [('dry-run', []), ('dry-run -d', ['-d'])]:\n    repo = work / ('clone-delete' if extra else 'clone-preview')\n    git(work, '-c', 'protocol.file.allow=always', 'clone', '--filter=blob:none',\n        remote.as_uri(), str(repo))\n    assert git(repo, 'cat-file', '-s', blob) == '2200000'\n    before = inventory(repo)\n    output = git(repo, 'repack', '-a', *extra, '--filter=blob:limit=1m',\n                 '--drop-filtered', '--dry-run')\n    after = inventory(repo)\n    added = sorted(after.keys() - before.keys())\n    removed = sorted(before.keys() - after.keys())\n    changed = sorted(k for k in before.keys() & after.keys() if\nbefore[k] != after[k])\n    print(label + ': exit 0')\n    print('candidate=' + output)\n    print('pack directory: before=%d after=%d added=%d removed=%d changed=%d' %\n          (len(before), len(after), len(added), len(removed), len(changed)))\n    print('added extensions=' + ','.join(sorted(Path(k).suffix for k in added)))\n    print('removed extensions=' + ','.join(sorted(Path(k).suffix for k\nin removed)))\n    print('candidate size after=' + git(repo, 'cat-file', '-s', blob))\nshutil.rmtree(work)\n```\n\n## Expected behavior\n\nThe Git 2.56.0 `git-repack` manual says `--dry-run` should \"List the\nobjects that would be dropped, one object ID per line, without\nrebuilding any pack or deleting anything.\"\n\nFor both commands, Git should print the candidate blob and leave the\nexisting pack files and their contents unchanged. Explicit `-d` should\nnot cause deletion during this dry run. The fixture satisfies the\ndocumented prerequisites: `-a`, a supported `blob:limit` filter, a\nconfigured promisor remote, no operation in progress, and a candidate\nabsent from the current index.\n\n## Actual behavior\n\nThe executed script produced this output. The counts include regular\nfiles in `objects/pack`, and `changed` compares SHA-256 content hashes\nfor names present before and after.\n\n```text\ngit version 2.56.0\ndry-run: exit 0\ncandidate=faed553c77de798540bd1edc898e174bf4436b28\npack directory: before=12 after=16 added=4 removed=0 changed=0\nadded extensions=.idx,.pack,.promisor,.rev\nremoved extensions=\ncandidate size after=2200000\ndry-run -d: exit 0\ncandidate=faed553c77de798540bd1edc898e174bf4436b28\npack directory: before=12 after=4 added=4 removed=12 changed=0\nadded extensions=.idx,.pack,.promisor,.rev\nremoved extensions=.idx,.idx,.idx,.pack,.pack,.pack,.promisor,.promisor,.promisor,.rev,.rev,.rev\ncandidate size after=2200000\n```\n\nThe ordinary preview added four files, one each with `.pack`, `.idx`,\n`.promisor`, and `.rev` extensions. The preview with explicit `-d`\nadded the same four types and deleted the 12 previous pack and sidecar\nfiles. Both invocations printed the expected candidate object ID and\nexited 0. A subsequent `cat-file -s` still reported the blob's\noriginal size in both clones.\n\nThis report records one successful invocation of each variant in the\nfinal script execution. A preceding fixture execution reproduced the\nsame counts. These observations establish the Git 2.56.0 behavior;\ncurrent development Git was not built or executed for this report.\n\n## Evidence\n\n- Expected source: Git 2.56.0 [Documentation/git-repack.adoc, the\n`--dry-run` option](https://github.com/git/git/blob/v2.56.0/Documentation/git-repack.adoc#L217-L220),\nwhich promises no pack rebuilding or deletion.\n- Failure source: The inline script and its captured output in Actual\nbehavior. The before/after pack inventories show four added files for\nboth variants and 12 deleted files when explicit `-d` is present.\n- Evidence provenance: observed\n- Local verification: reproduced\n- Reproduction completeness: complete\n\nThe primary violation evidence is execution of the inline fixture with\nGit 2.56.0. Both commands exited 0 with the pack-directory changes\nshown above. The manual and source links provide the contract and\nsupporting static evidence.\n\nThe release source at [builtin/repack.c, lines\n356-394](https://github.com/git/git/blob/v2.56.0/builtin/repack.c#L356-L394)\nguards the implicit `delete_redundant` setting with `!dry_run`, then\nprints candidates when `dry_run` is set. Execution continues beyond\nthat block. This is a source breadcrumb consistent with the observed\nresults, rather than a required implementation change.\n\nThe original implementation discussion also describes dry run as\nleaving the repository unchanged: [v5\n1/6](https://lore.kernel.org/git/20260813200830.84348-2-r.siddharth.shrimali@gmail.com/)\nand [v5 5/6](https://lore.kernel.org/git/20260813200830.84348-6-r.siddharth.shrimali@gmail.com/).\n\n## Restoration check\n\nRun the same fixture after a fix. Both preview variants should still\nprint the candidate object ID and exit successfully, with `added=0\nremoved=0 changed=0` and equal before/after pack-directory counts.\nRetaining the candidate output distinguishes a working preview from\nsimply skipping the operation. The cached blob should remain\navailable. Use the ordinary command and the explicit `-d` variant as\nseparate checks of the same no-write contract.\n"},{"id":"554411","messageId":"CALnO6CCmv7PmxW2HTfvD8i6-PCVqMWgasyU9PYhPLXGj1sz=Hg@mail.gmail.com","threadId":"66462","inReplyTo":"CACgTecOm+=vbf50tZNXhcYvRi1ZTsQwbjVoJAbQqs2CmXdJCxg@mail.gmail.com","subject":"Re: [BUG] repack --drop-filtered --dry-run writes packs and honors -d in Git 2.56.0","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-07T19:10:24Z","receivedAt":"2026-10-07T19:10:24Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"Cc: Siddharth Shrimali <r.siddharth.shrimali@gmail.com> who authored\nthe --drop-filtered code.\n\nOn Sun, Oct 4, 2026 at 7:47 PM Coy Geek <coygeek@gmail.com> wrote:\n>\n> fix(repack): --drop-filtered --dry-run writes packs and deletes old\n> packs with -d\n>\n> ## Summary\n>\n> On Git 2.56.0, `git repack -a --filter=blob:limit=1m --drop-filtered\n> --dry-run` prints the candidate blob but also writes a new promisor\n> pack and its sidecar files. Adding explicit `-d` also removes the old\n> redundant packs and their sidecar files. Both commands exit\n> successfully despite the documented promise to list candidates without\n> rebuilding packs or deleting anything.\n>\n> This makes the advertised preview mutate repository storage. The\n> tested blob remains available after both commands; this report does\n> not demonstrate loss of object content.\n>\n> ## Steps to reproduce\n>\n> The following Python 3 script was executed with Git 2.56.0 on macOS.\n> It requires `git` on `PATH`, creates only disposable local\n> repositories, disables ambient Git configuration and hooks, and uses a\n> synthetic commit identity. It creates a 2,200,000-byte historical blob\n> absent from the current index, makes a filtered clone through a local\n> promisor remote, fetches that blob into a promisor pack, and snapshots\n> the pack directory before each preview. Each variant uses its own\n> fresh partial clone. The script removes its fixture after a successful\n> run.\n>\n> ```python\n> import hashlib\n> import os\n> from pathlib import Path\n> import subprocess\n> import shutil\n> import tempfile\n>\n> work = Path(tempfile.mkdtemp(prefix='agent-work.', dir='/tmp'))\n> env = {k: v for k, v in os.environ.items() if not k.startswith('GIT_')}\n> env.update(GIT_CONFIG_NOSYSTEM='1', GIT_CONFIG_GLOBAL=os.devnull,\n>            LC_ALL='C', GIT_TERMINAL_PROMPT='0')\n>\n> def git(repo, *args):\n>     command = ['git', '-c', 'gc.auto=0', '-c', 'core.hooksPath=' + os.devnull,\n>                '-c', 'user.name=Fixture', '-c',\n> 'user.email=fixture@example.invalid',\n>                '-C', str(repo), *args]\n>     return subprocess.run(command, env=env, check=True, text=True,\n>                           stdout=subprocess.PIPE,\n> stderr=subprocess.PIPE).stdout.strip()\n>\n> def inventory(repo):\n>     packdir = repo / '.git' / 'objects' / 'pack'\n>     return {p.name: hashlib.sha256(p.read_bytes()).hexdigest()\n>             for p in packdir.iterdir() if p.is_file()}\n>\n> print(git(work, '--version'))\n> source = work / 'source'\n> source.mkdir()\n> git(source, 'init', '--template=', '-b', 'main')\n> (source / 'large.bin').write_bytes(b'LARGE BLOB\\n' * 200000)\n> git(source, 'add', 'large.bin')\n> git(source, 'commit', '-m', 'Add historical blob')\n> blob = git(source, 'rev-parse', 'HEAD:large.bin')\n> git(source, 'rm', 'large.bin')\n> (source / 'tip.txt').write_text('tip\\n')\n> git(source, 'add', 'tip.txt')\n> git(source, 'commit', '-m', 'Remove historical blob')\n> remote = work / 'remote.git'\n> git(work, 'clone', '--bare', str(source), str(remote))\n> git(remote, 'config', 'uploadpack.allowFilter', 'true')\n>\n> for label, extra in [('dry-run', []), ('dry-run -d', ['-d'])]:\n>     repo = work / ('clone-delete' if extra else 'clone-preview')\n>     git(work, '-c', 'protocol.file.allow=always', 'clone', '--filter=blob:none',\n>         remote.as_uri(), str(repo))\n>     assert git(repo, 'cat-file', '-s', blob) == '2200000'\n>     before = inventory(repo)\n>     output = git(repo, 'repack', '-a', *extra, '--filter=blob:limit=1m',\n>                  '--drop-filtered', '--dry-run')\n>     after = inventory(repo)\n>     added = sorted(after.keys() - before.keys())\n>     removed = sorted(before.keys() - after.keys())\n>     changed = sorted(k for k in before.keys() & after.keys() if\n> before[k] != after[k])\n>     print(label + ': exit 0')\n>     print('candidate=' + output)\n>     print('pack directory: before=%d after=%d added=%d removed=%d changed=%d' %\n>           (len(before), len(after), len(added), len(removed), len(changed)))\n>     print('added extensions=' + ','.join(sorted(Path(k).suffix for k in added)))\n>     print('removed extensions=' + ','.join(sorted(Path(k).suffix for k\n> in removed)))\n>     print('candidate size after=' + git(repo, 'cat-file', '-s', blob))\n> shutil.rmtree(work)\n> ```\n>\n> ## Expected behavior\n>\n> The Git 2.56.0 `git-repack` manual says `--dry-run` should \"List the\n> objects that would be dropped, one object ID per line, without\n> rebuilding any pack or deleting anything.\"\n>\n> For both commands, Git should print the candidate blob and leave the\n> existing pack files and their contents unchanged. Explicit `-d` should\n> not cause deletion during this dry run. The fixture satisfies the\n> documented prerequisites: `-a`, a supported `blob:limit` filter, a\n> configured promisor remote, no operation in progress, and a candidate\n> absent from the current index.\n>\n> ## Actual behavior\n>\n> The executed script produced this output. The counts include regular\n> files in `objects/pack`, and `changed` compares SHA-256 content hashes\n> for names present before and after.\n>\n> ```text\n> git version 2.56.0\n> dry-run: exit 0\n> candidate=faed553c77de798540bd1edc898e174bf4436b28\n> pack directory: before=12 after=16 added=4 removed=0 changed=0\n> added extensions=.idx,.pack,.promisor,.rev\n> removed extensions=\n> candidate size after=2200000\n> dry-run -d: exit 0\n> candidate=faed553c77de798540bd1edc898e174bf4436b28\n> pack directory: before=12 after=4 added=4 removed=12 changed=0\n> added extensions=.idx,.pack,.promisor,.rev\n> removed extensions=.idx,.idx,.idx,.pack,.pack,.pack,.promisor,.promisor,.promisor,.rev,.rev,.rev\n> candidate size after=2200000\n> ```\n>\n> The ordinary preview added four files, one each with `.pack`, `.idx`,\n> `.promisor`, and `.rev` extensions. The preview with explicit `-d`\n> added the same four types and deleted the 12 previous pack and sidecar\n> files. Both invocations printed the expected candidate object ID and\n> exited 0. A subsequent `cat-file -s` still reported the blob's\n> original size in both clones.\n>\n> This report records one successful invocation of each variant in the\n> final script execution. A preceding fixture execution reproduced the\n> same counts. These observations establish the Git 2.56.0 behavior;\n> current development Git was not built or executed for this report.\n>\n> ## Evidence\n>\n> - Expected source: Git 2.56.0 [Documentation/git-repack.adoc, the\n> `--dry-run` option](https://github.com/git/git/blob/v2.56.0/Documentation/git-repack.adoc#L217-L220),\n> which promises no pack rebuilding or deletion.\n> - Failure source: The inline script and its captured output in Actual\n> behavior. The before/after pack inventories show four added files for\n> both variants and 12 deleted files when explicit `-d` is present.\n> - Evidence provenance: observed\n> - Local verification: reproduced\n> - Reproduction completeness: complete\n>\n> The primary violation evidence is execution of the inline fixture with\n> Git 2.56.0. Both commands exited 0 with the pack-directory changes\n> shown above. The manual and source links provide the contract and\n> supporting static evidence.\n>\n> The release source at [builtin/repack.c, lines\n> 356-394](https://github.com/git/git/blob/v2.56.0/builtin/repack.c#L356-L394)\n> guards the implicit `delete_redundant` setting with `!dry_run`, then\n> prints candidates when `dry_run` is set. Execution continues beyond\n> that block. This is a source breadcrumb consistent with the observed\n> results, rather than a required implementation change.\n>\n> The original implementation discussion also describes dry run as\n> leaving the repository unchanged: [v5\n> 1/6](https://lore.kernel.org/git/20260813200830.84348-2-r.siddharth.shrimali@gmail.com/)\n> and [v5 5/6](https://lore.kernel.org/git/20260813200830.84348-6-r.siddharth.shrimali@gmail.com/).\n>\n> ## Restoration check\n>\n> Run the same fixture after a fix. Both preview variants should still\n> print the candidate object ID and exit successfully, with `added=0\n> removed=0 changed=0` and equal before/after pack-directory counts.\n> Retaining the candidate output distinguishes a working preview from\n> simply skipping the operation. The cached blob should remain\n> available. Use the ordinary command and the explicit `-d` variant as\n> separate checks of the same no-write contract.\n>\n\n\n-- \nD. Ben Knoble\n\n"},{"id":"554433","messageId":"CAGWgyh9QTN8T=ZyvbEGA16acNw4KGLBeg1R4mt=E_nAGGU8APA@mail.gmail.com","threadId":"66462","inReplyTo":"CALnO6CCmv7PmxW2HTfvD8i6-PCVqMWgasyU9PYhPLXGj1sz=Hg@mail.gmail.com","subject":"Re: [BUG] repack --drop-filtered --dry-run writes packs and honors -d in Git 2.56.0","fromName":"Siddharth Shrimali","fromEmail":"r.siddharth.shrimali@gmail.com","sentAt":"2026-10-08T02:25:34Z","receivedAt":"2026-10-08T02:25:34Z","isPatch":false,"sender":{"key":"r.siddharth.shrimali@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183274193?v=4"},"body":"Hi Coy,\n\nOn Thu, 8 Oct 2026 at 00:40, D. Ben Knoble <ben.knoble@gmail.com> wrote:\n>\n> Cc: Siddharth Shrimali <r.siddharth.shrimali@gmail.com> who authored\n> the --drop-filtered code.\nThanks Ben for the cc\n\n> On Sun, Oct 4, 2026 at 7:47 PM Coy Geek <coygeek@gmail.com> wrote:\n> >\n> > On Git 2.56.0, `git repack -a --filter=blob:limit=1m --drop-filtered\n> > --dry-run` prints the candidate blob but also writes a new promisor\n> > pack and its sidecar files. Adding explicit `-d` also removes the old\n> > redundant packs and their sidecar files.\nThanks for the report and the reproducer.\n\nThe issue is that the --dry-run block in cmd_repack() prints the\ncandidates but does not stop there. it falls through to\nrepack_promisor_objects(), which writes the new promisor pack, and\nwith an explicit -d it also reaches existing_packs_remove_redundant(),\nwhich deletes the old packs. the earlier\n\"if (!dry_run) delete_redundant = 1\" only stops -d from being implied,\nnot from being given explicitly.\n\nThe fix is two lines in builtin/repack.c: at the end of the\n\"if (dry_run)\" block, right after the loop that prints the candidate\nobject IDs, add\n\n    ret = 0;\n    goto cleanup;\n\nso a dry run returns as soon as the candidates are listed, before any\npack is rebuilt or deleted.\n\nI will also add a test to t/t7706-repack-drop-filtered.sh that runs the\ndry run both without and with -d, and checks that the pack directory\nis unchanged, the candidate is still printed, and the blob is still\npresent\n\nI will send the patch shortly\n\nThanks,\nSiddharth\n\n"}]}