Guest User

Untitled

a guest
Mar 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. $deletedFiles = @(git ls-files --deleted)
  2. if($deletedFiles.length -ne 0) {
  3. $deletedFiles | % { git rm $_ }
  4. git commit -m "Deleted some files"
  5. }
  6.  
  7. $f = git status --porcelain=v1 -u
  8. if(!$?) { throw "Failed." }
  9.  
  10. $f = $f | % { $_ -replace '^...', '' -replace '^"', '' -replace '"$', '' }
  11. $f = $f | % { ls -Force -LiteralPath $_ } | sort FullName
  12.  
  13. function BuildCommands($batch) {
  14. @($batch) | % {
  15. git add $_
  16. }
  17. git commit -m 'Adding new batch'
  18. git push
  19. if(!$?) {
  20. throw "Failed to push batch."
  21. }
  22. }
  23.  
  24. $maxSize = 500MB
  25. $totalSize = 0
  26. $thisBatch = New-Object System.Collections.ArrayList
  27. $commands = for($i = 0; $i -ne $f.length; ++$i) {
  28. $current = $f[$i]
  29. Write-Host $current.FullName
  30. $currentSize = $current.Length
  31. $sizeIncludingThis = $totalSize + $currentSize
  32. if($sizeIncludingThis -le $maxSize) {
  33. $thisBatch.Add($current) | Out-Null
  34. $totalSize = $sizeIncludingThis
  35. if($i -eq $f.length - 1) {
  36. # this is the final batch of stragglers
  37. BuildCommands $thisBatch
  38. }
  39. } else {
  40. if($thisBatch.Count -ne 0) {
  41. BuildCommands $thisBatch
  42. }
  43. $thisBatch = New-Object System.Collections.ArrayList
  44. $thisBatch.Add($current) | Out-Null
  45. $totalSize = $currentSize
  46. }
  47. }
Add Comment
Please, Sign In to add comment