Skip to content

update --how(-subds) (!=fetch) cannot handle adjusted branches #7507

Closed

Description

@mih

Here is an example

C:\Users\mih\paper-remodnav>datalad update -r --how-subds reset
[INFO] Fetching updates for Dataset("C:\Users\mih\paper-remodnav")
update(ok): . (dataset)
[INFO] Fetching updates for Dataset("C:\Users\mih\paper-remodnav\data\raw_eyegaze")
CommandError: '"git" "-c" "diff.ignoreSubmodules=none" "-c" "core.quotepath=false" "rev-parse" "--symbolic-full-name" "--abbrev-ref=strict" "@{upstream}"' failed with exitcode 128
fatal: no upstream configured for branch 'adjusted/master(unlocked)'

C:\Users\mih\paper-remodnav>cd C:\Users\mih\paper-remodnav\data\raw_eyegaze

C:\Users\mih\paper-remodnav\data\raw_eyegaze>git branch -a
* adjusted/master(unlocked)
  git-annex
  master
  remotes/mddatasrc/git-annex
  remotes/mddatasrc/master
  remotes/mddatasrc/synced/git-annex
  remotes/mddatasrc/synced/master
  remotes/origin/HEAD -> origin/master
  remotes/origin/git-annex
  remotes/origin/master

It looks, as if it is simply not considering the presence of adjusted branches.

Looking at the scenarios affected: Any update mode other than fetch leads to this crash, and need not be a subdataset either.

