Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch '1.8'

Conflicts:
	sites/www/changelog.rst
  • Loading branch information...
commit 198780e85c9813be8317990eebcf36a24486dd51 2 parents 2bc47fd + da2eae7
@bitprophet bitprophet authored
View
2  fabric/context_managers.py
@@ -329,7 +329,7 @@ def lcd(path):
def _change_cwd(which, path):
path = path.replace(' ', '\ ')
- if state.env.get(which) and not path.startswith('/'):
+ if state.env.get(which) and not path.startswith('/') and not path.startswith('~'):
new_cwd = state.env.get(which) + '/' + path
else:
new_cwd = path
View
3  sites/www/changelog.rst
@@ -2,6 +2,9 @@
Changelog
=========
+* :bug:`898` Treat paths that begin with tilde "~" as absolute paths instead of
+ relative. Thanks to Alex Plugaru for the patch and Dan Craig for the
+ suggestion.
* :feature:`1078` Add ``.command`` and ``.real_command`` attributes to
``local`` return value. Thanks to Alexander Teves (``@alexanderteves``) and
Konrad Hałas (``@konradhalas``).
View
54 tests/test_context_managers.py
@@ -2,6 +2,7 @@
import os
import sys
+from StringIO import StringIO
from nose.tools import eq_, ok_
@@ -9,10 +10,8 @@
from fabric.context_managers import (cd, settings, lcd, hide, shell_env, quiet,
warn_only, prefix, path)
from fabric.operations import run, local
-
from utils import mock_streams, FabricTest
from server import server
-from StringIO import StringIO
#
@@ -23,8 +22,10 @@ def test_error_handling():
"""
cd cleans up after itself even in case of an exception
"""
+
class TestException(Exception):
pass
+
try:
with cd('somewhere'):
raise TestException('Houston, we have a problem.')
@@ -49,6 +50,52 @@ def test_cwd_with_absolute_paths():
eq_(env.cwd, existing + '/' + additional)
+def test_cd_home_dir():
+ """
+ cd() should work with home directories
+ """
+ homepath = "~/somepath"
+ with cd(homepath):
+ eq_(env.cwd, homepath)
+
+
+def test_cd_nested_home_abs_dirs():
+ """
+ cd() should work with nested user homedir (starting with ~) paths.
+
+ It should always take the last path if the new path begins with `/` or `~`
+ """
+
+ home_path = "~/somepath"
+ abs_path = "/some/random/path"
+ relative_path = "some/random/path"
+
+ # 2 nested homedir paths
+ with cd(home_path):
+ eq_(env.cwd, home_path)
+ another_path = home_path + "/another/path"
+ with cd(another_path):
+ eq_(env.cwd, another_path)
+
+ # first absolute path, then a homedir path
+ with cd(abs_path):
+ eq_(env.cwd, abs_path)
+ with cd(home_path):
+ eq_(env.cwd, home_path)
+
+ # first relative path, then a homedir path
+ with cd(relative_path):
+ eq_(env.cwd, relative_path)
+ with cd(home_path):
+ eq_(env.cwd, home_path)
+
+ # first home path, then a a relative path
+ with cd(home_path):
+ eq_(env.cwd, home_path)
+ with cd(relative_path):
+ eq_(env.cwd, home_path + "/" + relative_path)
+
+
#
# prefix
#
@@ -107,6 +154,7 @@ def test_settings():
eq_(env.testval, "inner value")
eq_(env.testval, "outer value")
+
def test_settings_with_multiple_kwargs():
"""
settings() should temporarily override env dict with given key/value pairS
@@ -119,6 +167,7 @@ def test_settings_with_multiple_kwargs():
eq_(env.testval1, "outer 1")
eq_(env.testval2, "outer 2")
+
def test_settings_with_other_context_managers():
"""
settings() should take other context managers, and use them with other overrided
@@ -168,6 +217,7 @@ def test_shell_env():
eq_(env.shell_env, {})
+
class TestQuietAndWarnOnly(FabricTest):
@server()
@mock_streams('both')
Please sign in to comment.
Something went wrong with that request. Please try again.