Sourcetree Windows fails to clone a private Hg hosted on Bitbucket
Asked by tcuvelier:

Dear all,

I am currently using Sourcetree 3.0.6-beta-2193 (the latest, it seems) on Windows 10 1709, with both embedded Git (2.18.0/LibGit2Sharp 0.24.0 + git-lfs v2.4.2) and Hg (4.6.2). I work behind a nasty proxy, which blocks many many things (including SSH) --- well, at least, it does not require authentication. I configured Sourcetree to use OAuth authentication for both Bitbucket and GitHub, and to use HTTPS as the preferred protocol.

When I try to clone a private repository, I get a handful of errors if the repository is a Mercurial one hosted on Bitbucket. In Sourcetree, I click on the + to open a new tab, then Remote, I select one of my repos (Sourcetree can easily retrieve the complete list), Clone. Then, Sourcetree fails to identify the type of repository, with these errors:

```
Command: perl.exe C:\Users\XXX\AppData\Local\SourceTreebeta\app-3.0.6-beta-2193\tools\svn.pl info https://tcuvelier@bitbucket.org/tcuvelier/YYY
Output: 
Error: System.ComponentModel.Win32Exception: The system cannot find the file specified

Command: git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks -c credential.helper= -c credential.helper="C:/Users/XXX/AppData/Local/SOURCE~2/beta/GIT_EX~1/GIT-CR~1.EXE" ls-remote https://tcuvelier@bitbucket.org/tcuvelier/YYY
Output: 
Error: remote: Mercurial (hg) is required to use this repository.
remote: 
remote: https://confluence.atlassian.com/x/vLRCMw
fatal: unable to access 'https://tcuvelier@bitbucket.org/tcuvelier/YYY/': The requested URL returned error: 405

Command: hg identify extensions.hgext.hgsubversion=! https://tcuvelier@bitbucket.org/tcuvelier/YYY
Output: 
Error: ** Unknown exception encountered with possibly-broken third-party extension mercurial_credential_manager
** which supports versions unknown of Mercurial.
** Please disable mercurial_credential_manager and try your action again.
** If that fixes the bug please report it to https://github.com/mminns/mercurial_credential_manager_for_windows
** Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:22:17) [MSC v.1500 32 bit (Intel)]
** Mercurial Distributed SCM (version 4.6.2)
** Extensions loaded: mercurial_credential_manager, rebase, transplant, extdiff, fetch, strip, mq, hgflow, shelve
Traceback (most recent call last):
? File "hg", line 41, in <module>
? File "mercurial\dispatch.pyc", line 90, in run
? File "mercurial\dispatch.pyc", line 210, in dispatch
? File "mercurial\dispatch.pyc", line 351, in _runcatch
? File "mercurial\dispatch.pyc", line 359, in _callcatch
? File "mercurial\scmutil.pyc", line 160, in callcatch
? File "mercurial\dispatch.pyc", line 341, in _runcatchfunc
? File "mercurial\dispatch.pyc", line 971, in _dispatch
? File "mercurial\dispatch.pyc", line 727, in runcommand
? File "mercurial\dispatch.pyc", line 979, in _runcommand
? File "mercurial\dispatch.pyc", line 968, in <lambda>
? File "mercurial\util.pyc", line 1553, in check
? File "mercurial\util.pyc", line 1553, in check
? File "hgext\mq.pyc", line 3599, in mqcommand
? File "mercurial\util.pyc", line 1553, in check
? File "mercurial\commands.pyc", line 2805, in identify
? File "mercurial\hg.pyc", line 189, in peer
? File "mercurial\hg.pyc", line 163, in _peerorrepo
? File "mercurial\httppeer.pyc", line 987, in instance
? File "mercurial\httppeer.pyc", line 951, in makepeer
? File "mercurial\httppeer.pyc", line 871, in performhandshake
? File "mercurial\httppeer.pyc", line 311, in sendrequest
? File "urllib2.pyc", line 435, in open
? File "urllib2.pyc", line 548, in http_response
? File "urllib2.pyc", line 467, in error
? File "urllib2.pyc", line 407, in _call_chain
? File "urllib2.pyc", line 909, in http_error_401
? File "mercurial\url.pyc", line 463, in http_error_auth_reqed
? File "C:/Users/XXX/AppData/Local/SourceTree-Settings/beta/hg_extras/mercurial_credential_manager.py", line 437, in basic_http_error_auth_reqed
??? return basic_http_error_auth_reqed.orig(self, authreq, host, req, headers)
? File "urllib2.pyc", line 887, in http_error_auth_reqed
? File "mercurial\url.pyc", line 467, in retry_http_basic_auth
? File "C:/Users/XXX/AppData/Local/SourceTree-Settings/beta/hg_extras/mercurial_credential_manager.py", line 428, in find_user_password
??? return self._pwd_handler.find_auth(self, realm, authuri, req)
? File "C:/Users/XXX/AppData/Local/SourceTree-Settings/beta/hg_extras/mercurial_credential_manager.py", line 259, in find_auth
??? if username[0]:
IndexError: list index out of range

```

I do not have the same troubles with Git, be it on Bitbucket or GitHub: everything works fine.

Of course, I already configured the proxy in both Git and Mercurial (taking the same parameters as the ones used by my browser):

```
git config --global http.proxy http://nasty.proxy:8080
```

In my %USERPROFILE%\\mercurial.ini:

```
[http_proxy]
host=nasty.proxy:8080
```

This proxy is also configured in Sourcetree (Tools \> Options \> Network), using a custom proxy. I checked "Add proxy server configuration to Git / Mercurial".

I feel a bit lost in all of this... Is there anything missing in my configuration? Or is it just that the proxy is blocking specifically Bitbucket? (I have access to the website through the proxy, if that helps.)

Thanks in advance!


Answers:
author: pemerick07
body: Hi, I'm getting a similar problem of no hg remote features in Sourcetree working. I tried all of the solutions suggested with no luck. I think this is definitely related to the Bitbucket TLS transition because the last time we interacted with remote was in mid-November, before Bitbucket transitioned to exclusive TLS 1.2 support. This is a problem across 4 different computers of which I've went through the following process on 2 different computers.

1) Installed latest Sourcetree version - 3.0.12

2) Installed latest embedded hg version - 4.6.2

3) Installed standalone hg (4.8.1) and used it inside of Sourcetree (3.0.12)

4) Temporarily changed repo to public to test if credentials were causing this error

5) Tested hg inside TortoiseHG with success - I pulled, pushed and cloned

Any support would be appreciated because I prefer to use Sourcetree instead of terminal of Tortoise. Thanks.

comments: author: minnsey
body: Can I check you are using HTTPS style remote urls for the repo, not SSH ?

Also does your url contain a username?  

To be clear, I can't as yet reproduce your problem.


author: pemerick07
body: Michael,

Clone URLs we use are in this format: https://\[username\]@bitbucket.org/\[organization\]/\[repo\]

Problem was gone in Sourcetree version 3.0.12 when we returned from our Holiday break on Jan 2nd.


author: minnsey
body: Thanks for the update, glad everything is working.


author: Martin
body: I solved it like that:

In Sourcetree -\> Settings -\> In the tab "Remotes" -\> Select your path -\> Click Edit -\> In the field URL / Path, add ( : ) + you password like that:

https://user:password@bitbucket.org/project1


author: minnsey
body: Please upgrade to 3.0.12. The issues is with the removal of TLS 1/1.1 from Bitbucket.  

3.0.12 includes updates authentication components that support TLS 1.2  

<https://product-downloads.atlassian.com/software/sourcetree/windows/ga/SourceTreeSetup-3.0.12.exe>

comments: author: tcuvelier
body: Thanks for your answer. I could not test your solution yet, but I'm not sure the issue is linked with old TLS versions: it happened well before December 1st. I'll still give it a shot ASAP.


author: Wayne Woods
body: The update fixed it for me. Thanks Michael!


author: tcuvelier
body: The update doesn't solve the problem for me (3.0.13). I tried to update the embedded Hg, but it brought no solution.

```
Command: perl.exe C:\Users\xxxx\AppData\Local\SourceTreebeta\app-3.0.13-beta-2567\tools\svn.pl info https://tcuvelier@bitbucket.org/tcuvelier/moocs
Output: 
Error: System.ComponentModel.Win32Exception: The system cannot find the file specified

Command: git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks -c credential.helper= -c credential.helper="C:/Users/xxxx/AppData/Local/SOURCE~2/beta/GIT_EX~1/GIT-CR~1.EXE" ls-remote https://tcuvelier@bitbucket.org/tcuvelier/moocs
Output: 
Error: remote: Mercurial (hg) is required to use this repository.
remote: 
remote: https://confluence.atlassian.com/x/vLRCMw
fatal: unable to access 'https://tcuvelier@bitbucket.org/tcuvelier/moocs/': The requested URL returned error: 405

Command: hg identify extensions.hgext.hgsubversion=! https://tcuvelier@bitbucket.org/tcuvelier/moocs
Output: 
Error: ** Unknown exception encountered with possibly-broken third-party extension mercurial_credential_manager
** which supports versions unknown of Mercurial.
** Please disable mercurial_credential_manager and try your action again.
** If that fixes the bug please report it to https://github.com/mminns/mercurial_credential_manager_for_windows
** Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:22:17) [MSC v.1500 32 bit (Intel)]
** Mercurial Distributed SCM (version 4.6.2)
** Extensions loaded: mercurial_credential_manager, rebase, transplant, extdiff, fetch, strip, mq, hgflow, shelve
Traceback (most recent call last):
? File "hg", line 41, in <module>
? File "mercurial\dispatch.pyc", line 90, in run
? File "mercurial\dispatch.pyc", line 210, in dispatch
? File "mercurial\dispatch.pyc", line 351, in _runcatch
? File "mercurial\dispatch.pyc", line 359, in _callcatch
? File "mercurial\scmutil.pyc", line 160, in callcatch
? File "mercurial\dispatch.pyc", line 341, in _runcatchfunc
? File "mercurial\dispatch.pyc", line 971, in _dispatch
? File "mercurial\dispatch.pyc", line 727, in runcommand
? File "mercurial\dispatch.pyc", line 979, in _runcommand
? File "mercurial\dispatch.pyc", line 968, in <lambda>
? File "mercurial\util.pyc", line 1553, in check
? File "mercurial\util.pyc", line 1553, in check
? File "hgext\mq.pyc", line 3599, in mqcommand
? File "mercurial\util.pyc", line 1553, in check
? File "mercurial\commands.pyc", line 2805, in identify
? File "mercurial\hg.pyc", line 189, in peer
? File "mercurial\hg.pyc", line 163, in _peerorrepo
? File "mercurial\httppeer.pyc", line 987, in instance
? File "mercurial\httppeer.pyc", line 951, in makepeer
? File "mercurial\httppeer.pyc", line 871, in performhandshake
? File "mercurial\httppeer.pyc", line 311, in sendrequest
? File "urllib2.pyc", line 435, in open
? File "urllib2.pyc", line 548, in http_response
? File "urllib2.pyc", line 467, in error
? File "urllib2.pyc", line 407, in _call_chain
? File "urllib2.pyc", line 909, in http_error_401
? File "mercurial\url.pyc", line 463, in http_error_auth_reqed
? File "C:/Users/xxxx/AppData/Local/SourceTree-Settings/beta/hg_extras/mercurial_credential_manager.py", line 437, in basic_http_error_auth_reqed
??? return basic_http_error_auth_reqed.orig(self, authreq, host, req, headers)
? File "urllib2.pyc", line 887, in http_error_auth_reqed
? File "mercurial\url.pyc", line 467, in retry_http_basic_auth
? File "C:/Users/xxxx/AppData/Local/SourceTree-Settings/beta/hg_extras/mercurial_credential_manager.py", line 428, in find_user_password
??? return self._pwd_handler.find_auth(self, realm, authuri, req)
? File "C:/Users/xxxx/AppData/Local/SourceTree-Settings/beta/hg_extras/mercurial_credential_manager.py", line 259, in find_auth
??? if username[0]:
IndexError: list index out of range

```


author: minnsey
body: For what its worth that error can also appear if the wrong credentials are used.


author: Duncan McIntyre
body: Hi [@Wayne Woods](/t5/user/viewprofilepage/user-id/527827) and [@Moshe Freund](/t5/user/viewprofilepage/user-id/2374783), not sure if you've work around this. But it's all working for me now using SSH instead of using HTTPS in my Accounts. I'm guessing that's because SSH doesn't use the credential manager that the error is complaining about.   

Was banging my head all day yesterday as this started happening on both my Windows and Mac machines and I had some changes from the Windows machine I needed to push and pull on my Mac. Hope you guys sort out the issues from your end as well.

comments: author: tcuvelier
body: When you have the chance to have SSH going through your proxy, it may be a solution, but that is definitely not my case :(.

To you all: maybe voting for <https://jira.atlassian.com/browse/SRCTREEWIN-10824> might help Atlassian prioritise this bug...


author: Wayne Woods
body: Trying to switch to ssh, it tells me that ssh isn't a recognized command by remote. :/


author: Duncan McIntyre
body: Hi [@Wayne Woods](/t5/user/viewprofilepage/user-id/527827) I followed this documentation to add the ssh keys to our bitbucket settings [https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html](https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html?)


author: Duncan McIntyre
body: [@tcuvelier](/t5/user/viewprofilepage/user-id/623319) Will do once I have that access. I get below message when clicking that link you posted to vote. Maybe because I'm new here.

You can't view this issue {#toc-hId-1849751830}
-----------------------------------------------

It may have been deleted or you don't have permission to view it.


author: minnsey
body: Hi  

It looks like an issue in the mercurial credential manager extension Sourcetree uses to share credentials between Sourcetree and Hg.  

Can I ask what version of Mercurial you are using and if it is not sensitive, or can be sensibly made anonymous, what does the URL you are cloning look like?

comments: author: tcuvelier
body: Thank you for your answer! (I already tried to look at the code myself, but albeit it is just Python I did not really understand what was going on there...)

I am using Mercurial 4.6.2 (downloaded by Sourcetree, not my own) and I am trying to clone URLs like https://tcuvelier@bitbucket.org/tcuvelier/moocs/ (as provided by Bitbucket when clicking on the Clone button).


author: minnsey
body: Can you try upgrading your Mercurial. Installing as a standalone instance and then setting Sourcetree to use it as a System Install in Tools/Options/Hg tab?


author: tcuvelier
body: I get the same kind of error (4.8 x64, coming straight from the official website):

```
Command: hg identify extensions.hgext.hgsubversion=! https://tcuvelier@bitbucket.org/tcuvelier/moocs
Output: 
Error: *** failed to import extension hgext.hgflow from C:\Users\XXX\AppData\Local\SourceTreebeta\app-3.0.6-beta-2193\extras\hgext\hgflow\hgflow.py: 'module' object has no attribute 'command'
** Unknown exception encountered with possibly-broken third-party extension mercurial_credential_manager
** which supports versions unknown of Mercurial.
** Please disable mercurial_credential_manager and try your action again.
** If that fixes the bug please report it to https://github.com/mminns/mercurial_credential_manager_for_windows
** Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)]
** Mercurial Distributed SCM (version 4.8)
** Extensions loaded: mercurial_credential_manager, rebase, transplant, extdiff, fetch, strip, mq, shelve
Traceback (most recent call last):
? File "hg", line 43, in <module>
? File "mercurial\dispatch.pyc", line 96, in run
? File "mercurial\dispatch.pyc", line 220, in dispatch
? File "mercurial\dispatch.pyc", line 363, in _runcatch
? File "mercurial\dispatch.pyc", line 371, in _callcatch
? File "mercurial\scmutil.pyc", line 166, in callcatch
? File "mercurial\dispatch.pyc", line 354, in _runcatchfunc
? File "mercurial\dispatch.pyc", line 994, in _dispatch
? File "mercurial\dispatch.pyc", line 737, in runcommand
? File "mercurial\dispatch.pyc", line 1003, in _runcommand
? File "mercurial\dispatch.pyc", line 991, in <lambda>
? File "mercurial\util.pyc", line 1644, in check
? File "mercurial\util.pyc", line 1644, in check
? File "hgext\mq.pyc", line 3631, in mqcommand
? File "mercurial\util.pyc", line 1644, in check
? File "mercurial\commands.pyc", line 3132, in identify
? File "mercurial\hg.pyc", line 200, in peer
? File "mercurial\hg.pyc", line 161, in _peerorrepo
? File "mercurial\httppeer.pyc", line 997, in instance
? File "mercurial\httppeer.pyc", line 961, in makepeer
? File "mercurial\httppeer.pyc", line 881, in performhandshake
? File "mercurial\httppeer.pyc", line 275, in sendrequest
? File "urllib2.pyc", line 435, in open
? File "urllib2.pyc", line 548, in http_response
? File "urllib2.pyc", line 467, in error
? File "urllib2.pyc", line 407, in _call_chain
? File "urllib2.pyc", line 909, in http_error_401
? File "mercurial\url.pyc", line 463, in http_error_auth_reqed
? File "C:/Users/XXX/AppData/Local/SourceTree-Settings/beta/hg_extras/mercurial_credential_manager.py", line 437, in basic_http_error_auth_reqed
??? return basic_http_error_auth_reqed.orig(self, authreq, host, req, headers)
? File "urllib2.pyc", line 887, in http_error_auth_reqed
? File "mercurial\url.pyc", line 467, in retry_http_basic_auth
? File "C:/Users/XXX/AppData/Local/SourceTree-Settings/beta/hg_extras/mercurial_credential_manager.py", line 428, in find_user_password
??? return self._pwd_handler.find_auth(self, realm, authuri, req)
? File "C:/Users/XXX/AppData/Local/SourceTree-Settings/beta/hg_extras/mercurial_credential_manager.py", line 259, in find_auth
??? if username[0]:
IndexError: list index out of range
```


author: minnsey
body: It looks like some kind of bug in the Mercurial Credential Manager possibly triggered by the proxy, I've not seen this error before.  

Can you please create an issue at <https://jira.atlassian.com> ?

Thanks


author: tcuvelier
body: Thank you for your support! Here is the issue: <https://jira.atlassian.com/browse/SRCTREEWIN-10824>


author: Duncan McIntyre
body: Hi [@tcuvelier](/t5/user/viewprofilepage/user-id/623319) or [@minnsey](/t5/user/viewprofilepage/user-id/502201), Has this issue been resolved? I started getting this error today and can't seem to find any solutions online.


author: Wayne Woods
body: I'm experiencing the same (or very similar) issue. Originally the error message blamed hgflow, but once I disabled that it blamed mercurial_credential_manager. I re-enabled hgflow and it still blames mercurial_credential_manager. Otherwise it's a very similar issue. I tried using the latest SourceTree embedded Mercurial (4.6.2) and the latest system one (4.7) and both give the same error:

> \*\* Unknown exception encountered with possibly-broken third-party extension mercurial_credential_manager  
> \*\* which supports versions unknown of Mercurial.  
> \*\* Please disable mercurial_credential_manager and try your action again.  
> \*\* If that fixes the bug please report it to <https://github.com/mminns/mercurial_credential_manager_for_windows>  
> \*\* Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:22:17) \[MSC v.1500 32 bit (Intel)\]  
> \*\* Mercurial Distributed SCM (version 4.6.2)  
> \*\* Extensions loaded: eol, strip, rebase, transplant, extdiff, fetch, mq, mercurial_credential_manager, hgflow, shelve  
>
> Traceback (most recent call last):  
> File "hg", line 41, in \<module\>  
> File "mercurial\\dispatch.pyc", line 90, in run  
> File "mercurial\\dispatch.pyc", line 210, in dispatch  
> File "mercurial\\dispatch.pyc", line 351, in _runcatch  
> File "mercurial\\dispatch.pyc", line 359, in _callcatch  
> File "mercurial\\scmutil.pyc", line 160, in callcatch  
> File "mercurial\\dispatch.pyc", line 341, in _runcatchfunc  
> File "mercurial\\dispatch.pyc", line 971, in _dispatch  
> File "mercurial\\dispatch.pyc", line 727, in runcommand  
> File "mercurial\\dispatch.pyc", line 979, in _runcommand  
> File "mercurial\\dispatch.pyc", line 968, in \<lambda\>  
> File "mercurial\\util.pyc", line 1553, in check  
> File "mercurial\\util.pyc", line 1553, in check  
> File "hgext\\mq.pyc", line 3599, in mqcommand  
> File "mercurial\\util.pyc", line 1553, in check  
> File "mercurial\\commands.pyc", line 4216, in push  
> File "mercurial\\exchange.pyc", line 528, in push  
> File "mercurial\\exchange.pyc", line 1107, in _pushbundle2  
> File "mercurial\\thirdparty\\concurrent\\futures\\_base.pyc", line 457, in result  
> File "mercurial\\wireprotov1peer.pyc", line 210, in sendcommands  
> File "mercurial\\wireprotov1peer.pyc", line 480, in unbundle  
> File "mercurial\\httppeer.pyc", line 532, in _calltwowaystream  
> File "mercurial\\httppeer.pyc", line 461, in _callstream  
> File "mercurial\\httppeer.pyc", line 311, in sendrequest  
> File "urllib2.pyc", line 435, in open  
> File "urllib2.pyc", line 548, in http_response  
> File "urllib2.pyc", line 467, in error  
> File "urllib2.pyc", line 407, in _call_chain  
> File "urllib2.pyc", line 909, in http_error_401  
> File "mercurial\\url.pyc", line 463, in http_error_auth_reqed  
> File "C:/Users/xxxx/AppData/Local/Atlassian/SourceTree/hg_extras/mercurial_credential_manager.py", line 437, in basic_http_error_auth_reqed  
> return basic_http_error_auth_reqed.orig(self, authreq, host, req, headers)  
> File "urllib2.pyc", line 887, in http_error_auth_reqed  
> File "mercurial\\url.pyc", line 467, in retry_http_basic_auth  
> File "C:/Users/xxxx/AppData/Local/Atlassian/SourceTree/hg_extras/mercurial_credential_manager.py", line 428, in find_user_password  
> return self._pwd_handler.find_auth(self, realm, authuri, req)  
> File "C:/Users/xxxx/AppData/Local/Atlassian/SourceTree/hg_extras/mercurial_credential_manager.py", line 259, in find_auth  
> if username\[0\]:  
> IndexError: list index out of range  
>
> <br />
>
> Completed with errors, see above.


author: Moshe Freund
body: I have the same issue


author: minnsey
body: Please upgrade to 3.0.12. The issues is with the removal of TLS 1/1.1 from Bitbucket.  

3.0.12 includes updates authentication components that support TLS 1.2  

<https://product-downloads.atlassian.com/software/sourcetree/windows/ga/SourceTreeSetup-3.0.12.exe>


Tags: mercurial

windows