Activity

  1. added
    adjusted-branchesIssues caused by or affected adjusted branch operation
    cmd-updateIssues relates to update functionality
    on Oct 12, 2023
  2. changed the title [-]`update --how-subds reset` cannot handle adjusted branches[/-] [+]`update --how(-subds) (!=fetch)` cannot handle adjusted branches[/+] on Oct 12, 2023
  3. mih commented on Oct 24, 2023

    @mih
    MemberAuthor

    Looking through the tests, this is known for some time, and the tests are configured to be skipped.

  4. mih commented on Oct 25, 2023

    @mih
    MemberAuthor

    The skipped tests do not seem to be the core issue (or cover them). I also saw that the error handling is different between super and subdatasets

    ❯ datalad clone git@github.com:psychoinformatics-de/paper-remodnav.git
    ❯ datalad update --how reset
    update(impossible): . (dataset) [Updating via 'reset' is incompatible with adjusted branches]
    ❯ datalad update --how ff-only
    update(impossible): . (dataset) [Updating via 'ff-only' is incompatible with adjusted branches]
    ❯ datalad update --how checkout
    update(impossible): . (dataset) [Updating via 'checkout' is incompatible with adjusted branches]
    ❯ datalad update --how merge
    update.annex_sync(ok): . (dataset) [Ran git-annex-sync]
    update(ok): . (dataset)
    

    So this is good. Running this any number of times is also not an issue.

    The handling for a subdataset is different:

    (in that same superdataset)

    ❯ datalad get -n data/raw_eyegaze
    install(ok): /media/mih/Samsung_T5/datalad-tests/paper-remodnav/data/raw_eyegaze (dataset) [Installed subdataset in order to get /media/mih/Samsung_T5/datalad-tests/paper-remodnav/data/raw_eyegaze]
    # cd to avoid any possible complication introduced by subdataset handling
    ❯ cd data/raw_eyegaze
    ❯ datalad update --how merge
    [INFO   ] Fetching updates for Dataset(/media/mih/Samsung_T5/datalad-tests/paper-remodnav/data/raw_eyegaze) 
    CommandError: 'git -c diff.ignoreSubmodules=none -c core.quotepath=false rev-parse --symbolic-full-name --abbrev-ref=strict '@{upstream}'' failed with exitcode 128
    fatal: no upstream configured for branch 'adjusted/master(unlocked)'
    

    Running update any number of times give the same outcome.

    Right now it is unclear to me, whether this is caused by the subdataset actually having things to update (while the superdataset was freshly cloned and did not have things to merge).

  5. mih commented on Oct 25, 2023

    @mih
    MemberAuthor

    So here is the piece that blows up

    HUGE THANKS to the one who wrote the comment!
    Edit: This goes to @kyleam 76a7283

    > /home/mih/hacking/datalad/git/datalad/distribution/update.py(482)_choose_update_target()
    -> target = repo.call_git_oneline(
    (Pdb) l
    477             # In this scenario, it's tempting to use FETCH_HEAD as the target. For
    478             # a merge, that would be the equivalent of 'git pull REMOTE'. But doing
    479             # so would be problematic when the GitRepo.fetch() call was passed
    480             # all_=True. Given we can't use FETCH_HEAD, it's tempting to use the
    481             # branch.*.merge value, but that assumes a value for remote.*.fetch.
    482  ->         target = repo.call_git_oneline(
    483                 ["rev-parse", "--symbolic-full-name", "--abbrev-ref=strict",
    484                  "@{upstream}"],
    485                 read_only=True)
    486         elif branch:
    487             remote_branch = "{}/{}".format(remote, branch)
    (Pdb) p repo
    AnnexRepo('/media/mih/Samsung_T5/datalad-tests/paper-remodnav/data/raw_eyegaze')
    (Pdb) p branch
    'adjusted/master(unlocked)'
    (Pdb) p remote
    'origin'
    (Pdb) p cfg_remote
    'origin'
    

    So we want to change that from

    ❯ git rev-parse --symbolic-full-name --abbrev-ref=strict @{upstream}
    fatal: no upstream configured for branch 'adjusted/master(unlocked)'
    

    to

    ❯ git rev-parse --symbolic-full-name --abbrev-ref=strict master@{upstream}
    origin/master
    

    where master is the return value of repo.get_corresponding_branch(branch)

    So taken together, the following patch fixes the issue, at least for this particular case:

    diff --git a/datalad/distribution/update.py b/datalad/distribution/update.py
    index 4dde06d52..216186cec 100644
    --- a/datalad/distribution/update.py
    +++ b/datalad/distribution/update.py
    @@ -481,7 +481,7 @@ def _choose_update_target(repo, branch, remote, cfg_remote):
             # branch.*.merge value, but that assumes a value for remote.*.fetch.
             target = repo.call_git_oneline(
                 ["rev-parse", "--symbolic-full-name", "--abbrev-ref=strict",
    -             "@{upstream}"],
    +             f"{repo.get_corresponding_branch(branch) or ''}" "@{upstream}"],
                 read_only=True)
         elif branch:
             remote_branch = "{}/{}".format(remote, branch)
  6. mih commented on Oct 25, 2023

    @mih
    MemberAuthor

    I suspect the reason that we do not see this breakage in the tests is that we only test in-sync, i.e. update source and target are jointly in adjusted mode, or not.

  7. mih commented on Oct 25, 2023

    @mih
    MemberAuthor

    It is not that simple. I cannot show the breakage when forcing a dataset into adjusted mode AFTER clone created a normal mode repository. It does not matter whether it is a superdataset or a subdataset.

    Using the reproducer from above as a test case is way too heavy.

    But this one works always, on crippled FS or not:

    diff --git a/datalad/distribution/tests/test_update.py b/datalad/distribution/tests/test_update.py
    index befcd4077..23438199f 100644
    --- a/datalad/distribution/tests/test_update.py
    +++ b/datalad/distribution/tests/test_update.py
    @@ -61,6 +61,8 @@ from datalad.utils import (
     
     from ..dataset import Dataset
     
    +common_kwargs = {'result_renderer': 'disabled'}
    +
     
     @slow
     @with_tempfile(mkdir=True)
    @@ -1120,3 +1121,35 @@ def test_update_fetch_failure(path=None):
             status="ok",
             path=ds_b.path,
             action="update")
    +
    +
    +def test_update_adjusted_from_any(tmp_path):
    +    src = Dataset(tmp_path / "src").create(**common_kwargs)
    +    cln = clone(source=src, path=tmp_path / 'cln', **common_kwargs)
    +    # we force the clone into adjusted mode to be able to
    +    # also test source and clone being in different modes
    +    cln.repo.call_annex(['adjust', '--unlock'])
    +
    +    # now modify the source and update
    +    testfile = 'testfile'
    +    (src.pathobj / testfile).write_text(testfile)
    +    src.save(**common_kwargs)
    +    cln.update(how='merge', **common_kwargs)
    +    # we are in adjusted mode, any annexed file in the clone should
    +    # be a real file, not just a symlink, regardless of content presence
    +    assert (cln.pathobj / testfile).exists()
    +
    +    # now we add a subdataset at the source, clone it, and also force the
    +    # clone into adjusted mode
    +    subds = src.create('sub', **common_kwargs)
    +    cln.update(how='merge', **common_kwargs)
    +    subdscln = cln.get(
    +        'sub', get_data=False,
    +        result_xfm='datasets', return_type='item-or-list', **common_kwargs)
    +    subdscln.repo.call_annex(['adjust', '--unlock'])
    +
    +    # now we modify the subdataset
    +    (subds.pathobj / testfile).write_text(testfile)
    +    src.save(recursive=True, **common_kwargs)
    +    cln.update(recursive=True, how='merge', **common_kwargs)
    +    assert (subdscln.pathobj / testfile).exists()
    
  8. mih commented on Oct 25, 2023

    @mih
    MemberAuthor

    It is also not about the clone into adjusted mode. This test implementation also always works

    diff --git a/datalad/distribution/tests/test_update.py b/datalad/distribution/tests/test_update.py
    index befcd4077..893064833 100644
    --- a/datalad/distribution/tests/test_update.py
    +++ b/datalad/distribution/tests/test_update.py
    @@ -61,6 +61,8 @@ from datalad.utils import (
     
     from ..dataset import Dataset
     
    +common_kwargs = {'result_renderer': 'disabled'}
    +
     
     @slow
     @with_tempfile(mkdir=True)
    @@ -1120,3 +1121,23 @@ def test_update_fetch_failure(path=None):
             status="ok",
             path=ds_b.path,
             action="update")
    +
    +
    +def test_update_adjusted_from_any(tmp_path):
    +    from datalad.dataset.gitrepo import GitRepo as LeanGitRepo
    +    barepath = tmp_path / 'bare'
    +    barepath.mkdir()
    +    LeanGitRepo(barepath).call_git(['init', '--bare'])
    +    src = Dataset(tmp_path / "src").create(**common_kwargs)
    +    src.siblings('add', name='origin', url=str(barepath), **common_kwargs)
    +    src.push(to='origin', **common_kwargs)
    +
    +    cln = clone(source=barepath, path=tmp_path / 'cln', **common_kwargs)
    +
    +    # now modify the source and update
    +    testfile = 'testfile'
    +    (src.pathobj / testfile).write_text(testfile)
    +    src.save(**common_kwargs)
    +    src.push(to='origin', **common_kwargs)
    +    cln.update(how='merge', **common_kwargs)
    +    assert op.lexists(cln.pathobj / testfile)
  9. mih commented on Oct 25, 2023

    @mih
    MemberAuthor

    Even this one does work all the time

    diff --git a/datalad/distribution/tests/test_update.py b/datalad/distribution/tests/test_update.py
    index befcd4077..56f067789 100644
    --- a/datalad/distribution/tests/test_update.py
    +++ b/datalad/distribution/tests/test_update.py
    @@ -61,6 +61,8 @@ from datalad.utils import (
     
     from ..dataset import Dataset
     
    +common_kwargs = {'result_renderer': 'disabled'}
    +
     
     @slow
     @with_tempfile(mkdir=True)
    @@ -1120,3 +1121,36 @@ def test_update_fetch_failure(path=None):
             status="ok",
             path=ds_b.path,
             action="update")
    +
    +
    +def test_update_adjusted_from_any(tmp_path):
    +    from datalad.dataset.gitrepo import GitRepo as LeanGitRepo
    +    # create two datasets and push them to bare remotes
    +    barepath = tmp_path / 'bare'
    +    barepath_sub = tmp_path / 'baresub'
    +    for p in (barepath, barepath_sub):
    +        p.mkdir()
    +        LeanGitRepo(p).call_git(['init', '--bare'])
    +    src = Dataset(tmp_path / "src").create(**common_kwargs)
    +    subds = Dataset(tmp_path / "sub").create(**common_kwargs)
    +    for ds, p in ((src, barepath), (subds, barepath_sub)):
    +        ds.siblings('add', name='origin', url=str(p), **common_kwargs)
    +        ds.push(to='origin', **common_kwargs)
    +    # make one dataset the subdatasets of the other and push that change
    +    src.clone(barepath_sub, 'sub', **common_kwargs)
    +    src.push(to='origin', **common_kwargs)
    +
    +    # clone the superdataset
    +    cln = clone(source=barepath, path=tmp_path / 'cln', **common_kwargs)
    +    # get the subdataset
    +    subdscln = cln.get(
    +        'sub', get_data=False,
    +        result_xfm='datasets', return_type='item-or-list', **common_kwargs)
    +
    +    # now modify the source-subds and update
    +    testfile = 'testfile'
    +    (subds.pathobj / testfile).write_text(testfile)
    +    subds.save(**common_kwargs)
    +    subds.push(to='origin', **common_kwargs)
    +    subdscln.update(how='merge', **common_kwargs)
    +    assert op.lexists(subdscln.pathobj / testfile)
    
  10. mih commented on Oct 25, 2023

    @mih
    MemberAuthor

    So bottom-line, the only way to reproduce ATM is:

    on a crippled FS

    ❯ datalad clone git@github.com:psychoinformatics-de/paper-remodnav.git
    ❯ cd paper-remodnav
    ❯ datalad get -n data/raw_eyegaze
    ❯ cd data/raw_eyegaze
    ❯ datalad update --how merge
    CommandError: 'git -c diff.ignoreSubmodules=none -c core.quotepath=false rev-parse --symbolic-full-name --abbrev-ref=strict '@{upstream}'' failed with exitcode 128
    fatal: no upstream configured for branch 'adjusted/master(unlocked)'
    

    and with the patch

    diff --git a/datalad/distribution/update.py b/datalad/distribution/update.py
    index 4dde06d52..216186cec 100644
    --- a/datalad/distribution/update.py
    +++ b/datalad/distribution/update.py
    @@ -481,7 +481,7 @@ def _choose_update_target(repo, branch, remote, cfg_remote):
             # branch.*.merge value, but that assumes a value for remote.*.fetch.
             target = repo.call_git_oneline(
                 ["rev-parse", "--symbolic-full-name", "--abbrev-ref=strict",
    -             "@{upstream}"],
    +             f"{repo.get_corresponding_branch(branch) or ''}" "@{upstream}"],
                 read_only=True)
         elif branch:
             remote_branch = "{}/{}".format(remote, branch)

    the same code works, and updates the subdataset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    adjusted-branchesIssues caused by or affected adjusted branch operationcmd-updateIssues relates to update functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions