posh-git
posh-git copied to clipboard
Abbreviate Git Directory Edge Cases
Two edge cases not considered by original implementation (#720):
- If the current repo is bare, returns its parent directory.
-
Get-GitDirectory
inside a worktree currently returns the path to.git/worktrees/[name]
, which won't match the current path. I can think of two ways to resolve this:- Revise
Get-GitDirectory
to return the contents of.git/worktrees/[name]/gitdir
. No idea what the downstream effects of this would be. - Check here if
$gitPath
matches.git/worktrees/
; if it does, set$gitPath
to the contents of$gitPath/gitdir
- Revise
Submitted a PR (#797) to address nr 1 above.
I also found another thing which I don't really understand, Utils.ps1 line 288:
if (!$settings -or !$currentPath -or $currentPath.Equals($Home, $stringComparison))
This means that when in the home directory root, the path won't be abbreviated, this will only when I go down one or more levels. Isn't a more standard behavior to also abbreviate the home dir to only '~'?
Isn't a more standard behavior to also abbreviate the home dir to only '~'?
On Linux yes but after using it on Windows, it seemed a bit too much of an abbreviation for the typical Windows user. We could qualify that last condition with a test for the OS so that we'd only do this on Windows. Alternatively, we could add a new setting for this that defaults differently for Windows.
Alright, then I vote for a setting so that people who use both Windows and Linux can feel welcome at ~ :D
After thinking about this some more, I'm really tempted to simplify and make Windows behave like Linux and just show ~
when in the home dir.
Is it reasonable to default to whatever PowerShell defaults to without posh-git?
Well, PowerShell does not abbreviate paths displayed in the prompt. Maybe we should not enable this option DefaultPromptAbbreviateHomeDirectory
by default. And if the user does enable it, make it behave like a typical Linux prompt - always display ~
in place of the home path even when directly in the home path.
And if the user does enable it, make it behave like a typical Linux prompt - always display
~
in place of the home path even when directly in the home path.
This matches Git Bash behavior, too.
OK, I'll submit a PR to make this change later tonight!