forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymlinks-to-hardlinks.ps1
More file actions
31 lines (25 loc) · 928 Bytes
/
symlinks-to-hardlinks.ps1
File metadata and controls
31 lines (25 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env powershell
Set-Location -Path $(Split-Path -Parent $PSScriptRoot)
git ls-files -s | Select-String '^120000' | ConvertFrom-String -PropertyNames Get-Content,Hash,_,Path | ForEach-Object {
$symlink = $_.Path
git checkout --quiet -- $symlink
if (Test-Path $symlink -PathType Leaf) {
$parent = (Get-Item $symlink).Directory
} else {
$parent = (Get-Item $symlink).Parent
}
$child = (Get-Content $symlink)
$src = (Join-Path -Path $parent -ChildPath $child)
if (Test-Path $src -PathType Leaf) {
Remove-Item $symlink
New-Item -ItemType HardLink -Name $symlink -Value $src
} elseif (Test-Path $src -PathType Container) {
Remove-Item $symlink
New-Item -ItemType Junction -Name $symlink -Value $src
} else {
Write-Error 'error: git-rm-symlink: Not a valid source\n'
Write-Error '$symlink =/=> $src...'
return
}
git update-index --assume-unchanged $symlink
}