Skip to content

Instantly share code, notes, and snippets.

@ccgus
Created February 7, 2012 22:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccgus/1762511 to your computer and use it in GitHub Desktop.
Save ccgus/1762511 to your computer and use it in GitHub Desktop.
Auto-gitify
function runGitWithArgsForDocument(document, args) {
task = NSTask.alloc().init().autorelease();
task.setCurrentDirectoryPath(document.fileURL().path());
task.setLaunchPath('/usr/bin/git');
task.setArguments(args);
task.launch();
task.waitUntilExit();
}
function documentWasOpened(document) {
var docURL = document.fileURL();
var gitURL = docURL.URLByAppendingPathComponent_('.git');
var fm = NSFileManager.defaultManager();
if (!fm.fileExistsAtPath_(gitURL.path())) {
print("Making the git repository");
runGitWithArgsForDocument(document, ['init']);
runGitWithArgsForDocument(document, ['add', 'pages', 'properties.plist', 'storeinfo.plist']);
runGitWithArgsForDocument(document, ['commit', '-m', 'First Commit']);
}
}
function documentWillClose(document) {
// adding pages again will just add any new pages that didn't already exist.
runGitWithArgsForDocument(document, ['add', 'pages']);
runGitWithArgsForDocument(document, ['commit', '-a', '-m', 'document close']);
}
function documentWasClosed(documentPath) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment