GitPython
GitPython copied to clipboard
git.remote.Remote.set_url does not update self.url
Python 3.10.1 (main, Dec 12 2021, 12:17:52) [GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import git
>>> git.__version__
'3.1.27'
>>> repo = git.Repo.init(".")
>>> remote = repo.create_remote("name", "url")
>>> remote.set_url("newurl", old_url=remote.url)
<git.Remote "name">
>>> remote.url
'url'
>>> repo.remote(remote.name).url
'newurl'
It's also a bit unexpected that Remote.__eq__ does not consider url:
>>> remote == repo.remote(remote.name)
True
Thanks a lot for letting me know. Help with the fix would definitely be appreciated.
I played around a bit with this bug, and it's trickier than I first thought.
repo = git.Repo.init('.')
remote = repo.create_remote('name', 'url')
print(f'Remote url before set_url: {remote.url}')
remote.set_url('newurl', old_url='url')
print(f'Remote url after set_url: {remote.url}')
prints
Remote url before set_url: url
Remote url after set_url: url
but
repo = git.Repo.init('.')
remote = repo.create_remote('name', 'url')
remote.set_url('newurl', old_url='url')
print(f'Remote url after set_url without an earlier call: {remote.url}')
prints
Remote url after set_url without an earlier call: newurl
This is probably related to the caching of the _config_reader output, but I haven't dug into that yet. In debugging the calls, I also noticed that the Remote.url parameter is never actually given a value, and all access to it is only through the __getattr__ interface.