Skip to content

Commit

Permalink
Suppress spurious error output during LFS push
Browse files Browse the repository at this point in the history
  • Loading branch information
olsen232 committed Sep 27, 2022
1 parent b991a09 commit efbb5aa
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions kart/lfs_commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from kart.object_builder import ObjectBuilder
from kart.rev_list_objects import rev_list_tile_pointer_files
from kart.repo import KartRepoState
from kart.subprocess_util import subprocess_tee

EMPTY_SHA = "0" * 40

Expand Down Expand Up @@ -99,30 +98,40 @@ def push_lfs_oids(repo, remote_name, lfs_oids):
push all of those LFS blobs from the local cache to the given remote.
"""
# Older git-lfs doesn't support stdin so we fall back to using args if we somehow have an older version.
if not _push_lfs_oids_using_stdin(repo, remote_name, lfs_oids):
if _git_lfs_supports_stdin(repo):
_push_lfs_oids_using_stdin(repo, remote_name, lfs_oids)
else:
_push_lfs_oids_using_args(repo, remote_name, lfs_oids)


def _git_lfs_supports_stdin(repo):
r = subprocess.run(
["git-lfs", "push", "?", "--object-id", "--stdin"],
env=tool_environment(),
cwd=repo.workdir_path,
capture_output=True,
text=True,
)
return "unknown flag: --stdin" not in r.stderr


def _push_lfs_oids_using_stdin(repo, remote_name, lfs_oids):
# TODO - capture progress reporting and do our own.
with tempfile.TemporaryFile() as oid_file:
oid_file.write("\n".join(lfs_oids).encode("utf-8"))
oid_file.write(b"\n")
oid_file.seek(0)

returncode, stdout, stderr = subprocess_tee(
["git-lfs", "push", remote_name, "--object-id", "--stdin"],
env=tool_environment(),
cwd=repo.workdir_path,
stdin=oid_file,
)
if returncode == 0:
return True
elif b"unknown flag: --stdin" in stderr:
return False
else:
try:
# TODO - capture progress reporting and do our own.
subprocess.check_call(
["git-lfs", "push", remote_name, "--object-id", "--stdin"],
env=tool_environment(),
cwd=repo.workdir_path,
stdin=oid_file,
)
except subprocess.CalledProcessError as e:
raise SubprocessError(
"There was a problem with git-lfs push", exit_code=returncode
f"There was a problem with git-lfs push: {e}", called_process_error=e
)


Expand Down

0 comments on commit efbb5aa

Please sign in to comment.