tests/test-missing-capability.t
author Matt Harbison <matt_harbison@yahoo.com>
Sat, 03 Aug 2024 01:33:13 -0400
changeset 51871 cfd30df0f8e4
parent 47921 0c92cd9286ee
permissions -rw-r--r--
bundlerepo: fix mismatches with repository and revlog classes Both pytype and PyCharm complained that `write()` and `_write()` in the bundlephasecache class aren't proper overrides- indeed they seem to be missing an argument that the base class has. PyCharm and pytype also complained that the `revlog.revlog` class doesn't have a `_chunk()` method. That looks like it was moved from revlog to `_InnerRevlog` back in e8ad6d8de8b8, and wasn't caught because this module wasn't type checked. However, I couldn't figure out a syntax with `revlog.revlog._inner._chunk(self, rev)`, as it complained about passing too many args. `bundlerevlog._rawtext()` uses this `super(...)` style to call the super class, so hopefully that works, even with the wonky dynamic subclassing. The revlog class needed the `_InnerRevlog` field typed because it isn't set in the constructor. Finally, the vfs type hints look broken. This initially failed with: File "/mnt/c/Users/Matt/hg/mercurial/bundlerepo.py", line 65, in __init__: Function readonlyvfs.__init__ was called with the wrong arguments [wrong-arg-types] Expected: (self, vfs: mercurial.vfs.vfs) Actually passed: (self, vfs: Callable) Called from (traceback): line 232, in dirlog line 214, in __init__ I don't see a raw Callable, but I tried changing some of the vfs args to be typed as `vfsmod.abstractvfs`, but that class doesn't have `options`, so it failed elsewhere. `readonlyvfs` isn't a subclass of `vfs` (it's a subclass of `abstractvfs`), so I'm not sure how to handle that. It would be a shame to have to make a union of vfs subclasses (but not all of them have `options` either).

Checking how hg behaves when one side of a pull/push doesn't support
some capability (because it's running an older hg version, usually).

  $ hg init repo1
  $ cd repo1
  $ echo a > a; hg add -q a; hg commit -q -m a
  $ hg bookmark a
  $ hg clone -q . ../repo2
  $ cd ../repo2

  $ touch $TESTTMP/disable-lookup.py
  $ disable_cap() {
  >   rm -f $TESTTMP/disable-lookup.pyc # pyc caching is buggy
  >   cat <<EOF > $TESTTMP/disable-lookup.py
  > from mercurial import extensions, wireprotov1server
  > def wcapabilities(orig, *args, **kwargs):
  >   cap = orig(*args, **kwargs)
  >   cap.remove(b'$1')
  >   return cap
  > extensions.wrapfunction(wireprotov1server, '_capabilities', wcapabilities)
  > EOF
  > }
  $ cat >> ../repo1/.hg/hgrc <<EOF
  > [extensions]
  > disable-lookup = $TESTTMP/disable-lookup.py
  > EOF

  $ hg pull ssh://user@dummy/repo1 -r tip -B a
  pulling from ssh://user@dummy/repo1
  no changes found

  $ disable_cap lookup
  $ hg pull ssh://user@dummy/repo1 -r tip -B a
  pulling from ssh://user@dummy/repo1
  abort: other repository doesn't support revision lookup, so a rev cannot be specified.
  [255]

  $ disable_cap pushkey
  $ hg pull ssh://user@dummy/repo1 -r tip -B a
  pulling from ssh://user@dummy/repo1
  abort: remote bookmark a not found!
  [10]