Created
June 24, 2015 13:22
-
-
Save tkirill/115de9d0a5d7d4d096a3 to your computer and use it in GitHub Desktop.
Test `git fetch --prune`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For http://stackoverflow.com/q/31026942/458723 | |
function Clean-TestRepos { | |
if (Test-Path test-repo) { | |
rm -Force -Recurse test-repo | |
} | |
if (Test-Path test-clone) { | |
rm -Force -Recurse test-clone | |
} | |
} | |
function Create-RepositoryWithMultipleBranches | |
{ | |
git init test-repo | |
cd test-repo | |
echo 1 > file | |
git add --all | |
git commit -m 'commit1' | |
git checkout -b branch1 | |
echo 2 > file | |
git commit -am 'commit2' | |
git checkout master | |
git checkout -b branch2 | |
echo 3 > file | |
git commit -am 'commit3' | |
git checkout master | |
cd .. | |
} | |
function Clone-AndCheckoutAllBranches | |
{ | |
git clone test-repo test-clone | |
cd test-clone | |
git checkout branch1 | |
git checkout branch2 | |
git checkout master | |
cd .. | |
} | |
function Remove-RemoteBranchWithPush | |
{ | |
Create-RepositoryWithMultipleBranches | |
Clone-AndCheckoutAllBranches | |
cd test-clone | |
echo "Branches before delete" | |
git branch -v --remote | |
git push origin --delete branch1 | |
git push origin --delete branch2 | |
echo "Branches before prune" | |
git branch -v --remote | |
git fetch -p | |
echo "Branches after prune" | |
git branch -v --remote | |
cd .. | |
} | |
function Remove-RemoteBranchOnRemote | |
{ | |
Create-RepositoryWithMultipleBranches | |
Clone-AndCheckoutAllBranches | |
cd test-repo | |
git branch -D branch1 | |
git branch -D branch2 | |
cd ..\test-clone | |
echo "Branches before prune" | |
git branch -v --remote | |
git fetch -p | |
echo "Branches after prune" | |
git branch -v --remote | |
cd .. | |
} | |
function Run-Main | |
{ | |
Write-Host "Remove remote branches with push" | |
Clean-TestRepos | |
Remove-RemoteBranchWithPush | |
Write-Host | |
Write-Host "Remove remote branches with push" | |
Clean-TestRepos | |
Remove-RemoteBranchOnRemote | |
} | |
Run-Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment