AppHandling/Add-GitToAlProjectFolder.ps1

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
<#
 .Synopsis
  Adds GIT to an Al Project Folder
 .Description
  This function will create a .gitignore file, initialize a git repo, add and commit all files in the folder
  The GIT repo will NOT have any remote defined
 .Parameter alProjectFolder
  Path of the folder in which to add a GIT repo
 .Parameter commitMessage
  Message of initial commit to the repo
 .Example
  Add-GitToAlProjectFolder
#>

function Add-GitToAlProjectFolder {
    Param(
        [Parameter(Mandatory=$true)]
        [string] $alProjectFolder,
        [Parameter(Mandatory=$true)]
        [string] $commitMessage
    )

    Write-Host "Initializing Git repository"

    $gitIgnoreFile = Join-Path $AlProjectFolder ".gitignore"
    Set-Content -Path $gitIgnoreFile -Value ".vscode`r`n*.app"

    $oldLocation = Get-Location
    Set-Location $AlProjectFolder
    & git init
    Write-Host "Adding files"
    & git add .
    & git gc --quiet
    Write-Host "Committing files"
    & git commit -m $commitMessage --quiet
    Set-Location $oldLocation
}
Export-ModuleMember -Function Add-GitToAlProjectFolder