X Tutup
Skip to content

Commit afa6850

Browse files
committed
Convert symlinks to hardlinks on windows
1 parent 986b8b2 commit afa6850

File tree

6 files changed

+29
-0
lines changed

6 files changed

+29
-0
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
architecture: 'x64'
2020

2121
- script: |
22+
powershell.exe scripts/symlinks-to-hardlinks.ps1
2223
"C:\Program Files\Git\mingw64\bin\curl.exe" -sSf -o rustup-init.exe https://win.rustup.rs/
2324
.\rustup-init.exe -y
2425
set PATH=%PATH%;%USERPROFILE%\.cargo\bin
File renamed without changes.

scripts/symlinks-to-hardlinks.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env powershell
2+
git ls-files -s | Select-String '^120000' | ConvertFrom-String -PropertyNames Get-Content,Hash,_,Path | ForEach-Object {
3+
$symlink = $_.Path
4+
5+
git checkout --quiet -- $symlink
6+
if (Test-Path $symlink -PathType Leaf) {
7+
$parent = (Get-Item $symlink).Directory
8+
} else {
9+
$parent = (Get-Item $symlink).Parent
10+
}
11+
$child = (Get-Content $symlink)
12+
13+
$src = (Join-Path -Path $parent -ChildPath $child)
14+
15+
if (Test-Path $src -PathType Leaf) {
16+
Remove-Item $symlink
17+
New-Item -ItemType HardLink -Name $symlink -Value $src
18+
} elseif (Test-Path $src -PathType Container) {
19+
Remove-Item $symlink
20+
New-Item -ItemType Junction -Name $symlink -Value $src
21+
} else {
22+
Write-Error 'error: git-rm-symlink: Not a valid source\n'
23+
Write-Error '$symlink =/=> $src...'
24+
return
25+
}
26+
27+
git update-index --assume-unchanged $symlink
28+
}

0 commit comments

Comments
 (0)
X Tutup