Browse files

wrote some tests for direct ref creation.

  • Loading branch information...
1 parent 45dba8c commit 41aa465b3a026f0ee1b007984f119b4a7d374b3c @samcday samcday committed Jun 3, 2012
Showing with 35 additions and 1 deletion.
  1. +13 −1 coffee/gitteh.coffee
  2. +2 −0 test/fixtures.coffee
  3. +20 −0 test/test.reference.coffee
View
14 coffee/gitteh.coffee
@@ -284,11 +284,23 @@ Repository.prototype.reference = ->
_priv = getPrivate @
[name, resolve, cb] = args
name: type: "string"
- resolve: type: "bool"
+ resolve: type: "bool", default: false
cb: type: "function"
_priv.native.reference name, resolve, wrapCallback cb, (ref) =>
cb null, new Reference @, ref
Repository.prototype.ref = Repository.prototype.reference
+Repository.prototype.createReference = ->
+ _priv = getPrivate @
+ [name, target, force, cb] = args
+ name: type: "string"
+ target: type: "string"
+ force: type: "bool", default: false
+ cb: type: "function"
+ fn = "createSymReference"
+ if target.length is 40 and oidRegex.test target
+ fn = "createOidReference"
+ _priv.native[fn] name, target, force, wrapCallback cb, (ref) =>
+ cb null, new Reference @, ref
Repository.prototype.remote = ->
_priv = getPrivate @
[name, cb] = args
View
2 test/fixtures.coffee
@@ -4,6 +4,8 @@ exports.projectRepo =
path: path.join __dirname, "../"
gitPath: path.join __dirname, "..", ".git/"
+ firstCommit:
+ id: "1f4425ce2a14f21b96b9c8dde5bcfd3733467b14"
secondCommit:
id: "8a916d5fbce49f5780668a1ee780e0ef2e89360f"
tree: "aa41780f2129bf03cce1a3eeadc78db47f83d9ad"
View
20 test/test.reference.coffee
@@ -5,6 +5,8 @@ gitteh = require "../lib/gitteh"
utils = require "./utils"
fixtures = require "./fixtures"
+{secondCommit} = fixtures.projectRepo
+
describe "Reference", ->
repo = null
ref = null
@@ -43,3 +45,21 @@ describe "Reference", ->
repo.ref "HEAD", true, (err, ref) ->
should.not.exist err
ref.name.should.equal headFile
+ describe "Creating a direct reference to second commit", ->
+ newRef = null
+ after (cb) ->
+ fs.unlink path.join(repo.path, "refs", "heads", "testref"), cb
+ it "works", (done) ->
+ repo.createReference "refs/heads/testref", secondCommit.id, (err, _ref) ->
+ newRef = _ref
+ should.not.exist err
+ newRef.should.be.an.instanceof gitteh.Reference
+ done()
+ it "should have correct data", ->
+ newRef.name.should.equal "refs/heads/testref"
+ newRef.target.should.equal secondCommit.id
+ it "should fail when trying to create ref with same name again", (done) ->
+ repo.createReference "refs/heads/testref", secondCommit.id, (err, _ref) ->
+ should.exist err
+ err.should.be.an.instanceof Error
+ done()

0 comments on commit 41aa465

Please sign in to comment.