Launch
closed
Rui Ferreira
git (6) code (4)
2014-03-12
2013-04-18
Alfredo Matos
No
1 up votes | 0 down votes | 100%
12 comments

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

git remote add origin http://alfmatos@opensourceprojects.eu/git/p/helloworld/code-0

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

Discussion

  • Rui Ferreira
    Rui Ferreira
    2013-04-18

    I see multiple push requests in the log for user alfmatos with NO password (for the hello world project).

     
    Last edit: Rui Ferreira 2013-04-18
    • Alfredo Matos
      Alfredo Matos
      2013-04-18

      Did i miss that in the sample steps?

      cd myproject
      git remote add origin http://alfmatos@opensourceprojects.eu/git/p/helloworld/code-0
      git push origin master
      git branch --set-upstream master origin/master # so 'git pull' will work later

      On which part do I need to add a password? Should it be added to the instructions?

       
  • Alfredo Matos
    Alfredo Matos
    2013-04-19

    More info: just checked out a github rw http account and git asked me for password... Not sure why it doesn't ask me for a pass here.

     
  • Rui Ferreira
    Rui Ferreira
    2013-04-19

    its most likely the HTTP code being returned by the authentication handler - git seems to be picky about 401 and 403.

     
  • Rui Ferreira
    Rui Ferreira
    2013-04-19

    Alfredo, can you try?

    export GIT_CURL_VERBOSE=1
    git push ...
    

    and post the output here

     
    • Alfredo Matos
      Alfredo Matos
      2013-04-26

      Added the output of a push (to a fake repo, 404's in the end, but everything else is ok).

      This prompted me for password and logged in successfully.

      (still seeing the attachment bug on posting comment replies with attachment. Editing the comment and re-adding the attachment worked.)

       
      Last edit: Alfredo Matos 2013-04-26
      Attachments
  • Rui Ferreira
    Rui Ferreira
    2013-04-26

    Alfredo, can you retry now? I've made some changes to the access handler.

     
    • Alfredo Matos
      Alfredo Matos
      2013-04-26

      It worked. Process was straightforward and prompted for a password.

      Now all we need to do, is add instructions to add .netrc users to automate the process ;)

       
  • Rui Ferreira
    Rui Ferreira
    2013-04-26

    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.

    ...?service=git-receive-pack
    

    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
    2013-05-08

    • status: open --> closed
    • assigned_to: Rui Ferreira