Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If abbreviating git dir, display correct path on a bare repo #797

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ function Get-PromptPath {
# Look up the git root
if ($abbrevGitDir) {
$gitPath = Get-GitDirectory
# Up one level from `.git`
if ($gitPath) { $gitPath = Split-Path $gitPath -Parent }
# Up one level from `.git` if inside git directory
if ($gitPath -and $gitPath.EndsWith(".git")) { $gitPath = Split-Path $gitPath -Parent }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we should clarify what's expected here. As far as I can tell from my testing, this doesn't actually change behavior - I get this same display before and after:
image

I could argue that it should show posh-git.git: [BARE:master]> instead of Temp:posh-git.git.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the idea of the PR. I get a different behavior when I compare current master (just updated today) with this PR (which now is rebased onto master):

image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the difference is my bare repo has a .git suffix but yours does not:
image

Maybe we should check (Split-Path $gitDir -Leaf) -eq '.git' instead of EndsWith()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right you are...

Thinking a little bit more about it, I think my solution is a little bit over-simplified. Maybe the correct solution would be to base the logic on the same information that casues the "BARE:" label to appear? However, I cannot see that information being stored anywhere other than in the branch specifier after the function Get-GitBranch has completed.

I really don't have the full overview of how all the functions work together in the code base; maybe it is possible to receive this information somehow?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking a little bit more about it, I think my solution is a little bit over-simplified. Maybe the correct solution would be to base the logic on the same information that casues the "BARE:" label to appear? However, I cannot see that information being stored anywhere other than in the branch specifier after the function Get-GitBranch has completed.

You're right, we only store BARE/GIT_DIR in the branch name at the moment. We could definitely tack those onto $GitStatus with a bit of refactoring, but we'd also have to rearrange quite a bit to make $GitStatus available at the point where we're calling Get-PromptPath.

Let's just check for a .git exact match for now. If we get feedback that it's insufficient, we can revisit.

I really don't have the full overview of how all the functions work together in the code base; maybe it is possible to receive this information somehow?

I don't know that we have an overview written up anywhere, but that would definitely be good to have. In short:

  1. Unless it has already been customized, we replace prompt with $GitPromptScriptBlock
    $GitPromptScriptBlock = {
  2. $GitPromptScriptBlock builds the actual prompt mostly by expanding strings defined in $global:GitPromptSettings
    class PoshGitPromptSettings {
  3. Git status comes into the prompt from Write-GitStatus via Write-VcsStatus (added to support posh-hg long ago)
    function Write-GitStatus {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for the walk-through!

}

# Abbreviate path under a git repository as "<repo-name>:<relative-path>"
Expand Down