Rui Ferreira
git (6) code (4)
Alfredo Matos
1 up votes | 0 down votes | 100%

Followed the steps for adding code to the git repository failed, on new project entitled Hello World.

git remote add origin

Cannot push:

git push origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 292 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
error: RPC failed; result=22, HTTP code = 401
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly


<< < 1 2 (Page 2 of 2)
  • Rui Ferreira
    Rui Ferreira

    Some more bits on the technical side, about this:

    When git makes its request via HTTP, distinguising READ from WRITE operations is done using a regexp similar to the following

    "^/git/.*/git-receive-pack$" # man git-http-backend

    Where the previous example would be a write operation (e.g. push) and all others would be read.

    But since individual git commands don't execute one single HTTP request but several, for the same push command some operations will be READ operations while others will be WRITE operations.

    This means that the access handler will treat the initial stages of a git-push as regular READ operations (because that is what they are), and only requiring authentication later (when a path matching the regexp appears). This is made slightly harder to detect because Git likes to start the process without authenticating.

    Git 1.8 has no problem dealling with this, it will prompt for the password when its needed. However it seems that Git 1.7 assumes that since it was already able to perform some operation, it will be able to do so again - i.e. the READ succeeded so the WRITE should do as well.

    It turns out that Git itself provides a solution for this (but i have not seen this document on its manpage) - Git requests identify the intended service as a query string parameter, e.g.


    would mean a push, even if that specific HTTP request is only reading the references.

    Basically I added one extra check for the query string to the access handler. So far this seems to be working with both 1.8 and 1.7 and I have not seen any regressions so far.

  • João Paulo Barraca
    João Paulo Barraca

    • status: open --> closed
    • assigned_to: Rui Ferreira
<< < 1 2 (Page 2 of 2)