Skip to content

Commit

Permalink
Merge pull request datalad#4200 from yarikoptic/bf-publish-fresh
Browse files Browse the repository at this point in the history
BF: allow for fetch to fail due to HEAD not yet been available on a remote for annex
  • Loading branch information
yarikoptic authored Feb 29, 2020
2 parents 09faea2 + 1dc0fdc commit 43c671d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
17 changes: 14 additions & 3 deletions datalad/distribution/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
from datalad.support.constraints import EnsureNone
from datalad.support.annexrepo import AnnexRepo
from datalad.support.sshconnector import sh_quote
from datalad.support.exceptions import InsufficientArgumentsError
from datalad.support.exceptions import (
InsufficientArgumentsError,
)
from datalad.support.network import URL, RI, SSHRI, is_ssh

from datalad.utils import assure_list
Expand Down Expand Up @@ -259,6 +261,15 @@ def _check_and_update_remote_server_info(ds, remote):
return False


def _maybe_fetch(repo, remote):
if repo.config.get("remote.{}.fetch".format(remote)):
repo.fetch(remote=remote)
else:
# Fetching would lead to "Couldn't find remote ref HEAD" if no
# branch" error. See gh-4199 for an example.
lgr.warning("Remote %s has no configured refspec", remote)


def _publish_dataset(ds, remote, refspec, paths, annex_copy_options, force=False, jobs=None,
transfer_data='auto', **kwargs):
remote_branch_name = _get_remote_branch(ds, refspec)
Expand Down Expand Up @@ -288,7 +299,7 @@ def _publish_dataset(ds, remote, refspec, paths, annex_copy_options, force=False
for r in publish_depends + [remote]:
if not ds.config.get('.'.join(('remote', remote, 'annex-uuid')), None):
lgr.debug("Obtain remote annex info from '%s'", r)
ds.repo.fetch(remote=r)
_maybe_fetch(ds.repo, r)
# in order to be able to use git's config to determine what to push,
# we need to annex merge first. Otherwise a git push might be
# rejected if involving all matching branches for example.
Expand Down Expand Up @@ -420,7 +431,7 @@ def _publish_dataset(ds, remote, refspec, paths, annex_copy_options, force=False
# even if we already fetched above we need to do it again
if is_annex_repo:
lgr.debug("Obtain remote annex info from '%s'", remote)
ds.repo.fetch(remote=remote)
_maybe_fetch(ds.repo, remote)
ds.repo.merge_annex(remote)

# Note: git's push.default is 'matching', which doesn't work for first
Expand Down
20 changes: 19 additions & 1 deletion datalad/distribution/tests/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
from nose.tools import assert_false as nok_
from datalad.tests.utils import with_tempfile, assert_in, \
with_testrepos, assert_not_in
from datalad.utils import _path_
from datalad.utils import (
_path_,
Path,
)
from datalad.tests.utils import assert_raises
from datalad.tests.utils import assert_false
from datalad.tests.utils import assert_not_equal
Expand Down Expand Up @@ -713,3 +716,18 @@ def test_gh1811(srcpath, clonepath):
path=clone.path, type='dataset', action='publish',
status='impossible',
message=('Cannot determine remote branch name from %s', 'HEAD'))


@with_tempfile(mkdir=True)
def test_publish_no_fetch_refspec_configured(path):
from datalad.cmd import GitRunner

path = Path(path)
GitRunner(cwd=str(path)).run(["git", "init", "--bare", "empty-remote"])
ds = Dataset(path / "ds").create()
ds.repo.add_remote("origin", str(ds.pathobj.parent / "empty-remote"))
# Mimic a situation that can happen with an LFS remote. See gh-4199.
ds.repo.config.unset("remote.origin.fetch", where="local")
(ds.repo.pathobj / "foo").write_text("a")
ds.save()
ds.publish(to="origin")

0 comments on commit 43c671d

Please sign in to comment.