Tuesday, October 26, 2010

export files from git for sync using ftp upload

Well I had to do it.
I had to use GIT.
Everybody was using it and some recent forced contemplation at subversion merging made me finally give it a try. But I was reluctant. Partially because of the Linus speech at Google where he was bashing the Subversion guys, partly because of it's sheer difficulty. I really don't like any of those 2 factors. Not one bit. But the added value may surpass the second one. I won't say more about the first one.
So I adapted my export files from svn for sync using ftp upload for git.
Here it is:
# Exports GIT changed files to a chosen location

echo "Repository local path:"
read repositoryUrl
echo "Start commit:"
read startRevision
echo "End commit:"
read endRevision
echo "Export location:"
read exportLocation

cd $repositoryUrl
git diff $startRevision..$endRevision  --name-status | grep "^[AM].*\.\w\{2,4\}$" | awk '{print $2}' | sort -u | \
while read FN
        echo "exporting $FN ..."
        mkdir -p $exportLocation`dirname /$FN`
        git show $endRevision:$FN > $exportLocation/$FN
cd $currentFolder
Now this is really experimental. Use it only as an exercise for now.
Issues I have yet to fix and clear out:

  • I did not find a way to get the diff from the central origin/master. I am guessing that the commits are the same local and remote once you push/pull them (like svn commit) but I'm not 100% sure until I'll use this in a production scenario with lots of activity. The distributed nature of the sistem may give me some bad "aha" moments
  • diff with ".." seems to be so smart that it does not list stuff you added and also deleted before the last commit. Well that's how it looks...
  • I am not sure how diff works (there I said it) right now. I think and hope it'n not just diffing the 2 commits but also all the ones that happened between them. More experimenting should clear this out for me
If you have any hints on my issues please do comment. I'll probably come back here with the common "GIT rocks" post but I'm guessing that will take me a while. I am new to git and I still have a lot to figure out.

Sunday, October 17, 2010

export files from svn for sync using ftp upload

Well I finally got to write my first real shell script.
As always I wrote it because I found my self doing the same repetitive task again, for the thousand time.
In this particular situation it was the svn export of the files changed across several consecutive revisions with the purpose of updating a live site via FTP. I usually use the smarter way and have the production version as a svn checkout and update it using just svn up.
But sometimes that's not the best option. I know it's hard to believe but it can happen...
I am usually interacting with svn via Subclipse and despite all the complains I've found online I can only say that it works for me. But it doesn't provide this trick of exporting a bunch of files so I can ftp copy a folder onto another and update the darn site in a blink. Well a long blink but still I shouldn't have to individually select each file and press the copy button.
So I started digging. First I found a one liner that did a zip from the local changes with svn status. Well that's too bold for me. I like to commit my changes and then think that I have something to put live...
But that was a start. After I read some basics about bash my fears were confirmed. It was to be worse than when I had to code in perl :)
So probably the code can be tweaked and made look smarter. If so please comment. Although it feels archaic this style of coding definitely has some appeal.  Once you get it. And I haven't got it yet :D
An important note would be that I wrote it on OSX 10.5.8 Leopard. I first tried svn export but I got some errors from svn complaining that it cannot move it's tmp files to the target locations because the target is a directory. Which it was. Some people got it too and there was a fix involving a chmod but it did not work for me.
I also am using SSHKeychain because my svn path is in the form svn+ssh://user@IP/... so if you are not using svn over ssh you will not need SSHKeychain either.
The script asks for the repository root, start revision, end revision and the local path where to put the files. I get that info using Project properties - Subclipse.
So here's the trickster:

# Exports SVN changed files to a chosen location

echo "Please fire up your SSH Keychain!"
echo "Repository Root URL:"
read repositoryUrl
echo "Start revision:"
read startRevision
echo "End revision:"
read endRevision
echo "Export location:"
read exportLocation

svn log -r $startRevision:$endRevision -q -v $repositoryUrl | grep "^ *[AM].*\.\w\{2,4\}$" | awk '{print $2}' | sort -u | \
while read FN
        echo "exporting $FN..."
        mkdir -p $exportLocation`dirname $FN`
        svn cat -r $endRevision $repositoryUrl$FN > $exportLocation$FN

As stated above this is my first shell script. I hope it works just fine for you but until you really understand what it does I advise you to double check the exported data before using it to update a production environment. There are no warranties whatsoever.

Monday, October 11, 2010

Maker's Schedule, Manager's Schedule

Another great piece from Mr. Graham. Maker's Schedule, Manager's Schedule is about why meetings are so cheap for managers and yet so costly for their developers. All true as always.
I stumbled upon the piece while reading Achieving Flow in a Lean Startup by Ash Maurya. Another very interesting piece. On the same wave I picked up this presentation entitled A Disciplined Approach To Imagining, Designing, And Building New Products that's also well worth my time. Maybe yours too.
Well back to reading...