-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-status.ps1
65 lines (50 loc) · 1.67 KB
/
update-status.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
<#
.SYNOPSIS
This script looks for modified files in local repositories
.DESCRIPTION
The script searches for directories with a ".git" directory and makes a git "status".
.EXAMPLE
./update-status.ps1 myfolder
./update-status.ps1 -Folder myfolder
.PARAMETERS
-Folder
.NOTES
Git must be in the current PATH.
.LINK
#>
param (
[string]$folder = "."
)
Function check-git {
[Array] $gitdirs = (Get-ChildItem -Path $repodir -Name .git -Recurse -Directory -Attributes Hidden, !Hidden)
foreach($dir in $gitdirs){
# Add .git to the path and convert to absolute
$cdir = (Convert-Path (Split-Path (${repodir} + "\" + ${dir})))
#If it is a WSL directory, lxss, dont update since bad things happens.
if ($cdir -match "AppData\\local\\lxss" -or $cdir -match "\\Appdata\\local\\Packages" ) {
Write-Host "Will not check git in $cdir`n" -ForegroundColor red
}
else {
$gitstatus=(git -C ${cdir} status --porcelain)
# Check if there were any modified files
if ($gitstatus|where {$_ -match '^\?\?|^A|^M|^R'}) {
Write-Host "`nRepo " -Foregroundcolor Green -NoNewLine
Write-Host "${cdir} " -Foregroundcolor Cyan -NoNewLine
Write-Host "modified:" -Foregroundcolor Green
# Print the modified files
foreach($file in $gitstatus){
Write-Host "${file}" -Foregroundcolor Yellow
}
}
}
}
}
# Main
if (Test-Path -Path $folder -PathType Container){
$repodir = $folder
check-git
}
else {
"$folder is not a valid directory. Exiting."
break
}