Public/Initialize-GitWorkflowAutomation.ps1

function Initialize-GitWorkflowAutomation {
    <#
    .SYNOPSIS
    Initializes Git workflow automation including hooks, commit templates, and workflow rules.
     
    .DESCRIPTION
    Sets up comprehensive Git workflow automation including pre-commit hooks, commit message
    templates, branch protection rules, and development workflow standardization.
     
    .PARAMETER Repository
    Path to Git repository. Defaults to current directory.
     
    .PARAMETER HookTypes
    Types of Git hooks to install. Default: @('pre-commit', 'commit-msg', 'pre-push')
     
    .PARAMETER TeamConfiguration
    Path or URL to team Git configuration file.
     
    .PARAMETER ShowProgress
    Display detailed progress information.
     
    .EXAMPLE
    Initialize-GitWorkflowAutomation
     
    .EXAMPLE
    Initialize-GitWorkflowAutomation -Repository "C:\Projects\MyApp" -ShowProgress
     
    .OUTPUTS
    PSCustomObject with setup results
    #>

    
    [CmdletBinding()]
    param(
        [Parameter(HelpMessage = "Git repository path")]
        [string]$Repository = (Get-Location).Path,
        
        [Parameter(HelpMessage = "Git hook types to install")]
        [string[]]$HookTypes = @('pre-commit', 'commit-msg', 'pre-push'),
        
        [Parameter(HelpMessage = "Team configuration")]
        [object]$Configuration,
        
        [Parameter(HelpMessage = "Show progress")]
        [switch]$ShowProgress
    )
    
    $result = [PSCustomObject]@{
        Repository = $Repository
        HooksInstalled = @()
        ConfigurationsApplied = @()
        Success = $true
        Error = $null
    }
    
    try {
        if ($ShowProgress) { Write-Host " Initializing Git workflow automation..." -ForegroundColor Cyan }
        
        # Validate Git repository
        if (-not (Test-Path "$Repository\.git")) {
            throw "Not a Git repository: $Repository"
        }
        
        # Install Git hooks
        foreach ($hookType in $HookTypes) {
            if ($ShowProgress) { Write-Host " Installing $hookType hook..." -ForegroundColor White }
            
            $hookResult = Install-GitHook -Repository $Repository -HookType $hookType -Configuration $Configuration
            if ($hookResult.Success) {
                $result.HooksInstalled += $hookType
                if ($ShowProgress) { Write-Host " ✓ $hookType hook installed" -ForegroundColor Green }
            }
        }
        
        # Apply Git configurations
        $gitConfigs = @(
            @{ Name = 'core.autocrlf'; Value = 'true'; Scope = 'local' },
            @{ Name = 'pull.rebase'; Value = 'false'; Scope = 'local' },
            @{ Name = 'init.defaultBranch'; Value = 'main'; Scope = 'global' }
        )
        
        foreach ($config in $gitConfigs) {
            if ($ShowProgress) { Write-Host " Applying Git config: $($config.Name)" -ForegroundColor White }
            
            $configResult = Set-GitConfiguration -Name $config.Name -Value $config.Value -Scope $config.Scope -Repository $Repository
            if ($configResult.Success) {
                $result.ConfigurationsApplied += $config.Name
            }
        }
        
        if ($ShowProgress) { Write-Host " ✓ Git workflow automation complete" -ForegroundColor Green }
    }
    catch {
        $result.Success = $false
        $result.Error = $_.Exception.Message
        if ($ShowProgress) { Write-Host " ✗ Git workflow setup failed: $($_.Exception.Message)" -ForegroundColor Red }
    }
    
    return $result
}