ToggleGitTracking.ps1 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. param (
  2. [Parameter(Position=0, Mandatory=$false)]
  3. [ValidateSet("t", "u")]
  4. [string]$option
  5. )
  6. # Define the directory to apply changes to
  7. $targetDir = "components\wifi-manager\webapp\dist"
  8. # Get the current directory
  9. $currentDir = Get-Location
  10. # Get list of files from the file system
  11. $fsFiles = Get-ChildItem -Recurse $targetDir -File | ForEach-Object {
  12. $_.FullName.Substring($currentDir.Path.Length + 1).Replace("\", "/")
  13. }
  14. # Get list of files from the Git index
  15. $indexFiles = git ls-files -s $targetDir | ForEach-Object {
  16. ($_ -split "\s+")[3]
  17. }
  18. # Combine and remove duplicates
  19. $allFiles = $fsFiles + $indexFiles | Sort-Object -Unique
  20. # Apply the git command based on the option
  21. $allFiles | ForEach-Object {
  22. $relativePath = $_
  23. $isInIndex = $indexFiles -contains $relativePath
  24. if ($null -eq $option) {
  25. $status = if ($isInIndex) { 'tracked' } else { 'not tracked' }
  26. Write-Host "$relativePath is $status"
  27. }
  28. elseif ($isInIndex) {
  29. if ($option -eq "t") {
  30. git update-index --no-skip-worktree $relativePath
  31. Write-Host "Started tracking changes in $relativePath"
  32. }
  33. elseif ($option -eq "u") {
  34. git update-index --skip-worktree $relativePath
  35. Write-Host "Stopped tracking changes in $relativePath"
  36. }
  37. }
  38. else {
  39. Write-Host "File $relativePath is not tracked."
  40. }
  41. }