From 1eb737244db7a40aeead9b3d61b758842844663f Mon Sep 17 00:00:00 2001 From: Luke Plaster Date: Tue, 23 Jan 2018 00:01:05 +0800 Subject: [PATCH] Applied tweaks from #38 --- src/ref.coffee | 6 +++--- test/index.test.coffee | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ref.coffee b/src/ref.coffee index e927004..8b750a2 100644 --- a/src/ref.coffee +++ b/src/ref.coffee @@ -38,7 +38,7 @@ exports.Head = class Head extends Ref Ref.find_all repo, "head", Head, callback @current: (repo, callback) -> - fs.readFile "#{repo.dot_git}/HEAD", (err, data) -> + fs.readFile "#{repo.dot_git}/HEAD", "utf8", (err, data) -> return callback err if err ref = /ref: refs\/heads\/([^\s]+)/.exec data @@ -46,7 +46,7 @@ exports.Head = class Head extends Ref return callback new Error "Current branch is not a valid branch." if !ref [m, branch] = ref - fs.readFile "#{repo.dot_git}/refs/heads/#{branch}", (err, id) -> - Commit.find repo, id, (err, commit) -> + fs.readFile "#{repo.dot_git}/refs/heads/#{branch}", "utf8", (err, id) -> + Commit.find repo, id.trim(), (err, commit) -> return callback err if err return callback null, (new Head branch, commit) diff --git a/test/index.test.coffee b/test/index.test.coffee index 541e4f7..c922bd0 100644 --- a/test/index.test.coffee +++ b/test/index.test.coffee @@ -1,7 +1,7 @@ should = require 'should' git = require '../src' Repo = require '../src/repo' -fs = require "fs" +fs = require "fs-extra" exec = require 'flex-exec' describe "git", -> @@ -23,7 +23,7 @@ describe "git", -> bare = repo.bare || false bare.should.be.false after (done) -> - exec "rm -rf #{newRepositoryDir}", done + fs.remove newRepositoryDir, done describe "init() bare", -> repo = null @@ -38,7 +38,7 @@ describe "git", -> bare = repo.bare || false bare.should.be.true after (done) -> - exec "rm -rf #{newRepositoryDir}", done + fs.remove newRepositoryDir, done describe "clone()", -> @timeout 30000 @@ -54,7 +54,7 @@ describe "git", -> remotes.should.have.length 1 done() after (done) -> - exec "rm -rf #{newRepositoryDir}", done + fs.remove newRepositoryDir, done describe "clone() with depth", -> @timeout 30000 @@ -70,7 +70,7 @@ describe "git", -> remotes.should.have.length 1 done() after (done) -> - exec "rm -rf #{newRepositoryDir}", done + fs.remove newRepositoryDir, done describe "clone() with depth and branch", -> @timeout 30000 @@ -85,4 +85,4 @@ describe "git", -> repo.branch "develop", (err, head) -> done err after (done) -> - exec "rm -rf #{newRepositoryDir}", done + fs.remove newRepositoryDir, done