Working Copy integration sidebar
I recently stumbled on an app called Working Copy, which is a github client (though it also works with other services). It's a very well put together app, and to make things better, the beta currently out for testing with testflight supports x-callback-url. Since I know little to nothing about writing my own git client with authentication and all that, this makes things a ton easier, for the most part (more about that in a minute). In order to push to a remote repository you do have to upgrade the app ($1 for three weeks or $10 for forever). Note that charges do not apply to beta testers.
I've made a repo with a sidebar client I made which can add files on working copy, update them, commit single files or whole repositories, push, and pull to working copy. I hope to roll this into my personal copy of edit-menu, so I can switch back and forth between edit-menu, editing tabs, and git functions. I also hope to combine steps so I can add, commit, and push in a single step if desired for example.
Now for my problem. When trying to copy text stored in working copy file and update the corresponding file, I open an x-callback-url which should read the contents of the file stored in local copy, and send the right file location and text back as arguments to a second script (Update.py), which can then update the script contents. For some reason I am not getting sent back to pythonista with this code.
I also need to say that the developer of Working Copy has been very helpful. In the latest beta he updated the x-callback-url functionality at my request so that it would even be possible to get file contents back into pythonista. I have successfully gotten it to work when using a premade test URL. It just fails when this code puts it together for some reason. I can't tell what part of the URL is broken.
Sorry, I think it might be
I figured it out, but I don't have time to finish the code right now. I'll post it when it's done.
By the by, Smath, you may want to pull the latest editmenu if you haven't in a while. I recently updated everything as classes, which fixed some namespace conflicts and other issues when changing folders....
Okay. I just updated the repository, and while I still hope to make improvements, everything is working. Please read the updated instructions on the README before trying to use, or it won't work. Let me know if you still have any questions. Also feel free to improve or suggest how it could be better.
I understand this probably won't be the best thing for everyone, especially people who are used to using git via the command line. It's also not a great idea for large repositories, and in fact breaks down when there are sub-directories in the repository (something I need to fix). Hopefully once I get around to combining steps it will be better for that purpose. I just like the idea of having a git interface built into my pythonista workflow, and since I usually work in small repositories this should work just fine.
JonB - thanks for the suggestion. I'll make sure to get the most current version.
FYI, there is also gitview, which is a ui interface to git.
It still has a lot of work to go
I do like the idea of sidebar commands. I suspect working copy has the capability to handle merges, etc better.
I've noticed a problem with how I'm doing this. When I get text returned from working copy, what I get is a list of words. which I join with spaces. This totally kills my indentation. Any ideas how to fix this without looping through the whole list of words or string? If not I'lll probably give up on this and find some other way to simplify working with git. I may still use this to send stuff to git, but pullling code from git through working copy is turning out to be more complicated than I originally thought.
In the pythonista manual, it says
If you want to pass arguments that contain spaces, you have to enclose them in double quotes (as you would in a classic shell). %22 is an encoded double quote:
['/var/mobile/Applications/88D6E0F3-4BB7-4D36-8AD6-BAF532976A46/Documents/printargs.py', 'foo bar']
Your scripts would have to ensure that there are no
"s in you code. Use single quotes for strings, then you can replace any double quotes inside of strings with \x22.
If you ever need to quote single quotes, you could use triple single quoted strings instead of double quotes.
If you are only using ios, and don't need to share elsewhere, your pythonista code could add double quotes to the file that you check in, which thus ensures that when you get it back from working copy, the quotes get stripped off automatically. Alternatively, you will need the workingcopy author to add the option to surround the encoded code with %22s.
The other options you've got, I think, are:
You could use git from stash, which has been functionalized compared to the pythonista versions. So you could call those from a sidebar.
You could also use gitview, which right now has some additional features, like the ability to checkout old sha's. Once you create the gitui object, you can set the repo programatically, then all the commands should be callable from the gitui object. I have a lot of cleanup and organization to do in that class, but I don't see any real barrier to sidebar integration. Do you have a use css for what git commands you want implemented via sidebars?
Correction: you want to use argv rather than args. Argv does not require quoting.
Okay, I got this working, however, I have been rethinking how good of a path this is. I didn't realize that git had been included in stash. That might be a good route. Is there any reason that it wouldn't work with bitbucket? I know that I can use the same command line commands with bitbucket as github on desktop, but I'm having trouble cloning a bitbucket url with it.
Be sure to include the full extension. Do you have an example url you are cloning?
ok, I reproduced this problem. I suspect it has to do with the authentication method used. Technically I don't see a reason dulwich wouldn't support bitbucket..
The new release of
Working Copyadds x-callback-url commands.
Just so you know, PMB1999 on github submitted an update for that app on 2/28 that should improve functionality substantially from what I had, so make sure you have the current version. I had arranged with the working copy developer to allow sending encoded zip files back to pythonista to allow whole folders to be synced at once, and I believe PMB1999 implemented that along with other improvements. I haven't been able to use it much yet, so I'm not sure of all the changes.
The other option for dealing with the close button is that I could just have all of the buttons moved down. Then no work around will be needed. I'm not sure if that will impact any iPhone users.
By the way, check out my pull request on Github. I think I improved the script a little by removing the need for the user to configure INSTALL_PATH.
v1.8 of Working Copywas released yesterday and it seems to have great new features. I use it to fiddle with GitHub repos but I do not really know how use it to do heavy work between Pythonista and Working Copy and a GitHub repo.
Could someone please document some best practices for
how to use Pythonista and Working Copy together?
A walk-through of the following steps would be a huge help to me:
- Use Working Copy fork an existing repo from GitHub
- Move one (or all) of the Python files from that local copy into Pythonista
- Make a change in one of those Python files
- Move the modified file from Pythonista back into Working Copy
- Push the change into the GitHub repo
5a. A repo to which I have commit rights 5b. As a "pull request" to a repo to which I do NOT have commit rights
Steps 2, 4, and 5b are the ones that I have difficulty with and I am sure that my current approach is suboptimal ;-).
I'm a big fan of Working Copy (but only just getting started with Pythonista), having a full-featured Git client on iOS is wonderful I think, so I was delighted to discover this script.
@ccc I'm still relatively new to Pythonista, but I've used Working Copy quite a bit for other projects, so I can answer some of these.
- Cloning from GitHub is very easy. The main URL of the GitHub repository you want to clone can act as an alias for the Git clone URL. Copy the URL from the safari address bar (the "copy" command in the action menu will do this), open Working Copy, navigate to the root if you aren't already there, hit "+" clone, it should detect that you have a GitHub URL in the clipboard, and a blue notification appears asking if you want to clone from that URL, tap the notification, then tap clone.
for 2-5, I would use the buttons in this script. You can save the script to the Pythonista action menu, so that it is always easily within reach.
@smath I just submitted a pull request to your repo, just a couple of small changes. When I push/upload, the operation works, but when it switches back to Pythonista, a notification pops up saying that I have no such file in my library.
I have forked the wc_sync repo and made some updates to it to work with the Pythonista 2.0 beta. The sidebar view has not worked in the beta for a while now and some other changes have been made that made the original code unusable.
PS @Utsira - Working copy sends back the name of the updated file in the x-callback-url, so in turn Pythonista tries to open said file, which it thinks is in the root directory, since WC does not send back the repo name. I have accounted for this in my updates below.
@ahenry91 slight issue with the UI it doesn't appear to be responsive on my iPhone it is cut off slightly still usable though.
If you are happy to accept a pull request I might try and fix it tonight if someone doesn't beat me to it.
@shaun-h sorry, I beat you to the iPhone interface. If you would like to create a better interface, I'd be happy to accept the pull request.
Were the ideas in these two pull requests incorporated into the current code? https://github.com/pysmath/wc_sync/pulls