Mercurial > hg-stable
changeset 47621:d6ee6456bd5f
windows: enforce upper case drive letter for getcwd in mercurial too
This is affecting code that checks if a pull/push destination is the same as a
configured one. For example the one creating divergent bookmark.
Doing this fixes will help fixing `test-bookmarks.t` and `test-bookflow.t` on
Windows. However, we also need to fix `abspath` invocation.
Differential Revision: https://phab.mercurial-scm.org/D11058
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sat, 10 Jul 2021 13:10:18 +0200 |
parents | 724066f23e2d |
children | bb917eea1605 |
files | mercurial/encoding.py |
diffstat | 1 files changed, 18 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/encoding.py Fri Jul 09 23:38:24 2021 +0200 +++ b/mercurial/encoding.py Sat Jul 10 13:10:18 2021 +0200 @@ -9,6 +9,7 @@ import locale import os +import re import unicodedata from .pycompat import getattr @@ -352,6 +353,8 @@ environ[tolocal(k.encode('utf-8'))] = tolocal(v.encode('utf-8')) +DRIVE_RE = re.compile(b'^[a-z]:') + if pycompat.ispy3: # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which # returns bytes. @@ -363,7 +366,21 @@ # os.path.realpath(), which is used on ``repo.root``. Since those # strings are compared in various places as simple strings, also call # realpath here. See https://bugs.python.org/issue40368 - getcwd = lambda: strtolocal(os.path.realpath(os.getcwd())) # re-exports + # + # However this is not reliable, so lets explicitly make this drive + # letter upper case. + # + # note: we should consider dropping realpath here since it seems to + # change the semantic of `getcwd`. + + def getcwd(): + cwd = os.getcwd() # re-exports + cwd = os.path.realpath(cwd) + cwd = strtolocal(cwd) + if DRIVE_RE.match(cwd): + cwd = cwd[0:1].upper() + cwd[1:] + return cwd + else: getcwd = os.getcwdb # re-exports else: