Mercurial > hg
changeset 34299:b1d4ac068961
blackbox: do not prevent 'chg init' from working
Previously, blackbox always appends to blackbox.log and creates the
directory for that file on demand. That could be an issue if:
1. chg starts from `$REPO` directory, so `ui._bbrepo` is set.
2. `rm -rf $REPO`.
3. `chg init $REPO`, blackbox writes something and `init` will fail
because `$REPO` directory is non-empty.
This patch fixes that by verifying whether vfs exists before re-using it.
Differential Revision: https://phab.mercurial-scm.org/D768
author | Jun Wu <quark@fb.com> |
---|---|
date | Thu, 21 Sep 2017 11:03:37 -0700 |
parents | 25e1a8876cc0 |
children | e6723c939344 |
files | hgext/blackbox.py tests/test-blackbox.t |
diffstat | 2 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/blackbox.py Mon Sep 11 20:07:41 2017 -0400 +++ b/hgext/blackbox.py Thu Sep 21 11:03:37 2017 -0700 @@ -77,9 +77,13 @@ class blackboxui(ui.__class__): @property def _bbvfs(self): + vfs = None repo = getattr(self, '_bbrepo', None) if repo: - return repo.vfs + vfs = repo.vfs + if not vfs.isdir('.'): + vfs = None + return vfs @util.propertycache def track(self): @@ -136,6 +140,10 @@ if not ui: return + vfs = ui._bbvfs + if not vfs: + return + repo = getattr(ui, '_bbrepo', None) if not lastui or repo: lastui = ui
--- a/tests/test-blackbox.t Mon Sep 11 20:07:41 2017 -0400 +++ b/tests/test-blackbox.t Thu Sep 21 11:03:37 2017 -0700 @@ -293,6 +293,13 @@ $ cd .. +With chg, blackbox should not create the log file if the repo is gone + + $ hg init repo1 + $ hg --config extensions.a=! -R repo1 log + $ rm -rf $TESTTMP/repo1 + $ hg --config extensions.a=! init repo1 + #endif blackbox should work if repo.ui.log is not called (issue5518)