ugit
ugit copied to clipboard
Cleaner user facing errors for expected native git errors from `clone` and `-Since` / `--shallow-since`
About
Both expected native git errors errors are showing a stack trace when they should not.
The Since errors could use a clearer 'humanized' error message.
I first thought it was an error because it says Out-Git @OutGitParams: error processing shallow info: 4
It's actually because StartAutomating/Rocker had has zero commits within the date range of 1 months.
- Use
-Since ([DateTime]::Now.AddMonths(-11))and the clone works as expected - I don't know what
4means
Suggested Behavior
Printing the stacktrace to out-git is misleading. It makes it look like ugit itself has an error. I propose:
Pwsh> git clone -Since ([DateTime]::Now.AddSeconds(-1)) 'https://www.github.com/StartAutomating/Rocker'
Error: Zero history was found for 'https://www.github.com/StartAutomating/Rocker' with since filter: '2024-06-15T20:50:42.9423564-05:00'
Pwsh> git clone https://github.com/StartAutomating/badRepoName
Error: Repository 'https://github.com/StartAutomating/badRepoName.git' was not found
Pwsh> git clone 'https://www.github.com/StartAutomating/Rocker'
Error: destination path 'Rocker' already exists and is not an empty directory
Suggested Sources to Catch
- [ ] when zero records are found using
ugit -sinceorgit.exe --shallow-since - [ ] when RepositoryUrl was not found
- [ ] when directory already exists:
destination path 'Rocker' already exists and is not an empty directory
Actual Behavior
To Reproduce: using ugit
# I included `Save-Module` to rule out filepaths, but it's not required for the error.
mkdir 'g:\temp\psnow'
pushd 'G:\temp\psnow'
Save-Module ugit -Path .\Imports
ipmo .\Imports\ugit -Force -PassThru # version 0.4.4
# Case 1
[DateTime] $Since = ([DateTime]::Now.AddSeconds(-1))
[uri] $RepoUrl = 'https://www.github.com/StartAutomating/Rocker'
git clone -Since $Since $RepoUrl
# Case 2
git clone 'https://www.github.com/StartAutomating/BadRepoName'
To Reproduce: using native git
Case 1:
Remove-module ugit* # ensure native command is invoked
[DateTime] $Since = ([DateTime]::Now.AddSeconds(-1))
[uri] $RepoUrl = 'https://www.github.com/StartAutomating/Rocker'
$SinceArg = '--shallow-since="{0}"' -f $Since.ToString('o')
git clone $SinceArg $RepoUrl
output:
Cloning into 'Rocker'...
warning: redirecting to https://github.com/StartAutomating/Rocker.git/
fatal: error processing shallow info: 4
Case 2:
Remove-module ugit* # ensure native command is invoked
git clone 'https://www.github.com/StartAutomating/BadRepoName'
output:
Cloning into 'BadRepoName'...
remote: Repository not found.
fatal: repository 'https://github.com/StartAutomating/BadRepoName.git/' not found
Environment
Powershell: 'pwsh 7.4.2'
ugit: '0.4.4'
git: '2.45.2.windows.1'
Error Details
Pwsh🐒> [DateTime] $Since = ([DateTime]::Now.AddMonths(-1))
Pwsh🐒> [uri] $RepoUrl = 'https://www.github.com/StartAutomating/Rocker'
Pwsh🐒> git clone --no-checkout -Since $Since $RepoUrl
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 0.4.4 ugit {Get-UGitExtension, Out-Git, Use-Git, git…}
Out-Git: C:\Users\cppmo_000\SkyDrive\Documents\PowerShell\Modules\ugit\0.4.4\Commands\Use-Git.ps1:436
Line |
436 | Out-Git @OutGitParams # output git as obj …
| ~~~~~~~~~~~~~~~~~~~~~
| error processing shallow info: 4
Pwsh🐒> $error
Out-Git: G:\temp\psnow\Imports\ugit\0.4.4\Commands\Use-Git.ps1:436
Line |
436 | Out-Git @OutGitParams # output git as obj …
| ~~~~~~~~~~~~~~~~~~~~~
| error processing shallow info: 4
Pwsh🐒> Get-Error
Exception :
Type : System.Exception
Message : error processing shallow info: 4
HResult : -2146233088
TargetObject : fatal: error processing shallow info: 4
CategoryInfo : NotSpecified: (fatal: error processing shallow info: 4:String) [Out-Git], Exception
FullyQualifiedErrorId : git clone --shallow-since=2024-06-15T19:56:07.4377206-05:00 --progress --no-checkout
https://www.github.com/StartAutomating/Rocker ,Out-Git
InvocationInfo :
MyCommand : Out-Git
ScriptLineNumber : 436
OffsetInLine : 29
HistoryId : 85
ScriptName : G:\temp\psnow\Imports\ugit\0.4.4\Commands\Use-Git.ps1
Line : Out-Git @OutGitParams # output git as objects.
Statement : Out-Git @OutGitParams
PositionMessage : At G:\temp\psnow\Imports\ugit\0.4.4\Commands\Use-Git.ps1:436 char:29
+ Out-Git @OutGitParams # output git as obj …
+ ~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot : G:\temp\psnow\Imports\ugit\0.4.4\Commands
PSCommandPath : G:\temp\psnow\Imports\ugit\0.4.4\Commands\Use-Git.ps1
InvocationName : Out-Git
CommandOrigin : Internal
ScriptStackTrace : at Out-Git<Process>, G:\temp\psnow\Imports\ugit\0.4.4\Commands\Out-Git.ps1: line 201
at Use-Git<End>, G:\temp\psnow\Imports\ugit\0.4.4\Commands\Use-Git.ps1: line 434
at <ScriptBlock>, <No file>: line 4
PipelineIterationInfo :
0
0
3