From 74895c26626c4927576568e721ce3a88eebf4d2d Mon Sep 17 00:00:00 2001 From: Anton Pusch Date: Tue, 11 Oct 2022 04:33:58 +0200 Subject: [PATCH] git: only sync branch on remote and local --- scripts/gitUpdateAll.ps1.bat | 43 ++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/scripts/gitUpdateAll.ps1.bat b/scripts/gitUpdateAll.ps1.bat index 340baa9..74cd040 100644 --- a/scripts/gitUpdateAll.ps1.bat +++ b/scripts/gitUpdateAll.ps1.bat @@ -17,27 +17,42 @@ $repositories | $unchanged = ([DateTime]::Now - $_.LastWriteTime) if ($unchanged.Days -ge 1) { $unchanged = "" + $unchanged.Days + " days" - } else { - $unchanged = $unchanged.ToString().Substring(0,8) } - $repositories += $_ + else { + $unchanged = $unchanged.ToString().Substring(0, 8) + } ([PSCustomObject]@{ - Name = $_.Name; - Unchanged = $unchanged; - Location = $_.Parent.FullName; -})} | Out-String - -# update recently modified repositories first -$repositories = $repositories | sort LastWriteTime -Descending + Name = $_.Name; + Unchanged = $unchanged; + Location = $_.Parent.FullName; + }) +} | Out-String # Update repositories $index = 0 -$repositories | +$repositories | +sort LastWriteTime -Descending | % { + # Print progress information Write-Host @("`n(" + (++$index) + "/" + $repositories.Length + ") Found ") -NoNewline Write-Host $_.Name -ForegroundColor Cyan -NoNewline Write-Host " at " -NoNewline Write-Host $_.Parent.FullName -ForegroundColor Cyan - git -C $_.FullName pull --all - git -C $_.FullName push --all - } \ No newline at end of file + + $path = $_.FullName + $localBranches = git -C $path branch --format='%(refname:short)' + $remoteBranches = git -C $path branch --remotes --format='%(refname:short)' | + % { $_.replace("origin/", "") } + + # Sync branches, that are already on remote + $localBranches | + ? { $remoteBranches.Contains($_) } | + % { + Write-Host "pull " -NoNewline + Write-Host $_" `t" -ForegroundColor Yellow -NoNewline + git -C $path pull origin $_":"$_ + Write-Host "push " -NoNewline + Write-Host $_" `t" -ForegroundColor Yellow -NoNewline + git -C $path push origin $_":"$_ + } +} \ No newline at end of file