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

Case sensitivity with file paths #130

Closed
nycdotnet opened this issue Jan 11, 2014 · 22 comments
Closed

Case sensitivity with file paths #130

nycdotnet opened this issue Jan 11, 2014 · 22 comments
Milestone

Comments

@nycdotnet
Copy link

Posh-git displays strange behavior if you navigate to a directory using the wrong case.

Imagine a directory called "code" with a subdirectory called "Model". The posh-git prompt is in code. User types "cd model" (all lower-case, so technically the incorrect case). PowerShell handles this fine and will show the prompt as "code\model", but if you do git status (for example) it will show any changes in the Model folder as "..\Model\changedfile.txt" instead of "changedfile.txt". This is technically correct if Git is assuming that both the model and Model directories exist. Other commands such as git mv OLD NEW, don't work at all as Git will warn that the file is not under source control.

Is there any way to get posh-git to intercept and fix cases on cd commands (or at least error/warn if a case is invalid)? I'm willing to look into this a bit if it sounds like this is something that you're interested to address. Thanks!

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 11, 2014

Interesting...never noticed that. I'd gladly accept a PR if you're able to fix this, otherwise it seems like something that we should be able to fix for free once I get around to pulling in LibGit2Sharp.

@nycdotnet
Copy link
Author

How soon will that be? Perhaps this is a good Jump In tag issue in the meantime?

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 15, 2014

Perhaps this is a good Jump In tag issue in the meantime?

Done :)

@sclarson
Copy link

Here is something that would work in powershell 3. Not sure how to do this in v2 yet, maybe proxy set-location?

@lzybkr
Copy link
Collaborator

lzybkr commented Sep 22, 2014

Is there a way you can resolve the path in posh-git before runing commands instead of trying to hook cd/set-location? For example, maybe you can call [System.IO.Directory]::SetCurrentDirectory with the case correct path before calling git.

The PostCommandLookupHandler won't work in V2 and there are other cases you need to catch anyway, e.g. Push-Location and other custom cmdlets like Set-LocationEx (from PSCX) and Jump-Target.

@dahlbyk
Copy link
Owner

dahlbyk commented Sep 24, 2014

The challenge here is that posh-git doesn't actually intercept git calls, so there's not an easy way to hook in to reset its working directory correctly. Proxying directory changes would work were there not many ways for the current directory to change (as @lzybkr points out).

Rather than pretend the case is correct, maybe we should:

  1. Add a function (name suggestions?) to Set-Location with case correction, and
  2. Add a warning to the default prompt referencing that function if $pwd is indeed mis-cased

Thoughts?

@nycdotnet
Copy link
Author

@dahlbyk I think suggestion 2 is fair. I'm not sure I understand what suggestion 1 is intended to do.

@dahlbyk
Copy link
Owner

dahlbyk commented Sep 24, 2014

Suggestion 1 is really just meant to provide a shortcut we can suggest be used to fix the casing, e.g. "Current path may confuse Git, which is case-sensitive. Use Reset-Location to correct the path case."

@sclarson
Copy link

I'm assuming that calling reset-location as part of the prompt to make it transparent to the user is also more invasive than you want the default behavior to be?

@dahlbyk
Copy link
Owner

dahlbyk commented Sep 24, 2014

I'm assuming that calling reset-location as part of the prompt to make it transparent to the user is also more invasive than you want the default behavior to be?

We could add a setting to auto-fix location (and mention it in the warning?), but with all the location-changing alternatives out there it seems better to have a conservative default.

@nycdotnet
Copy link
Author

@dahlbyk I agree with being conservative in this case. I like "fix" better than "reset", so I'd suggest something like Fix-GitPwdCase or Fix-GitPathCase.

@dahlbyk
Copy link
Owner

dahlbyk commented Sep 24, 2014

Fix is not an approved PowerShell verb (Get-Verb lists those that are).

@nycdotnet
Copy link
Author

I should have thought of that. Perhaps Use-ExactPwdCase? Reset-Location is certainly fine if you prefer that - it just sounds non-specific and a collision risk (if that is actually a risk).

@dahlbyk
Copy link
Owner

dahlbyk commented Sep 25, 2014

Reset-Location is indeed not specific enough, though collision-wise it will be associated with the posh-git module so that should sufficiently disambiguate.

Reset-LocationCase? Optimize-LocationCase? I like the idea of keeping "Location" in the name to align with Set-Location/Push-Location.

@nycdotnet
Copy link
Author

Not sure why, but Optimize makes me chuckle. I suppose Reset-LocationCase is the best bet.

@lzybkr
Copy link
Collaborator

lzybkr commented Sep 25, 2014

Have you considered creating a function 'git' that fixes the path before running git.exe?

@dahlbyk
Copy link
Owner

dahlbyk commented Sep 25, 2014

Have you considered creating a function 'git' that fixes the path before running git.exe?

I haven't tried, but it's come up before as something that may open up some opportunities. I'm not sure what the best way to accurately forward the function's arguments on to git.exe would be, though.

sclarson added a commit to sclarson/posh-git that referenced this issue Sep 26, 2014
@sclarson
Copy link

So something more along the lines of the above commit is what you'd currently have in mind?

I couldn't think of anything better for warning text, and there might already be a color I should have used from a setting rather than just hard coding "red". Also could have made the warning only appear when inside a git repository.

@dahlbyk
Copy link
Owner

dahlbyk commented Sep 26, 2014

That's pretty much exactly what I was thinking - open a PR?

@sclarson
Copy link

Will do.

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 22, 2017

Not sure when this was fixed, but I can no longer reproduce this in git 2.10.2.

@dahlbyk dahlbyk closed this as completed Feb 22, 2017
@nycdotnet
Copy link
Author

ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants