ProductivityTools.CloneGitRepositories.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function CloneRepository($sshurl)
{
    git clone $sshurl
}

function GetRepositories()
{
    [cmdletbinding()]
    param ([string[]]$repositories)

    foreach($repository in $repositories)
    {
        Write-Verbose $repository
        $name=$repository.substring($repository.LastIndexOf('/')+1,$repository.LastIndexOf('.')-$repository.LastIndexOf('/')-1)
        if ($(Test-Path $name) -eq $true)
        {
            Write-Host "Directory $repoName exists. - Skipping." -ForegroundColor Yellow
        }
        else
        {
            CloneRepository $repository
            Write-Host "Repository $repoName cloned" -ForegroundColor Green
        }
    }

}


function Clone-GitRepositories()
{
    [cmdletbinding()]
    param ([string]$TargetDirectory,[string[]]$Repositories)

    Push-Location

    if ((Test-Path $TargetDirectory) -eq $false)
    {
        New-Item $TargetDirectory -ItemType Directory
    }
    cd $TargetDirectory
    GetRepositories $Repositories

    Pop-Location
}

Export-ModuleMember Clone-GitRepositories