Last active
May 6, 2020 05:55
-
-
Save doitian/1903b5960f03e4d615aa2171e0fb7bf6 to your computer and use it in GitHub Desktop.
[Git Hooks to Convert Symbol Links in Windows] #git #windows
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
$links = git ls-files -s | sls '^120000' | % { | |
($_.Line -Split '\s')[-1] | |
} | Resolve-Path | ? { | |
Test-Path -Path $_ -PathType Leaf | |
} | |
foreach ($link in $links) { | |
$target = Join-Path (Split-Path -Parent $link) (Get-Content $link) | |
rm $link | |
New-Item -Path $link -ItemType Junction -Value $target | |
$ignore = ((Resolve-Path -Relative $link) -Replace '\\','/').Substring(1) | |
if ((Get-Content .git\info\exclude) -ne $ignore) { | |
Add-Content -Path .git\info\exclude $ignore | |
} | |
git update-index --assume-unchanged $link | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment