Git fails with `fatal: transport 'file' not allowed`
langfield opened this issue · comments
Here is the stack trace:
Traceback (most recent call last):
File "/home/runner/work/ki/ki/submodule.py", line 117, in <module>
main()
File "<@beartype(__main__.main) at 0x7f761029d1f0>", line 10, in main
File "/home/runner/work/ki/ki/submodule.py", line 106, in main
repo.git.submodule("add", args.remote, args.deck)
File "/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/git/cmd.py", line 696, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/git/cmd.py", line 1270, in _call_process
return self.execute(call, **exec_kwargs)
File "/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/git/cmd.py", line 1064, in execute
raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
cmdline: git submodule add /tmp/pytest-of-runner/pytest-1/test_pull_succeeds_with_new_su0/tmpoaffg316/aa_remote/.git aa
stderr: 'Cloning into '/tmp/pytest-of-runner/pytest-1/test_pull_succeeds_with_new_su0/tmpoaffg316/multideck/aa'...
fatal: transport 'file' not allowed
fatal: clone of '/tmp/pytest-of-runner/pytest-1/test_pull_succeeds_with_new_su0/tmpoaffg316/aa_remote/.git' into submodule path '/tmp/pytest-of-runner/pytest-1/test_pull_succeeds_with_new_su0/tmpoaffg316/multideck/aa' failed'
And here is the source:
@beartype
def main() -> None:
"""Convert a arbitrary subdeck into a git submodule with remote."""
# Parse command-line arguments.
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("--kirepo", required=True, help=HELP_KIREPO.lstrip("\n"))
parser.add_argument("--deck", required=True, help=HELP_DECK.lstrip("\n"))
parser.add_argument("--remote", required=True, help=HELP_REMOTE.lstrip("\n"))
args: argparse.Namespace = parser.parse_args()
# Make a copy of the given repository.
kirepo = M.kirepo(F.chk(Path(args.kirepo)))
repo: git.Repo = kirepo.repo
head: Rev = M.head(repo)
copy: git.Repo = cp_repo(head, f"submodule-{head.sha}")
copyroot: Dir = F.root(copy)
# Harden all symlinks.
_ = map(M.hardlink, F.walk(copyroot))
# Filter ``copy`` to include only the given deck.
print(f"Operating on '{copyroot}'")
F.chdir(copyroot)
arglist: List[str] = ["--subdirectory-filter", args.deck, "--force"]
gfrargs = git_filter_repo.FilteringOptions.parse_args(arglist, error_on_empty=False)
git_filter_repo.RepoFilter(gfrargs).run()
# Clean up.
copy.git.reset(hard=True)
copy.git.gc(aggressive=True)
copy.git.prune()
# Delete all remotes.
for remote in copy.remotes:
copy.delete_remote(remote)
assert not remote.exists()
assert len(copy.remotes) == 0
# Add the new remote.
remote = copy.create_remote(REMOTE_NAME, args.remote)
assert remote.exists()
# Commit in the submodule.
copy.git.add(all=True)
copy.index.commit("Initial submodule commit.")
out = copy.git.push("--set-upstream", REMOTE_NAME, BRANCH_NAME, force=True)
print(out)
# Remove the deck and commit the deletion in the original repo.
F.chdir(kirepo.root)
try:
repo.git.rm(args.deck, r=True, f=True)
except git.exc.GitCommandError as err:
if "did not match any files" not in err.stderr:
raise err
deck = F.chk(Path(args.deck))
if isinstance(deck, Dir):
F.rmtree(deck)
repo.index.commit(f"Remove '{args.deck}'")
# Add, initialize, and update the submodule.
repo.git.submodule("add", args.remote, args.deck)
repo.git.submodule("init")
repo.git.submodule("update")
# Commit the addition.
repo.git.add(".gitmodules", args.deck)
sha = repo.index.commit(f"Add submodule '{args.deck}' with remote '{args.remote}'")
print(f"Committed submodule at rev '{sha}'")
Any ideas how to fix this?
I'm confused; nothing in your stacktrace or code in any way references git-filter-repo and there isn't even a trace of an explanation to claim you're actually using it, so I am at a loss as to why you filed a ticket against this project. Did you just accidentally file it against the wrong project or something?
How about this line:
git_filter_repo.RepoFilter(gfrargs).run()
In the block whose comment starts with # Filter ...
?
Okay indeed there was a fix that was unrelated to git filter-repo
.
How about this line:
git_filter_repo.RepoFilter(gfrargs).run()In the block whose comment starts with
# Filter ...
?
Oops, yeah, I missed that line.
Okay indeed there was a fix that was unrelated to
git filter-repo
.
Glad you were able to find it.