posh-git icon indicating copy to clipboard operation
posh-git copied to clipboard

Abbreviate Git Directory Edge Cases

Open dahlbyk opened this issue 4 years ago • 8 comments

Two edge cases not considered by original implementation (#720):

  1. If the current repo is bare, returns its parent directory.
  2. 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:
    1. Revise Get-GitDirectory to return the contents of .git/worktrees/[name]/gitdir. No idea what the downstream effects of this would be.
    2. Check here if $gitPath matches .git/worktrees/; if it does, set $gitPath to the contents of $gitPath/gitdir

dahlbyk avatar Mar 16 '20 05:03 dahlbyk

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 '~'?

RexTremendae avatar Oct 03 '20 08:10 RexTremendae

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.

rkeithhill avatar Oct 03 '20 20:10 rkeithhill

Alright, then I vote for a setting so that people who use both Windows and Linux can feel welcome at ~ :D

RexTremendae avatar Oct 04 '20 09:10 RexTremendae

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.

rkeithhill avatar Oct 17 '20 20:10 rkeithhill

Is it reasonable to default to whatever PowerShell defaults to without posh-git?

dahlbyk avatar Oct 19 '20 02:10 dahlbyk

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.

rkeithhill avatar Oct 19 '20 02:10 rkeithhill

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.

dahlbyk avatar Oct 19 '20 04:10 dahlbyk

OK, I'll submit a PR to make this change later tonight!

rkeithhill avatar Oct 19 '20 17:10 rkeithhill