Out of band syncing to a local git branch.
This started as an experiment to see how commits could be created without
modifying the working directory, the index, or the state of HEAD. The end
result is like a cross between rsync
and git stash
using a specified
branch.
This allows you to deploy your current working directory:
- without polluting your master branch with build artifacts
- without modifying your current checkout at all:
- no branch switching
- no index clobbering
- no complaining about clobbering unstaged changes
Here's how you would use it to push your current working directory to a git push based hosting provider (like Heroku):
$ git-snapshot production
Creating branch 'production' if it doesn't exist...
Creating index... (this can take a while)
Creating tree from index...
Created tree 1e035b51027ba785c74155025cd616bbd20d8d17
Creating commit...
Created commit f2527eb28622d7a17403f723d36584027e595723
$ git push hosting production:master
In order of appearance:
- http://git-scm.com/docs/git-branch
- http://git-scm.com/docs/git-rev-parse
- http://git-scm.com/docs/git-ls-files
- http://git-scm.com/docs/git-hash-object
- http://git-scm.com/docs/git-update-index
- http://git-scm.com/docs/git-write-tree
- http://git-scm.com/docs/git-commit-tree
- http://git-scm.com/docs/git-update-ref
- Option to create tag instead of branch
- Specify commit message
- Don't do empty commits, it means the branch is already up to date
- Find portable replacement for
stat
Sorry, you are clearly not compelled by the git support in slc build, but I'm not really seeing why.
The entire build process (npm install etc) in your gist modifies the working copy and leaves the atifacts there, I don't see the difference.
"without modifying your current checkout at all":
Except all the build products?
And possibly a modified package.json file and a new .npmignore file (if you use --bundle).
I do that deliberately on https://github.com/strongloop/strong-build/blob/master/lib/git.js#L90 with an explicit
git checkout deploy
, because without it you can't run "slc deploy", not doing so seems an anti-feature, and see below.You use a different index file, allowing the working copy to have a partially constructed index. Seems pretty questionable practice, do you generally do deployment builds with partically constructed indexes?
Still, robustness is important, and adding a custom GIT_INDEX_FILE to slc build would make it more robust, and work better if it is called during a commit (though libuv/node's lack of a cross-platform mkstemp makes that surprisingly hard, probably I'd need a binary dep). I could do that, it doesn't involve the wholesale rewrite you have above.
In summary, the main difference I can see between my command and yours above (other than it is an OS X specific shell script :-), stat doesn't work like that on linux) is:
I could do that, too, its easy, but it means you can't run slc deploy anymore.
Actually, its MUCH worse than that, you can in fact run slc deploy, and probably will, as Chandrika did in her walk-through, but you will be running it on the WRONG branch, which will give every appearance of success.... except that you will push an un-built branch, and npm install will download every dependency on the server, meaning you used slc build, but got zero value from it. Ouch.
I said why I don't like this, you haven't said why forcing this is a good idea. I could add it.
You are clearly not compelled by slc build, and I'd like you, or at least people like you, to be compelled, but so far all I really see is you don't like that it leaves you on the deploy branch and doesn't use its own index (latter easily fixed), and yours is less flexible and can't have its pieces composed into an existing build process.