Skip to content

Commit

Permalink
Discontinue use of GitRepo.call_git...() outside tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mih committed Feb 7, 2024
1 parent 3b6508b commit 6c2005e
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions datalad_next/gitremotes/datalad_annex.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,9 @@ def repoannex(self):
try:
# send annex into private mode, if supported
# this repo will never ever be shared
ra.call_git(['config', 'annex.private', 'true'])
ra.call_git(['annex', 'init'])
call_git_success(['config', 'annex.private', 'true'],
cwd=ra.pathobj, capture_output=True)
call_git_success(['annex', 'init'], capture_output=True)
ra = AnnexRepo(self._repoannexdir)
if 'type=web' in self.initremote_params:
self._init_repoannex_type_web(ra)
Expand Down Expand Up @@ -622,8 +623,15 @@ def mirrorrepo(self):
# otherwise we can end up in a conflict situation where the mirror
# points to 'master' (or something else) and the source actually
# has 'main' (or something different)
src_head_ref = self.repo.call_git(['symbolic-ref', 'HEAD']).strip()
mr.call_git(['symbolic-ref', 'HEAD', src_head_ref])
src_head_ref = call_git_oneline(
['symbolic-ref', 'HEAD'],
cwd=self.repo.pathobj,
).strip()
call_git_success(
['symbolic-ref', 'HEAD', src_head_ref],
cwd=mr.pathobj,
capture_output=True,
)

self.log('Established mirror')
self._mirrorrepo = mr
Expand Down Expand Up @@ -700,12 +708,15 @@ class instance.
for ref in post_refs:
# best MIH can think of is to leave behind another
# ref to indicate the unsuccessful upload
self.repo.call_git([
call_git_success([
'update-ref',
# strip 'refs/heads/' from refname
f'refs/dlra-upload-failed/{self.remote_name}/'
f'{ref["refname"][11:]}',
ref['objectname']])
ref['objectname']],
cwd=self.repo.pathobj,
capture_output=True,
)
raise

# clean-up potential upload failure markers for this particular
Expand All @@ -714,7 +725,11 @@ class instance.
for ref in self.repo.for_each_ref_(
fields=('refname',),
pattern=f'refs/dlra-upload-failed/{self.remote_name}'):
self.repo.call_git(['update-ref', '-d', ref['refname']])
call_git_success(
['update-ref', '-d', ref['refname']],
cwd=self.repo.pathobj,
capture_output=True,
)
# we do not need to update `self._cached_remote_refs`,
# because we end the remote-helper process here
# everything has worked, if we used a credential, update it
Expand Down Expand Up @@ -768,7 +783,7 @@ def replace_remote_deposit_from_mirrorrepo(self):
repoannex = self.repoannex

# trim it down, as much as possible
mirrorrepo.call_git(['gc'])
call_git(['gc'], cwd=mirrorrepo.pathobj)

# update the repo state keys
# it is critical to drop the local keys first, otherwise
Expand Down Expand Up @@ -1049,7 +1064,10 @@ def _format_refs(repo, refs=None):
if refstr:
refstr += '\n'
refstr += '@{} HEAD\n'.format(
repo.call_git(['symbolic-ref', 'HEAD']).strip()
call_git_oneline(
['symbolic-ref', 'HEAD'],
cwd=repo.pathobj,
).strip()
)
return refstr

Expand Down

0 comments on commit 6c2005e

Please sign in to comment.