# HG changeset patch # User Yuya Nishihara # Date 1454759000 -32400 # Node ID 89003c49315c507a5bab40ddd7f790791ec7c30c # Parent 72f2a19c5f88791e156711e4a90f241a1a8b3c0c ui: fix crash by non-interactive prompt echo for user name Since we've dropped a str cast at write() by f04bd381e8c0, ui.prompt() should convert default to '' if it is None. Otherwise, write() would fail with "TypeError: object of type 'NoneType' has no len()". This patch includes the tests for both interactive and non-interactive cases because "ui.askusername" was never tested. diff -r 72f2a19c5f88 -r 89003c49315c mercurial/ui.py --- a/mercurial/ui.py Wed Feb 10 22:53:17 2016 +0900 +++ b/mercurial/ui.py Sat Feb 06 20:43:20 2016 +0900 @@ -798,7 +798,7 @@ If ui is not interactive, the default is returned. """ if not self.interactive(): - self.write(msg, ' ', default, "\n") + self.write(msg, ' ', default or '', "\n") return default try: r = self._readline(self.label(msg, 'ui.prompt')) diff -r 72f2a19c5f88 -r 89003c49315c tests/test-committer.t --- a/tests/test-committer.t Wed Feb 10 22:53:17 2016 +0900 +++ b/tests/test-committer.t Sat Feb 06 20:43:20 2016 +0900 @@ -66,6 +66,31 @@ date: Thu Jan 01 00:00:00 1970 +0000 summary: commit-1 +# test prompt username + + $ cat > .hg/hgrc < [ui] + > askusername = True + > EOF + + $ echo 12345 > asdf + $ hg commit --config ui.interactive=False -m ask + enter a commit username: + no username found, using '[^']*' instead (re) + $ hg rollback -q + + $ hg commit --config ui.interactive=True -m ask < Asked User + > EOF + enter a commit username: Asked User + $ hg tip + changeset: 5:84c91d963b70 + tag: tip + user: Asked User + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ask + + # test no .hg/hgrc (uses generated non-interactive username) $ echo space > asdf