Module/Include/GitHelpter.ps1

function PullGitRepository {
    [CmdletBinding(SupportsShouldProcess = $true)]
    Param(
        [Parameter(Mandatory = $false)]
        [String] $BaseURI = 'https://dev.azure.com/',
        [Parameter(Mandatory = $false)]
        [String] $Organisation = 'BrightComSolutions',        
        [Parameter(Mandatory = $false)]
        [String] $Project = 'BrightCom%20Solutions',
        [Parameter(Mandatory = $false)]
        [String] $Repository = 'BCS%20AL%20Project%20Template',
        [Parameter(Mandatory = $false)]
        [String] $Branch = 'main'
    )
    try {
        $OriginalFolder = Get-Location;
        
        $RepositoryURI = ('{0}/{1}/{2}/_git/{3}' -f $BaseURI, $Organisation, $Project, $Repository)
        $Workfolder = ('{0}\{1}\{2}' -f $env:TEMP, $Project, $Repository);
        
        if (Test-Path -Path $Workfolder) {
            Remove-Item -Path $Workfolder -Recurse -Force;
        }
        
        $RepositoryCloneFolder = ('{0}\{1}' -f $Workfolder, '.Repo');
        git clone $RepositoryURI $RepositoryCloneFolder;
        Set-Location $RepositoryCloneFolder 
        
        git checkout "remotes/origin/$Branch";
        
        Set-Location $OriginalFolder

        return $RepositoryCloneFolder
    }
    catch {
        throw "An error occured: $_.Exception";
    }
}