-
Notifications
You must be signed in to change notification settings - Fork 4
/
git-lfs-fix-attributes.ps1
executable file
·69 lines (60 loc) · 2.3 KB
/
git-lfs-fix-attributes.ps1
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
[CmdletBinding()] # Fail on unknown args
param (
[switch]$dryrun = $false,
[switch]$help = $false
)
function Print-Usage {
Write-Output "Git LFS Fix Attributes"
Write-Output " Fix the read-only attributes on LFS files which are lockable"
Write-Output " but which are not currently locked. Unlocked files are"
Write-Output " made read-only on checkout but it's possible to accidentally"
Write-Output " have files left read/write when they aren't locked, which"
Write-Output " will only get fixed the next time this file is checked out."
Write-Output "Usage:"
Write-Output " git-lfs-fix-attributes.ps1 [options]"
Write-Output "Options:"
Write-Output " "
Write-Output " -dryrun : Don't perform actions, just report what would happen"
Write-Output " -verbose : Print more"
Write-Output " -help : Print this help"
}
$ErrorActionPreference = "Stop"
if ($help) {
Print-Usage
Exit 0
}
. $PSScriptRoot\inc\locking.ps1
Write-Output "Checking file attributes..."
$lockableLfsFiles = Get-All-Lockable-Files
Write-Verbose ("Checking attributes on lockable files:`n " + ($lockableLfsFiles -join "`n "))
# Now get active locks
$lockedFiles = Get-Locked-Files
Write-Verbose ("Currently locked files:`n " + ($lockedFiles -join "`n "))
$numFixed = 0
foreach ($filename in $lockableLfsFiles) {
# Skip missing files; may have locked something then deleted it
if (-not (Test-Path $filename -PathType Leaf)) {
Write-Verbose "${filename}: skipping, missing locally"
continue
}
$shouldBeReadOnly = -not ($lockedFiles -contains $filename)
$isReadOnly = Get-ItemProperty -Path $filename | Select-Object -Expand IsReadOnly
if ($isReadOnly -ne $shouldBeReadOnly) {
if ($dryrun) {
Write-Verbose "${filename}: read-only should be $shouldBeReadOnly"
} else {
Write-Output "${filename}: setting read-only=$shouldBeReadOnly"
Set-ItemProperty -Path $filename -Name IsReadOnly -Value $shouldBeReadOnly
}
++$numFixed
}
}
if ($numFixed -gt 0) {
if ($dryrun) {
Write-Output "Would have fixed $numFixed file attributes."
} else {
Write-Output "Fixed $numFixed file attributes."
}
} else {
Write-Output "All file attributes are OK"
}