Skip to content
Browse files

example works

  • Loading branch information...
1 parent 1f9d16e commit a1457a28a1d1a46543b92c6482f20ae3d10f8983 @substack substack committed Nov 19, 2011
Showing with 56 additions and 9 deletions.
  1. +51 −6 README.markdown
  2. +5 −3 example/reject.js
View
57 README.markdown
@@ -1,17 +1,62 @@
git-emit
========
-Expose git hooks as a single node.js EventEmitter.
-
-COMING SOON.
+Expose git hooks through an EventEmitter.
example
=======
+reject.js
+---------
+
``` js
-var em = require('git-emit')(__dirname + '/repo');
+// randomly reject 50% of commits
+var em = require('git-emit')(__dirname + '/repo.git');
-em.on('pre-commit', function (ok) {
- ok(Math.random() > 0.5); // randomly reject 50% of commits
+em.on('update', function (update) {
+ if (Math.random() > 0.5) update.reject()
+ else update.accept()
});
```
+
+Now we can create a new bare repo and run reject.js to listen for commits:
+
+```
+$ git init --bare repo.git
+Initialized empty Git repository in /home/substack/projects/node-git-emit/example/repo.git/
+$ node reject.js
+```
+
+The first time, our commit is rejected:
+
+```
+$ git push ~/projects/node-git-emit/example/repo.git master
+Counting objects: 43, done.
+Delta compression using up to 2 threads.
+Compressing objects: 100% (36/36), done.
+Writing objects: 100% (43/43), 6.15 KiB, done.
+Total 43 (delta 18), reused 0 (delta 0)
+Unpacking objects: 100% (43/43), done.
+remote: error: hook declined to update refs/heads/master
+To example/repo.git
+ ! [remote rejected] master -> master (hook declined)
+error: failed to push some refs to 'example/repo.git'
+```
+but the second time, the commit goes through!
+
+```
+$ git push ~/projects/node-git-emit/example/repo.git master
+Counting objects: 43, done.
+Delta compression using up to 2 threads.
+Compressing objects: 100% (36/36), done.
+Writing objects: 100% (43/43), 6.15 KiB, done.
+Total 43 (delta 18), reused 0 (delta 0)
+Unpacking objects: 100% (43/43), done.
+To example/repo.git
+ * [new branch] master -> master
+```
+
+It works as expected hooray!
+
+methods
+=======
View
8 example/reject.js
@@ -1,5 +1,7 @@
-var em = require('git-emit')(__dirname + '/repo');
+// randomly reject 50% of commits
+var em = require('../')(__dirname + '/repo.git');
-em.on('pre-commit', function (ok) {
- ok(Math.random() > 0.5); // randomly reject 50% of commits
+em.on('update', function (update) {
+ if (Math.random() > 0.5) update.reject()
+ else update.accept()
});

0 comments on commit a1457a2

Please sign in to comment.
Something went wrong with that request. Please try again.