Today I was writing a little app that helps me keep up with my Todo list, since I wanted to have a web interface for some reporting into my tasks.
The issue is that my todo list is just a text file (and before you go saying there are various apps, I am happy with my text file ok? for various reasons which are not part of this post), so I built a nice web interface to it, but the problem is that since I can modify it, and whilst I was developing it I wanted a way to back this file up. I mean, whist I am coding this app, I might make mistakes and want to roll back.
So I got thinking of a way to do this and realised I do this every day anyway, using git!. So, I thought, for every change I do to the file, why not check it into its repository.
I fiddled about with cfexecute, which to be honest I haven't used much previously but I couldn't change the working directory, so, thanks to Tim Blair's post I managed to do the following:
<!--- since we have made modifications to the files, we need to commit them in git --->
<cfscript>
// first of we set the command to call
cmd1 = "git add TODO.txt";
cmd2 = "git commit -m 'autobackup'";
// the environment variable is empty
envp = arraynew(1);
// and we want to run from a given "root"
path = "/Volumes/iDisk/Documents/TODO";
dir = createobject("java", "java.io.File").init(path);
// get the java runtime object
rt = createobject("java", "java.lang.Runtime").getRuntime();
// and make the exec call to run the command
rt.exec(cmd1, envp, dir);
rt.exec(cmd2, envp, dir);
</cfscript>
And that's it. Every time the file is changed, it is added to my git repo locally. Handy!
Tweet
comments powered by Disqus