Skip to content

Instantly share code, notes, and snippets.

@fcharlie
Last active August 27, 2017 01:58
Show Gist options
  • Save fcharlie/e2016b4dc56dcef3b2f042ba23cede4f to your computer and use it in GitHub Desktop.
Save fcharlie/e2016b4dc56dcef3b2f042ba23cede4f to your computer and use it in GitHub Desktop.
Track Repository
<#
#>
param(
[Switch]$Stash,
[Switch]$Restore
)
Function Restore-Repositories{
param(
[Parameter(Position=0,Mandatory=$True,HelpMessage="Restore git repository")]
[ValidateNotNullorEmpty()]
[String]$URL
)
git clone $URL --depth=1
}
Function Remove-RepositoriesStash{
param(
[Parameter(Position=0,Mandatory=$True,HelpMessage="Stash git repository")]
[ValidateNotNullorEmpty()]
[String]$Folder
)
if(Test-Path $Folder\.git){
Push-Location $PWD
Set-Location $Folder
$url=git remote get-url origin
$url|Out-File $PSScriptRoot\repositories.txt -Append
Write-Host "Track URL: $url"
Pop-Location
Remove-Item -Force -Recurse -Path $Folder
}
}
$env:PATH=$env:PATH+";"+"C:\Program Files\Git\bin"
if($Stash){
$folderlist=Get-ChildItem $PSScriptRoot -Directory # |ForEach-Object {$_.FullName}
foreach($f in $folderlist){
Remove-RepositoriesStash -Folder $f
}
}elseif($Restore){
$list=Get-Content "$PSScriptRoot\repositories.txt"
foreach($i in $list){
Restore-Repositories -URL $i
}
}else{
Write-Host "Error Argument Input"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment