|
46 | 46 | .\RepoHerd.ps1 -Verbose -DisablePostCheckoutScripts |
47 | 47 | .\RepoHerd.ps1 -EnableDebug -EnableErrorContext |
48 | 48 | .NOTES |
49 | | - Version: 9.0.0 |
| 49 | + Version: 9.1.0 |
50 | 50 | Last Modified: 2026-03-20 |
51 | 51 |
|
52 | 52 | Requires PowerShell 7.6 LTS or later (installs side-by-side with Windows PowerShell 5.1). |
@@ -94,175 +94,13 @@ param( |
94 | 94 | $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path |
95 | 95 | Import-Module (Join-Path $scriptDir 'RepoHerd.psm1') -Force |
96 | 96 |
|
97 | | -# Initialize module state from script parameters |
98 | | -Initialize-RepoHerd ` |
99 | | - -ScriptPath $scriptDir ` |
100 | | - -DryRun:$DryRun ` |
101 | | - -EnableDebug:$EnableDebug ` |
102 | | - -DisableRecursion:$DisableRecursion ` |
103 | | - -MaxDepth $MaxDepth ` |
104 | | - -ApiCompatibility $ApiCompatibility ` |
105 | | - -DisablePostCheckoutScripts:$DisablePostCheckoutScripts ` |
106 | | - -EnableErrorContext:$EnableErrorContext ` |
107 | | - -OutputFile $OutputFile |
108 | | - |
109 | | -# Main execution |
110 | | -$exitCode = 0 |
111 | | -try { |
112 | | - Write-Log "RepoHerd started - Version 9.0.0" -Level Info |
113 | | - Write-Log "Script path: $scriptDir" -Level Debug |
114 | | - Write-Log "PowerShell version: $($PSVersionTable.PSVersion)" -Level Debug |
115 | | - Write-Log "Operating System: $([System.Environment]::OSVersion.VersionString)" -Level Debug |
116 | | - Write-Log "Default API Compatibility: $ApiCompatibility" -Level Info |
117 | | - |
118 | | - if (-not $DisableRecursion) { |
119 | | - Write-Log "Recursive mode: ENABLED (default) with max depth: $MaxDepth" -Level Info |
120 | | - } else { |
121 | | - Write-Log "Recursive mode: DISABLED" -Level Info |
122 | | - } |
123 | | - |
124 | | - if (-not $DisablePostCheckoutScripts) { |
125 | | - Write-Log "Post-checkout scripts: ENABLED (default)" -Level Info |
126 | | - } else { |
127 | | - Write-Log "Post-checkout scripts: DISABLED" -Level Info |
128 | | - } |
129 | | - |
130 | | - if ($EnableErrorContext) { |
131 | | - Write-Log "Error context: ENABLED - Detailed error information will be shown" -Level Info |
132 | | - } else { |
133 | | - Write-Log "Error context: DISABLED - Use -EnableErrorContext for detailed error information" -Level Debug |
134 | | - } |
135 | | - |
136 | | - if ($OutputFile) { |
137 | | - Write-Log "Structured output will be written to: $OutputFile" -Level Info |
138 | | - } |
139 | | - |
140 | | - # Calculate and log script hash in debug mode |
141 | | - if ($EnableDebug) { |
142 | | - $scriptContent = Get-Content -Path $MyInvocation.MyCommand.Path -Raw |
143 | | - $scriptBytes = [System.Text.Encoding]::UTF8.GetBytes($scriptContent) |
144 | | - $sha256 = [System.Security.Cryptography.SHA256]::Create() |
145 | | - $hashBytes = $sha256.ComputeHash($scriptBytes) |
146 | | - $scriptHash = [System.BitConverter]::ToString($hashBytes).Replace('-', '') |
147 | | - Write-Log "Script SHA256 hash: $($scriptHash.Substring(0, 16))..." -Level Debug |
148 | | - Write-Log "Full script hash: $scriptHash" -Level Debug |
149 | | - } |
150 | | - |
151 | | - if ($DryRun) { |
152 | | - Write-Log "DRY RUN MODE - No actual changes will be made" -Level Warning |
153 | | - } |
154 | | - |
155 | | - if ($EnableDebug) { |
156 | | - Write-Log "Debug logging enabled" -Level Info |
157 | | - } |
158 | | - |
159 | | - # Check Git installation |
160 | | - if (-not (Test-GitInstalled)) { |
161 | | - throw "Git is not installed or not accessible in PATH" |
162 | | - } |
163 | | - |
164 | | - # Determine input file path |
165 | | - if ([string]::IsNullOrEmpty($InputFile)) { |
166 | | - $InputFile = Join-Path $scriptDir "dependencies.json" |
167 | | - Write-Log "Using default input file: $InputFile" -Level Verbose |
168 | | - } |
169 | | - |
170 | | - # Store the dependency file name for recursive processing |
171 | | - # Access module internals for setting the default dependency file name |
172 | | - & (Get-Module RepoHerd) { $script:DefaultDependencyFileName = $args[0] } (Split-Path -Leaf $InputFile) |
173 | | - Write-Log "Default dependency file name for recursive processing: $(Split-Path -Leaf $InputFile)" -Level Debug |
174 | | - |
175 | | - # Determine credentials file path |
176 | | - if ([string]::IsNullOrEmpty($CredentialsFile)) { |
177 | | - $CredentialsFile = Join-Path $scriptDir "git_credentials.json" |
178 | | - Write-Log "Using default credentials file: $CredentialsFile" -Level Verbose |
179 | | - } |
180 | | - |
181 | | - # Read SSH credentials |
182 | | - $sshCreds = Read-CredentialsFile -FilePath $CredentialsFile |
183 | | - & (Get-Module RepoHerd) { $script:SshCredentials = $args[0] } $sshCreds |
184 | | - |
185 | | - # Check if input file exists |
186 | | - if (-not (Test-Path $InputFile)) { |
187 | | - throw "Input file not found: $InputFile" |
188 | | - } |
189 | | - |
190 | | - # Process the initial dependency file with enhanced error handling |
191 | | - Write-Log "Starting dependency processing at depth 0" -Level Info |
192 | | - |
193 | | - $checkedOutRepos = Invoke-WithErrorContext -Context "Processing root dependency file" -ScriptBlock { |
194 | | - Invoke-DependencyFile -DependencyFilePath $InputFile -Depth 0 |
195 | | - } |
196 | | - |
197 | | - # Handle null return |
198 | | - if ($null -eq $checkedOutRepos) { |
199 | | - Write-Log "WARNING: Invoke-DependencyFile returned null, initializing as empty array" -Level Warning |
200 | | - $checkedOutRepos = @() |
201 | | - } else { |
202 | | - Write-Log "Invoke-DependencyFile returned type: $($checkedOutRepos.GetType().FullName)" -Level Debug |
203 | | - } |
204 | | - if ($null -eq $checkedOutRepos) { |
205 | | - Write-Log "WARNING: checkedOutRepos is null!" -Level Warning |
206 | | - $checkedOutRepos = @() |
207 | | - } |
208 | | - |
209 | | - Write-Log "Completed depth 0 processing: 1 dependency file processed, $($checkedOutRepos.Count) repositories checked out" -Level Info |
210 | | - |
211 | | - # Additional debug information |
212 | | - if ($EnableDebug) { |
213 | | - Write-Log "Detailed checkedOutRepos information:" -Level Debug |
214 | | - Write-Log " Count: $($checkedOutRepos.Count)" -Level Debug |
215 | | - Write-Log " IsArray: $($checkedOutRepos -is [Array])" -Level Debug |
216 | | - if ($checkedOutRepos.Count -gt 0) { |
217 | | - Write-Log " Repository details:" -Level Debug |
218 | | - foreach ($repo in $checkedOutRepos) { |
219 | | - Write-Log " - Repository: $($repo.Repository.'Repository URL'), Path: $($repo.AbsolutePath)" -Level Debug |
220 | | - } |
221 | | - } |
222 | | - } |
223 | | - |
224 | | - # If recursive mode is enabled, process nested dependencies |
225 | | - $isRecursiveMode = -not $DisableRecursion |
226 | | - Write-Log "Checking recursive processing conditions - RecursiveMode: $isRecursiveMode, CheckedOutRepos.Count: $($checkedOutRepos.Count)" -Level Debug |
227 | | - |
228 | | - if ($isRecursiveMode -and $checkedOutRepos.Count -gt 0) { |
229 | | - Write-Log "Entering recursive processing with $($checkedOutRepos.Count) repositories" -Level Info |
230 | | - $defaultDepFileName = Split-Path -Leaf $InputFile |
231 | | - Invoke-WithErrorContext -Context "Processing recursive dependencies" -ScriptBlock { |
232 | | - Invoke-RecursiveDependencies -CheckedOutRepos $checkedOutRepos -DefaultDependencyFileName $defaultDepFileName -CurrentDepth 0 |
233 | | - } |
234 | | - } else { |
235 | | - if ($DisableRecursion) { |
236 | | - Write-Log "Recursive processing skipped - recursive mode is disabled" -Level Info |
237 | | - } elseif ($checkedOutRepos.Count -eq 0) { |
238 | | - Write-Log "Recursive processing skipped - no new repositories were checked out at depth 0" -Level Info |
239 | | - } |
240 | | - } |
241 | | - |
242 | | - # Show summary |
243 | | - Show-Summary |
244 | | - |
245 | | - # Determine exit code from failure count |
246 | | - $failureCount = & (Get-Module RepoHerd) { $script:FailureCount } |
247 | | - if ($failureCount -gt 0) { |
248 | | - $exitCode = 1 |
249 | | - } |
250 | | -} |
251 | | -catch { |
252 | | - Write-ErrorWithContext -ErrorRecord $_ -AdditionalMessage "Unexpected error in main execution" |
253 | | - Show-ErrorDialog -Message $_.Exception.Message |
254 | | - $exitCode = 1 |
| 97 | +# When run from the script, default InputFile and CredentialsFile to the script directory |
| 98 | +if (-not $PSBoundParameters.ContainsKey('InputFile')) { |
| 99 | + $PSBoundParameters['InputFile'] = Join-Path $scriptDir "dependencies.json" |
255 | 100 | } |
256 | | -finally { |
257 | | - # Write structured output if requested — guaranteed even on failure |
258 | | - if (-not [string]::IsNullOrEmpty($OutputFile)) { |
259 | | - try { |
260 | | - Export-CheckoutResults -OutputFile $OutputFile |
261 | | - } |
262 | | - catch { |
263 | | - Write-Host "Failed to write output file: $_" -ForegroundColor Red |
264 | | - } |
265 | | - } |
| 101 | +if (-not $PSBoundParameters.ContainsKey('CredentialsFile')) { |
| 102 | + $PSBoundParameters['CredentialsFile'] = Join-Path $scriptDir "git_credentials.json" |
266 | 103 | } |
267 | 104 |
|
268 | | -exit $exitCode |
| 105 | +# Delegate to module function and exit with its return code |
| 106 | +exit (Invoke-RepoHerd @PSBoundParameters) |
0 commit comments