8000 Extra error handling in ProcessGitActions · PoshCode/PSGit@6213ea8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6213ea8

Browse files
committed
Extra error handling in ProcessGitActions
1 parent af0c9e5 commit 6213ea8

File tree

1 file changed

+64
-45
lines changed

1 file changed

+64
-45
lines changed

Tests/Status.Steps.ps1

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,53 +35,72 @@ Given "we are in a git repository" {
3535

3636
function global:ProcessGitActions($table) {
3737
if($table) {
38-
foreach($change in $table) {
39-
Write-Host " $($change.FileAction) $($change.Name)" -Fore Green
40-
switch($change.FileAction) {
41-
"Created" {
42-
Set-Content $change.Name (Get-Date)
43-
}
44-
"Added" {
45-
# TODO: replace with PSGit native commands
46-
git add --all $change.Name
47-
}
48-
"Ignore" {
49-
# TODO: replace with PSGit native commands
50-
Add-Content .gitignore $change.Name
51-
git add .\.gitignore
52-
git commit -m "Ignore $($change.Name)"
53-
}
54-
"Modified" {
55-
Add-Content $change.Name (Get-Date)
56-
}
57-
"Commited" {
58-
# TODO: replace with PSGit native commands
59-
git commit -m "$($change.Name)"
60-
}
61-
"Removed" {
62-
Remove-Item $change.Name
63-
}
64-
"Renamed" {
65-
Rename-Item $change.Name $change.Value
66-
}
67-
"Push" {
68-
&{[CmdletBinding()]param()
69-
70-
git push
71-
72-
} 2>>..\git.log
73-
}
74-
"Branched" {
75-
&{[CmdletBinding()]param()
76-
77-
git checkout -b $change.Name
78-
79-
} 2>>..\git.log
80-
}
81-
"Reset" {
82-
git reset --hard $change.Name
38+
try {
39+
foreach($change in $table) {
40+
Write-Host " $($change.FileAction) $($change.Name)" -Fore Green
41+
switch($change.FileAction) {
42+
"Created" {
43+
Set-Content $change.Name (Get-Date)
44+
}
45+
"Added" {
46+
# TODO: replace with PSGit native commands
47+
git add --all $change.Name
48+
}
49+
"Ignore" {
50+
# TODO: replace with PSGit native commands
51+
Add-Content .gitignore $change.Name
52+
git add .\.gitignore
53+
git commit -m "Ignore $($change.Name)"
54+
}
55+
"Modified" {
56+
Add-Content $change.Name (Get-Date)
57+
}
58+
"Commited" {
59+
# TODO: replace with PSGit native commands
60+
git commit -m "$($change.Name)"
61+
}
62+
"Removed" {
63+
Remove-Item $change.Name
64+
}
65+
"Renamed" {
66+
Rename-Item $change.Name $change.Value
67+
}
68+
"Push" {
69+
&{[CmdletBinding()]param()
70+
71+
git push
72+
73+
} 2>>..\git.log
74+
}
75+
"Branched" {
76+
&{[CmdletBinding()]param()
77+
78+
git checkout -b $change.Name
79+
80+
} 2>>..\git.log
81+
}
82+
"Reset" {
83+
git reset --hard $change.Name
84+
}
8385
}
8486
}
87+
} catch {
88+
$ErrorRecord = $_
89+
Write-Host "Caught exception processing git actions. `nStackTrace:" -ForegroundColor Yellow
90+
91+
if ($ErrorRecord -is [System.Management.Automation.ErrorRecord]) {
92+
Write-Host $ErrorRecord.ScriptStackTrace
93+
$Ex = $ErrorRecord.Exception
94+
} else {
95+
Write-Host $ErrorRecord.ErrorRecord.ScriptStackTrace
96+
$Ex = $ErrorRecord
97+
}
98+
# recursively add the exception types as tags
99+
do {
100+
Write-Host ("Exception: " + $Ex.GetType().Name) -ForegroundColor Yellow
101+
Write-Host $Ex
102+
$Ex = $Ex.InnerException
103+
} while ($Ex)
85104
}
86105
}
87106
}

0 commit comments

Comments
 (0)
0