Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify/fix join-path. #325

Merged
merged 1 commit into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${relativeFile}: the current opened file relative to workspaceRoot
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",

// Start PowerShell
"windows": {
"command": "${env.windir}\\sysnative\\windowspowershell\\v1.0\\PowerShell.exe"
},
"linux": {
"command": "/usr/bin/powershell"
},
"osx": {
"command": "/usr/local/bin/powershell"
},

// The command is a shell script
"isShellCommand": true,

// Show the output window always
"showOutput": "always",

"args": [
"-NoProfile", "-ExecutionPolicy", "Bypass"
],

// Associate with test task runner
"tasks": [
{
"taskName": "Test",
"suppressTaskName": true,
"isTestCommand": true,
"showOutput": "always",
"args": [
"Write-Host 'Invoking Pester'; Invoke-Pester test -PesterOption @{IncludeVSCodeMarker=$true};",
"Invoke-Command { Write-Host 'Completed Test task in task runner.' }"
],
"problemMatcher": [
{
"owner": "powershell",
"fileLocation": ["absolute"],
"severity": "error",
"pattern": [
{
"regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$",
"message": 1
},
{
"regexp": "^\\s+at\\s+[^,]+,\\s*(.*?):\\s+line\\s+(\\d+)$",
"file": 1,
"line": 2
}
]
}
]
}
]
}
7 changes: 3 additions & 4 deletions GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,9 @@ function Start-SshAgent([switch]$Quiet) {
Add-SshKey
}

function Get-SshPath($File = 'id_rsa')
{
$home = Resolve-Path (Invoke-NullCoalescing $Env:HOME ~)
Resolve-Path (Join-Path $home ".ssh\$File") -ErrorAction SilentlyContinue 2> $null
function Get-SshPath($File = 'id_rsa') {
# Avoid paths with path separator char since it is different on Linux/macOS.
Join-Path $Home (Join-Path .ssh $File)
}

<#
Expand Down
1 change: 1 addition & 0 deletions test/Shared.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Import-Module $PSScriptRoot\..\posh-git.psd1
12 changes: 12 additions & 0 deletions test/Ssh.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
. $PSScriptRoot\Shared.ps1

Describe 'SSH Function Tests' {
Context 'Get-SshPath Tests' {
It 'Returns the correct default path' {
Get-SshPath | Should BeExactly $Home\.ssh\id_rsa
}
It 'Returns the correct path given a filename' {
Get-SshPath mykey | Should BeExactly $Home\.ssh\mykey
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that these path expectations will likely fail on not-Windows.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't but I will test it. PowerShell itself handles both \ and / as path sep chars. Issues arise though when a path is passed down to a native application.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so PowerShell internally handles both just fine but when you "compare exactly", the expected has to be correct. Submitting a PR to fix this.

}
}
}