Merge pull request #1534 from PowerShell/vors/cd

Make 'cd' go to the HOME directory
This commit is contained in:
Sergei Vorobev 2016-07-27 19:07:38 -07:00 committed by GitHub
commit fa78a55c37
3 changed files with 41 additions and 20 deletions

View file

@ -996,6 +996,12 @@ namespace Microsoft.PowerShell.Commands
try
{
// Change the current working directory
if (string.IsNullOrEmpty(Path))
{
// If user just typed 'cd', go to FileSystem provider home directory
Path = SessionState.Internal.GetSingleProvider(Commands.FileSystemProvider.ProviderName).Home;
}
result = SessionState.Path.SetLocation(Path, CmdletProviderContext);
}
catch (PSNotSupportedException notSupported)

View file

@ -63,5 +63,20 @@ Describe "Set-Location" -Tags "CI" {
$(Set-Location $target -PassThru).GetType().Name | Should Be PathInfo
}
Context 'cd with no arguments' {
It 'Should go to $env:HOME when cd run with no arguments from FileSystem provider' {
Set-Location 'TestDrive:\'
cd
(Get-Location).Path | Should Be (Get-PSProvider FileSystem).Home
}
It 'Should go to $env:HOME when cd run with no arguments from Env: provider' {
Set-Location 'Env:'
cd
(Get-Location).Path | Should Be (Get-PSProvider FileSystem).Home
}
}
Set-Location $startDirectory
}

View file

@ -1,7 +1,7 @@
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
Describe "SemanticVersion api tests" {
Describe "SemanticVersion api tests" -Tags 'CI' {
Context "constructing valid versions" {
It "string argument constructor" {
$v = [SemanticVersion]::new("1.2.3-alpha")