Last active
September 17, 2015 22:17
-
-
Save nzbart/d1f5caa55f0405cbd17c to your computer and use it in GitHub Desktop.
Creates more optimal .gitignore files. Run from within your repository, and delete any .gitignore files you are not sure about first. You should make sure that all code is committed first.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = 'Stop' | |
$filesToIgnore = git status | ? { $_.StartsWith("`t") } | % { $_.SubString(1) } | ? { !$_.StartsWith("deleted:") } | |
$filesToIgnore | % { | |
$fileName = [IO.Path]::GetFileName($_) | |
$directory = [IO.Path]::GetDirectoryName($_) | |
if($fileName.length -eq 0) { | |
#The path is actually a directory | |
$fileName = [IO.Path]::GetFileName($directory) + "/" | |
$directory = [IO.Path]::GetDirectoryName($directory) | |
} | |
$ignore="/$fileName" | |
$ignoreFile = "$directory\.gitignore" | |
if($ignoreFile -eq '\.gitignore') { | |
$ignoreFile = '.gitignore' | |
} | |
New-Object psobject -Property ([ordered]@{ Original=$_; IgnoreFile=$ignoreFile; Ignore=$ignore }) | |
Add-Content -Value "$ignore" -Path $ignoreFile | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment