omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    git / github workflow in stash

    Pythonista
    8
    29
    22942
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • dcl
      dcl last edited by

      Has any progress been made with interfacing StaSh with Bitbucket? I am trying to share a project between my iPad and iPhone on Pythonista and I would like to use Bitbucket + StaSh to do revision control and be able to push from one device and pull from another. Bitbucket (as mentioned above) allows me to keep the project private without paying monthly for the service, and as this is a non-revenue project I do not wish to pay for monthly hosting.
      I have found, however, that StaSh isn't playing nicely with Bitbucket at the moment. Any advice?

      I tried the command:
      git clone https://myusername@bitbucket.org/myusername/myproj.git localFolder

      And got the error:
      class 'dulwich.errors.GitProtocolError'>: unexpected http response 401

      1 Reply Last reply Reply Quote 0
      • dcl
        dcl last edited by dcl

        Figured out the 401 error. It is complaining about credentials.

        I created a new local repo on my iPad and tried to push it to an empty repo on Bitbucket. I added a remote for the Bitbucket repo using:

        git remote [name] [URL] 
        

        And then tried to push using:

        Git push [name] 
        Username: [user]
        Password: [pass]
        

        But I got the same error as above

        class 'dulwich.errors.GitProtocolError'>: unexpected http response 401
        

        Is there some reason that StaSh can't talk to Bitbucket? Can I use SSH keys? If so, how so I do that?

        Also, in the process I added a bad remote to my repo on the iPad. Is there some StaSh command to remove a remote? The help doesn't list one. I suppose I could dig through the source to find how it added one and reverse that... if I had to.


        EDIT:

        Trashed the repo on the iPad because there is no way to remove remotes.

        Went back to Bitbucket and turned the repo off of "Private"

        Then I went back to Pythonista -> StaSh window and tried clone repo again using:

        git clone [URL]  
        

        And successfully got the repo to clone on my iPad
        I then added some files to the repo from the iPad by moving files from another folder in Pythonista and then added to the repo using:

        git add *
        git commit
        Commit Message: [message]
        Author Name: [name]
        Save [y/n]y
        Author Email: [email]
        Save [y/n]y
        

        This worked okay too, but then when I tried to push back to the repo using:

        git push
        Username: [user]
        Password: [pass]
        

        I ALWAYS get the same error from before:

        class 'dulwich.errors.GitProtocolError'>: unexpected http response 401
        

        And I am certain my credentials are correct for the repo (I have logged into and out of it on the website many times today to verify this). I have tried using my email instead of username. Nothing I try works to allow me to push back to the Bitbucket repo.

        Would it be possible for someone to try this and let me know what I am doing wrong, or add Bitbucket capability to dulwich if necessary? Thanks!!

        1 Reply Last reply Reply Quote 0
        • khilnani
          khilnani last edited by

          I get the same issue with github.com private repos. I cloned a private repo, pull changes, edited a file locally, comit and tried to push. The push fails with 401.

          Its able to clone and pull from a private repo, but cant push.

          Is anyone able to use stash git with private repos? Wondering if its only a few of us having issues.

          JonB 1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by

            Have you tried Working Copy? https://workingcopyapp.com

            khilnani 1 Reply Last reply Reply Quote 0
            • JonB
              JonB @khilnani last edited by

              @khilnani
              It occurs to me that when we add the use/pass to the repo for push, we might not be honorng an existing password, thus end up with something like
              https://user:pass@user:pass@github.com.....

              Can you try creating a new remote which points to the bare url without any buser/pass info? (i.e https://github.com/owner/repo.git), then push to that url?

              1 Reply Last reply Reply Quote 0
              • JonB
                JonB last edited by

                also, i should add that ssh might be better for private repos in general. you iust have to set up the keys and then it just works.

                khilnani 1 Reply Last reply Reply Quote 0
                • khilnani
                  khilnani @ccc last edited by

                  @ccc said:

                  Have you tried Working Copy? https://workingcopyapp.com

                  I already have that but wanted to find something inside pythonista since i have projects with many files to open in app back and forth :(

                  Good suggestion tho.

                  1 Reply Last reply Reply Quote 0
                  • khilnani
                    khilnani @JonB last edited by

                    @JonB said:

                    also, i should add that ssh might be better for private repos in general. you iust have to set up the keys and then it just works.

                    Hmmm.. For some reason i didnt try ssh when i use that everywhere else. I guess, i assumed it wouldnt work since Pythonista is an 'app'.

                    I did try your other suggestion and that didnt work. Seems like on ssh keys work with git@ urls and not https at all.

                    Might send a PR to https://github.com/jsbain/stash_git_tutorial/blob/master/stash_git_tutorial.md ... Noticed it mentions ssh in an upcoming update :)

                    Thanks for helping!!! @JonB

                    1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB last edited by

                      did ssh work for you?
                      Here is the section of an updated git tutorial (though i can't push it because I am in the midst of removing the gittle dependencies in stash git, so dont have a fully working git)

                      Setting up ssh keys

                      In some cases, you may need or want to use ssh instead of https. This is a somewhat more reliable way of pushing, though it can be a little slower. This might also work for private repos.

                      With guthub, the process is facilitated by the gh command in stash:

                      [git_tutorial]$ gh create_key stash 
                      

                      creates a key, and adds it to your github account. Note this command uses the stored github password, so you will have to create a key in your keychain, or better yet just use git push on an existing repo.

                      If you are using a non-github ssh, bitbucket, etc, you can create an ssh key

                      $ ssh-keygen -trsa -b2048
                      pbcopy ~/.ssh/id_rsa.pub 
                      

                      creates a key, and copies the public key to the clipboard. You can then paste this into whatever you use for setting up the keys on the server.

                      Next, we need to add a remote to an existing repo:

                      [git_tutorial]$ git remote originssh ssh://git@github.com/jsbain/stash_git_tutorial.git
                      

                      Now you can fetch/push,etc from originssh

                      [git_tutorial] git push originssh
                      1 Reply Last reply Reply Quote 0
                      • khilnani
                        khilnani last edited by

                        @JonB ssh keys worked after setting up in pythonista and github. Thanks!

                        Am still working through a few scenarios:
                        1 - moving files. Noticed there is no git mv command.
                        2 - adding directories with sub directories. Seems like need to add complete relative path of the files in each directory (* works) while in the main dir with .git
                        3 - files deleted without git rm. eg. deleting from pythonista GUI. git status, git pull etc. all fail with a IO exception
                        4 - Files deleted remotely - after a git pull, any file deleted remotely is auto staged to be added instead of being removed locally

                        1 Reply Last reply Reply Quote 0
                        • JonB
                          JonB last edited by

                          yes, removing files is probably not handled well... how does git handle rm without git rm?

                          i actually recommend against git pull in most cases, it will happily onliterate any local changes. i tend to use git fetch followed by git merge, which at least tries to do sane things (though is not exactly like the real git merge). iirc git reset can be helpful when files get deleted without git rm.

                          I am in the process of removing gittle dependencies, and will then be able to use the most recent dulwich. Some improvements have already been made to dulwich.porcelain, and this would let us make pull requests to dulwich...

                          khilnani 1 Reply Last reply Reply Quote 0
                          • khilnani
                            khilnani @JonB last edited by

                            @JonB said:

                            yes, removing files is probably not handled well... how does git handle rm without git rm?

                            from what ive seen, it treats them as if git rm was called and auto stages the removes

                            i actually recommend against git pull in most cases, it will happily onliterate any local changes. i tend to use git fetch followed by git merge, which at least tries to do sane things (though is not exactly like the real git merge). iirc git reset can be helpful when files get deleted without git rm.

                            git fetch OR git fetch origin OR even fit fetch git@gihub... gives an error -

                            stash: <type 'exceptions.Exception'>: url must match a remote name, or must start with http:// or https://
                            

                            i tried git reset after manually deleting a file. didnt seem to help. Still get

                            stash: <type 'exceptions.OSError'>: [Errno 2] No such file or directory: '/private/var/mobile/Containers/Shared/AppGroup/A90BB332.......ACD7F/Pythonista3/Documents/pythonista-scripts/test'
                            

                            I am in the process of removing gittle dependencies, and will then be able to use the most recent dulwich. Some improvements have already been made to dulwich.porcelain, and this would let us make pull requests to dulwich...

                            cool !!!!

                            Thanks so much for helping out!!!

                            1 Reply Last reply Reply Quote 0
                            • mikael
                              mikael last edited by

                              Tried gh create_key stash, which failed because it could not import jwt. Tried pip installing jwt, which partially failed installing dependency typing. Trying the original command again, which failed with syntax error in jwk.py (which makes sense if it depends on typing).

                              This with latest vanilla version of Pythonista 3 and an updated version of stash.

                              1 Reply Last reply Reply Quote 0
                              • JonB
                                JonB last edited by

                                hmm, @mikael, can you post the traceback? I don't have jwt installed, must be a module collision somewhere

                                mikael 1 Reply Last reply Reply Quote 0
                                • mikael
                                  mikael @JonB last edited by

                                  @JonB, not sure how to get a traceback. Here's what happens:

                                  gh create_key stash
                                  no github found in /private/var/mobile/Containers/Shared/AppGroup/447A26CB-FA57-4E8A-8C34-082F55AD274F/Pythonista3/Documents/site-packages/stash/lib
                                  Installing pygithub master ...
                                  Opening: https://github.com/pygithub/pygithub/archive/master.zip
                                  Save as: /private/var/mobile/Containers/Data/Application/33F31BE9-F7A7-4092-8AFE-9E3C77723213/tmp//pygithub.zip 
                                     3168996
                                  Done
                                  stash: <type 'exceptions.ImportError'>: No module named jwt
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • JonB
                                    JonB last edited by

                                    stashconf py_traceback 1

                                    then run the command

                                    1 Reply Last reply Reply Quote 0
                                    • mikael
                                      mikael last edited by

                                      Thanks. As I started stash to do this, I got a tip with that exact same line for enabling tracebacks. Funny - or scary, depending on how you see the world.

                                      Here's the trace:

                                      Traceback (most recent call last):
                                        File "/private/var/mobile/Containers/Shared/AppGroup/447A26CB-FA57-4E8A-8C34-082F55AD274F/Pythonista3/Documents/site-packages/stash/system/shruntime.py", line 498, in exec_py_file
                                          exec code in namespace, namespace
                                        File "site-packages/stash/bin/gh.py", line 44, in <module>
                                          import github
                                        File "/private/var/mobile/Containers/Shared/AppGroup/447A26CB-FA57-4E8A-8C34-082F55AD274F/Pythonista3/Documents/site-packages/stash/lib/github/__init__.py", line 37, in <module>
                                          from MainClass import Github, GithubIntegration
                                        File "/private/var/mobile/Containers/Shared/AppGroup/447A26CB-FA57-4E8A-8C34-082F55AD274F/Pythonista3/Documents/site-packages/stash/lib/github/MainClass.py", line 34, in <module>
                                          import jwt
                                      ImportError: No module named jwt
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • JonB
                                        JonB last edited by

                                        Hmm, okay, pygithub now depends on pyjwt. It used to be dependency free, so could just install it directly.

                                        pip install pyjwt
                                        

                                        should fix the issue, though i will have to update gh to maybe use pip to install pygithub (or install a specific version).

                                        mikael 1 Reply Last reply Reply Quote 1
                                        • mikael
                                          mikael @JonB last edited by

                                          @JonB, thanks, installing pyjwt - not jwt - fixed the issue.

                                          1 Reply Last reply Reply Quote 0
                                          • JonB
                                            JonB last edited by

                                            Does gh actually work for you? I note that jwt requires cryptography for certain algorithms, you can be forced to use pycrypto/ecsda instead. Just curious if anything we are using requires that.

                                            mikael 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors