Skip to content

Commit

Permalink
Make cd() overwrite cwd when given an absolute path.
Browse files Browse the repository at this point in the history
Fixes fabric#166.
  • Loading branch information
bitprophet committed May 28, 2010
1 parent 2b714ea commit 5702362
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/changes/0.9.1.rst
Expand Up @@ -25,6 +25,9 @@ Bugfixes
* :issue:`132`: `~fabric.operations.local` now calls ``strip`` on its stdout,
matching the behavior of `~fabric.operations.run`/`~fabric.operations.sudo`.
Thanks to Carl Meyer again on this one.
* :issue:`166`: `~fabric.context_managers.cd` now correctly overwrites
``env.cwd`` when given an absolute path, instead of naively appending its
argument to ``env.cwd``'s previous value.


Documentation updates
Expand Down
2 changes: 1 addition & 1 deletion fabric/context_managers.py
Expand Up @@ -181,7 +181,7 @@ def cd(path):
the *behavior* of `cd` will have any guarantee of backwards
compatibility.
"""
if env.get('cwd'):
if env.get('cwd') and not path.startswith('/'):
new_cwd = env.cwd + '/' + path
else:
new_cwd = path
Expand Down
14 changes: 14 additions & 0 deletions tests/test_context_managers.py
Expand Up @@ -24,3 +24,17 @@ class TestException(Exception):
finally:
with cd('else'):
eq_(env.cwd, 'else')


def test_cwd_with_absolute_paths():
"""
cd() should append arg if non-absolute or overwrite otherwise
"""
existing = '/some/existing/path'
additional = 'another'
absolute = '/absolute/path'
env.cwd = existing
with cd(absolute):
eq_(env.cwd, absolute)
with cd(additional):
eq_(env.cwd, existing + '/' + additional)

0 comments on commit 5702362

Please sign in to comment.