[Bug 4805] New: hgclient.open opens the current directory repository when non-existent path is given

mercurial-bugs at selenic.com mercurial-bugs at selenic.com
Mon Aug 31 04:04:45 CDT 2015


http://bz.selenic.com/show_bug.cgi?id=4805

          Priority: normal
            Bug ID: 4805
                CC: mercurial-devel at selenic.com
          Assignee: bugzilla at selenic.com
           Summary: hgclient.open opens the current directory repository
                    when non-existent path is given
          Severity: bug
    Classification: Unclassified
                OS: Linux
          Reporter: javier.santacruz.lc at gmail.com
          Hardware: PC
            Status: UNCONFIRMED
           Version: unspecified
         Component: hglib
           Product: Mercurial

hgclient.open opens the current directory repository when non-existent path is
given

How to reproduce this behaviour:

* Change current work directory to an existing repository
* Try opening a non-existing path with hglib.open

It does not fail but opens the current directory repository instead.

>>> os.getcwd()
'c:\\users\\user\\repos\\repository'
>>> hglib.open('.').identify()
'1e559b99769c+ tip\n'
>>> hglib.open('c:\lalalalalala').identify()
'1e559b99769c+ tip\n'

This only happens when the current work directory is a repository.
Performing the same operation from a regular directory behaves correctly.

>>> os.getcwd()
'c:\\users\\user'
>>> hglib.open('c:\lalalalalala')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jsl\Envs\taricpy\lib\site-packages\hglib\client.py", line 845,
in identify
    return self.rawcommand(args)
  File "C:\Users\jsl\Envs\taricpy\lib\site-packages\hglib\client.py", line 183,
in rawcommand
    raise error.CommandError(args, ret, out, err)
hglib.error.CommandError: (255, '', 'abort: there is no Mercurial repository
here (.hg not found)')

I would expect the client to fail by raising a CommandError either at calling
.open() or when trying to use the repository if the supplied repository PATH
does not exists or does not contain a repository.

This behaviour confuses me and increases the amount of work the client
programmer has to do in order to safely open a repository given an arbitrary
file system location.

Versions:

Reproduced both in Windows (py2.7.8) and Linux (py2.7.10 / py3.4.3)

> uname -a
> Linux tlap 4.1.6-1-ARCH #1 SMP PREEMPT Mon Aug 17 08:52:28 CEST 2015 x86_64 GNU/Linux

python --version
Python 3.4.3

python --version
Python 3.7.10

> OS Name	Microsoft Windows Server 2012 Datacenter
> Version	6.2.9200 Build 9200

> python --version
Python 2.7.8

> hg --version
Mercurial Distributed SCM (version 3.0)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Mercurial-devel mailing list