Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commits could be mistakenly pruned in subsequent RepoFilter().run() #617

Open
louiswpf opened this issue Dec 11, 2024 · 0 comments
Open

Comments

@louiswpf
Copy link

louiswpf commented Dec 11, 2024

Commits could be mistakenly pruned in subsequent RepoFilter().run() when using
filter-repo as a library. This is due to _SKIPPED_COMMITS not being cleared in
subsequent runs.

Here is a reproducer:

  • test.py
import subprocess
from pathlib import Path

import git_filter_repo as fr

subprocess.run(["git", "init", "r0", "-q"], check=True)
(Path("r0") / "f").touch()
subprocess.run(["git", "-C", "r0", "add", "f"], check=True)
subprocess.run(["git", "-C", "r0", "commit", "-m", "c0", "-q"], check=True)

subprocess.run(["git", "init", "r1", "-q"], check=True)
for msg in ["c0", "c1"]:
  subprocess.run(
    ["git", "-C", "r1", "commit", "--allow-empty", "-m", msg, "-q"], check=True
  )

print("r1 before:")
subprocess.run(["git", "-C", "r1", "log", "--oneline"], check=True)

for repo in ["r0", "r1"]:
  print(f"_SKIPPED_COMMITS: {fr._SKIPPED_COMMITS}")
  args = fr.FilteringOptions.parse_args(
    ["-f", f"--source={repo}", f"--target={repo}", "--path=nothing", "--quiet"]
  )
  fr.RepoFilter(args).run()

print("r1 after:")
subprocess.run(["git", "-C", "r1", "log", "--oneline"], check=True)
$ python test.py
r1 before:
1c29cdf (HEAD -> main) c1
962b81e c0
_SKIPPED_COMMITS: set()
New history written in 0.01 seconds; now repacking/cleaning...
Completely finished after 0.04 seconds.
_SKIPPED_COMMITS: {1}
New history written in 0.01 seconds; now repacking/cleaning...
Completely finished after 0.04 seconds.
r1 after:
962b81e (HEAD -> main) c0
@louiswpf louiswpf changed the title Commits could be mistakenly pruned in subsequent RepoFilter().run() Commits could be mistakenly pruned in subsequent RepoFilter().run() Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant