libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.58k stars 382 forks source link

"this operation is only valid for push" #1188

Open trivee opened 1 year ago

trivee commented 1 year ago

The sequence of calls

remote.ls_remotes(...) remote.fetch(...) remote.push(...)

works, while

remote.ls_remotes(...) remote.push(...)

doesn't, producing the GIT_ERROR_NET / "this operation is only valid for push" error.

I think this is because ls_remotes() explicitly calls connect(..., GIT_DIRECTION_FETCH), and fetch() implicitly calls disconnect() (within git_remote_fetch()). If fetch() is not called between ls_remotes() and push(), git_remote_push() encounters an existing connection with FETCH direction, and returns an error (from git_smart__get_push_stream()).

This could be addressed in several ways: either by disconnecting explicitly in ls_remotes(), or maybe by changing the implementation of connect_or_reset_options() and the functions it calls to handle the case where direction is changing.

krautcat commented 2 months ago

The same issue here without calling ls-remotes, just push to origin remote after cloning repository.