diff --git a/src/FileSystem.format.ps1xml b/src/FileSystem.format.ps1xml new file mode 100644 index 0000000..1303279 --- /dev/null +++ b/src/FileSystem.format.ps1xml @@ -0,0 +1,284 @@ + + + + GitFileSystemTypes + + System.IO.DirectoryInfo#git + System.IO.FileInfo#git + + + + + + + + GitFileSystemTypes-GroupingFormat + + + + + + 4 + + + + + $_.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "") + + + + + + + + + + + + + + + + + children + + GitFileSystemTypes + + + PSParentPath + GitFileSystemTypes-GroupingFormat + + + + + + 7 + left + + + + 25 + right + + + + 14 + right + + + + 8 + left + + + + 6 + left + + + + + + + + + Mode + + + + [String]::Format("{0,10} {1,8}", $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t")) + + + + Length + + + Change + + + Staged + + + Name + + + + + + + + children + + GitFileSystemTypes + + + PSParentPath + GitFileSystemTypes-GroupingFormat + + + + + + System.IO.FileInfo#git + + + + Name + + + Length + + + CreationTime + + + LastWriteTime + + + LastAccessTime + + + Mode + + + LinkType + + + Target + + + VersionInfo + + + + + + + Name + + + CreationTime + + + LastWriteTime + + + LastAccessTime + + + Mode + + + LinkType + + + Target + + + + + + + + children + + GitFileSystemTypes + + + PSParentPath + GitFileSystemTypes-GroupingFormat + + + + + + Name + + + + + System.IO.DirectoryInfo#git + + + Name + [{0}] + + + + + + + FileSecurityTable + + System.Security.AccessControl.FileSystemSecurity + + + PSParentPath + GitFileSystemTypes-GroupingFormat + + + + + + + + + + + + + + + + + split-path $_.Path -leaf + + + + Owner + + + + $_.AccessToString + + + + + + + + + FileSystemStream + + Microsoft.PowerShell.Commands.AlternateStreamData + + + Filename + + + + + 20 + left + + + 10 + right + + + + + + + Stream + + + Length + + + + + + + + \ No newline at end of file diff --git a/src/GetChildItemProxy.ps1 b/src/GetChildItemProxy.ps1 new file mode 100644 index 0000000..f3c3f73 --- /dev/null +++ b/src/GetChildItemProxy.ps1 @@ -0,0 +1,106 @@ +Function Get-Childitem +{ + [CmdletBinding(DefaultParameterSetName='Items', SupportsTransactions=$true, HelpUri='http://go.microsoft.com/fwlink/?LinkID=113308')] + param( + [Parameter(ParameterSetName='Items', Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [string[]] + ${Path}=$pwd.Path, + + [Parameter(ParameterSetName='LiteralItems', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('PSPath')] + [string[]] + ${LiteralPath}, + + [Parameter(Position=1)] + [string] + ${Filter}, + + [string[]] + ${Include}, + + [string[]] + ${Exclude}, + + [Alias('s')] + [switch] + ${Recurse}, + + [uint32] + ${Depth}, + + [switch] + ${Force}, + + [switch] + ${Name}) + + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Management\Get-ChildItem', [System.Management.Automation.CommandTypes]::Cmdlet) + write-debug "Path is: $path" + if(![string]::IsNullOrEmpty($path) -and (Get-Command Get-GitRootFolder -ErrorAction SilentlyContinue) -and ($path | %{Get-GitRootFolder $_})) + { + $scriptCmd = { + & $wrappedCmd @PSBoundParameters | % -Begin { + $roots = $path | %{Get-GitRootFolder $_} | get-unique + $changes = foreach($root in $roots){Get-GitChange -root $root -ShowIgnored | select @{n='Path';e={join-path $root ($_.path -replace '\\\\$','\*')}},staged,change } + } -Process { + + $fsItem = $_ + $info = if($fsItem.PSIsContainer) + { + $changes|? {$fsItem.fullname -eq $_.path.TrimEnd('\','*') -or $fsItem.fullname -like $_.path }|select change, staged + } + else + { + $changes|? {$fsItem.fullname -like $_.path}|select change, staged + } + + + + $fsItem | Add-Member -Name Change -value $info.change -MemberType NoteProperty + $fsItem | Add-Member -name Staged -Value $info.staged -MemberType NoteProperty + $null=$fsItem.pstypenames.insert(0,"$($fsItem.gettype().fullname)#git") + $fsItem + } + } + } + else + { + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin) + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } + } + + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } + } + + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } +} + +Update-FormatData $PSScriptRoot\filesystem.format.ps1xml + diff --git a/src/PSGit.psd1 b/src/PSGit.psd1 index 3cd3021..f1a6dbb 100644 --- a/src/PSGit.psd1 +++ b/src/PSGit.psd1 @@ -46,7 +46,7 @@ Description = 'A PowerShell implementation of Git, providing a new command-line RequiredAssemblies = 'lib\LibGit2Sharp.dll' # Script files (.ps1) that are run in the caller's environment prior to importing this module. -# ScriptsToProcess = @() +ScriptsToProcess = @('GetChildItemProxy.ps1') # Type files (.ps1xml) to be loaded when importing this module # TypesToProcess = @() diff --git a/src/PSGit.psm1 b/src/PSGit.psm1 index f9e2287..c4e38c3 100644 --- a/src/PSGit.psm1 +++ b/src/PSGit.psm1 @@ -312,4 +312,4 @@ function New-Repository $rtn = [LibGit2Sharp.Repository]::Init($Path) } finally {} } -} \ No newline at end of file +} diff --git a/test/Gci.Steps.ps1 b/test/Gci.Steps.ps1 new file mode 100644 index 0000000..cd0acf3 --- /dev/null +++ b/test/Gci.Steps.ps1 @@ -0,0 +1,36 @@ +BeforeScenario { + $script:repo = Convert-Path TestDrive:\ + Push-Location TestDrive:\ + [Environment]::CurrentDirectory = $repo + Remove-Item TestDrive:\* -Recurse -Force +} + +AfterScenario { + Pop-Location + [Environment]::CurrentDirectory = Convert-Path $Pwd +} + +When 'Get-ChildItem is called' { + $script:result = Get-ChildItem +} + +When 'Get-ChildItem -outbuffer 5 is called' { + $script:result = Get-ChildItem -outbuffer 5 +} + +Then 'the resulting object should not have a Changed property' { + + if($script:result | get-member -membertype noteproperty | ? name -eq Change) { + throw "Found Property, showing Git status when we are not in a repo" + } +} + +Then 'the resulting object should have a Changed property' { + + if($script:result | get-member -membertype noteproperty | ? name -eq Change) { + + } + else { + throw "Property not found!" + } +} \ No newline at end of file diff --git a/test/Gci.feature b/test/Gci.feature new file mode 100644 index 0000000..fbeaf9d --- /dev/null +++ b/test/Gci.feature @@ -0,0 +1,25 @@ +Feature: Get-ChildItem proxy function + This will test the functionality of the gci proxy to make sure the output is correctly modified + + Scenario: GCI not in a repo + Given we are NOT in a repository with + | FileAction | Name | + | Created | FileOne.ps1 | + When Get-ChildItem is called + Then the resulting object should not have a Changed property + + Scenario: GCI in a repo + Given we have initialized a repository with + | FileAction | Name | + | Created | FileOne.ps1 | + | Added | FileOne.ps1 | + | Created | FileTwo.ps1 | + When Get-ChildItem is called + Then the resulting object should have a Changed property + + Scenario: GCI test to cover the buffer code, which is in the proxy template + Given we are NOT in a repository with + | FileAction | Name | + | Created | FileOne.ps1 | + When Get-ChildItem -outbuffer 5 is called + Then the resulting object should not have a Changed property diff --git a/test/Status.Steps.ps1 b/test/Status.Steps.ps1 index 6d9b6c7..6f39647 100644 --- a/test/Status.Steps.ps1 +++ b/test/Status.Steps.ps1 @@ -21,9 +21,28 @@ Given "we have a command ([\w-]+)" { $script:command = Get-Command $command -Module PSGit } -Given "we are NOT in a repository" { +Given "we are NOT in a repository(?: with)?" { + param($table) # Remove-Item TestDrive:\* -Recurse -Force - if(gci){ throw "There Are Things Here!" } + if(Test-Path .git){ throw "There is a GIT repo Here!" } + if($table) { + foreach($change in $table) { + switch($change.FileAction) { + "Created" { + Set-Content $change.Name (Get-Date) + } + "Modified" { + Add-Content $change.Name (Get-Date) + } + "Removed" { + Remove-Item $change.Name + } + "Renamed" { + Rename-Item $change.Name $change.Value + } + } + } + } } Given "we are in an empty folder" { if(gci){ throw "There Are Things Here!" }