tests/test-update-names.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 39593 c8514f858788
permissions -rw-r--r--
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.

Test update logic when there are renames or weird same-name cases between dirs
and files

Update with local changes across a file rename

  $ hg init r1 && cd r1

  $ echo a > a
  $ hg add a
  $ hg ci -m a

  $ hg mv a b
  $ hg ci -m rename

  $ echo b > b
  $ hg ci -m change

  $ hg up -q 0

  $ echo c > a

  $ hg up
  merging a and b to b
  warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
  use 'hg resolve' to retry unresolved file merges
  [1]

Test update when local untracked directory exists with the same name as a
tracked file in a commit we are updating to
  $ hg init r2 && cd r2
  $ echo root > root && hg ci -Am root  # rev 0
  adding root
  $ echo text > name && hg ci -Am "name is a file"  # rev 1
  adding name
  $ hg up 0
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ mkdir name
  $ hg up 1
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved

Test update when local untracked directory exists with some files in it and has
the same name a tracked file in a commit we are updating to. In future this
should be updated to give an friendlier error message, but now we should just
make sure that this does not erase untracked data
  $ hg up 0
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ mkdir name
  $ echo text > name/file
  $ hg st
  ? name/file
  $ hg up 1
  abort: Unlinking directory not permitted: *$TESTTMP/r1/r2/name* (glob) (windows !)
  abort: Directory not empty: '?\$TESTTMP/r1/r2/name'? (re) (no-windows !)
  [255]
  $ cat name/file
  text
  $ cd ..

#if symlink

Test update when two commits have symlinks that point to different folders
  $ hg init r3 && cd r3
  $ echo root > root && hg ci -Am root
  adding root
  $ mkdir folder1 && mkdir folder2
  $ ln -s folder1 folder
  $ hg ci -Am "symlink to folder1"
  adding folder
  $ rm folder
  $ ln -s folder2 folder
  $ hg ci -Am "symlink to folder2"
  $ hg up 1
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cd ..

#endif

#if rmcwd

Test that warning is printed if cwd is deleted during update
  $ hg init r4 && cd r4
  $ mkdir dir
  $ cd dir
  $ echo a > a
  $ echo b > b
  $ hg add a b
  $ hg ci -m "file and dir"
  $ hg up -q null
  current directory was removed
  (consider changing to repo root: $TESTTMP/r1/r4)

#endif