ui: fix crash by non-interactive prompt echo for user name stable
authorYuya Nishihara <yuya@tcha.org>
Sat, 06 Feb 2016 20:43:20 +0900
branchstable
changeset 28039 89003c49315c
parent 28038 72f2a19c5f88
child 28040 6db47740e681
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.
mercurial/ui.py
tests/test-committer.t
--- 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'))
--- 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 <<EOF
+  > [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 <<EOF
+  > Asked User <ask@example.com>
+  > EOF
+  enter a commit username: Asked User <ask@example.com>
+  $ hg tip
+  changeset:   5:84c91d963b70
+  tag:         tip
+  user:        Asked User <ask@example.com>
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     ask
+  
+
 # test no .hg/hgrc (uses generated non-interactive username)
 
   $ echo space > asdf