Rev 6159: Address gz's review comments. in file:///home/vila/src/bzr/bugs/856261-unshelve-line-based/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Sep 28 14:49:44 UTC 2011
At file:///home/vila/src/bzr/bugs/856261-unshelve-line-based/
------------------------------------------------------------
revno: 6159
revision-id: v.ladeuil+lp at free.fr-20110928144944-gly88bevm0ivj4ms
parent: v.ladeuil+lp at free.fr-20110927211300-dazildg262nrz9a3
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 856261-unshelve-line-based
timestamp: Wed 2011-09-28 16:49:44 +0200
message:
Address gz's review comments.
-------------- next part --------------
=== modified file 'bzrlib/shelf_ui.py'
--- a/bzrlib/shelf_ui.py 2011-09-27 21:13:00 +0000
+++ b/bzrlib/shelf_ui.py 2011-09-28 14:49:44 +0000
@@ -16,6 +16,7 @@
from cStringIO import StringIO
+import os
import shutil
import sys
import tempfile
@@ -251,13 +252,20 @@
diff_file.seek(0)
return patches.parse_patch(diff_file)
+ def _char_based(self):
+ # FIXME: A bit hackish to use INSIDE_EMACS here, but there is another
+ # work in progress moving this method (and more importantly prompt()
+ # below) into the ui area and address the issue in better ways.
+ # -- vila 2011-09-28
+ return os.environ.get('INSIDE_EMACS', None) is None
+
def prompt(self, message):
"""Prompt the user for a character.
:param message: The message to prompt a user with.
:return: A character.
"""
- char_based = not(os.environ.get('INSIDE_EMACS', None) is not None)
+ char_based = self._char_based()
if char_based and not sys.stdin.isatty():
# Since there is no controlling terminal we will hang when
# trying to prompt the user, better abort now. See
@@ -277,10 +285,8 @@
# XXX: Warn if more than one char is typed ?
char = line[0]
else:
- # In the char based implementation, the default value is
- # selected when the user just hit enter, so we return that here
- # for edge cases.
- char = '\n'
+ # Empty input, callers handle it as enter
+ char = ''
sys.stdout.write("\r" + ' ' * len(message) + '\r')
sys.stdout.flush()
return char
=== modified file 'bzrlib/tests/test_script.py'
--- a/bzrlib/tests/test_script.py 2011-05-16 13:39:39 +0000
+++ b/bzrlib/tests/test_script.py 2011-09-28 14:49:44 +0000
@@ -572,9 +572,9 @@
def test_confirm_action(self):
"""You can write tests that demonstrate user confirmation.
- Specifically, ScriptRunner does't care if the output line for the prompt
- isn't terminated by a newline from the program; it's implicitly terminated
- by the input.
+ Specifically, ScriptRunner does't care if the output line for the
+ prompt isn't terminated by a newline from the program; it's implicitly
+ terminated by the input.
"""
commands.builtin_command_registry.register(cmd_test_confirm)
self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
@@ -589,3 +589,58 @@
ok, no
""")
+class TestShelve(script.TestCaseWithTransportAndScript):
+
+ def setUp(self):
+ super(TestShelve, self).setUp()
+ self.run_script("""
+ $ bzr init test
+ Created a standalone tree (format: 2a)
+ $ cd test
+ $ echo foo > file
+ $ bzr add
+ adding file
+ $ bzr commit -m 'file added'
+ 2>Committing to:...test/
+ 2>added file
+ 2>Committed revision 1.
+ $ echo bar > file
+ """)
+
+ def test_shelve(self):
+ self.overrideEnv('INSIDE_EMACS', '1')
+ self.run_script("""
+ $ bzr shelve -m 'shelve bar'
+ # Shelve? [yNfq?]
+ <y
+ # Shelve 1 change(s)? [yNfq?]
+ <y
+ 2>Selected changes:
+ 2> M file
+ 2>Changes shelved with id "1".
+ """,
+ # shelve uses \r that can't be represented in the
+ # script ?
+ null_output_matches_anything=True)
+ self.run_script("""
+ $ bzr shelve --list
+ 1: shelve bar
+ """)
+
+ def test_dont_shelve(self):
+ self.overrideEnv('INSIDE_EMACS', '1')
+ # We intentionally provide no input here to test EOF
+ self.run_script("""
+ $ bzr shelve -m 'shelve bar'
+ # Shelve? [yNfq?]
+ # Shelve 1 change(s)? [yNfq?]
+ 2>No changes to shelve.
+ """,
+ # shelve uses \r that can't be represented in the
+ # script ?
+ null_output_matches_anything=True)
+ self.run_script("""
+ $ bzr st
+ modified:
+ file
+ """)
More information about the bazaar-commits
mailing list