1
0
mirror of https://github.com/danog/gift.git synced 2024-11-30 04:19:37 +01:00

Merge pull request #20 from Lance0312/pr

Support gpgsig parsing and some extra fixes
This commit is contained in:
Luke Plaster 2014-06-06 14:53:15 +02:00
commit 5fcea7fbbd
14 changed files with 47 additions and 7 deletions

View File

@ -3,7 +3,7 @@ Actor = require './actor'
Tree = require './tree'
module.exports = class Commit
constructor: (@repo, @id, parents, tree, @author, @authored_date, @committer, @committed_date, @message) ->
constructor: (@repo, @id, parents, tree, @author, @authored_date, @committer, @committed_date, @gpgsig, @message) ->
# Public: Get the commit's Tree.
#
# Returns Tree.
@ -71,17 +71,20 @@ module.exports = class Commit
parents.push _.last lines.shift().split(" ")
author_line = lines.shift()
if !/^committer /.test(lines[0])
author_line.push lines.shift()
[author, authored_date] = @actor author_line
committer_line = lines.shift()
if lines[0] && !/^encoding/.test(lines[0])
committer_line.push lines.shift()
[committer, committed_date] = @actor committer_line
gpgsig = []
if /^gpgsig/.test lines[0]
gpgsig.push lines.shift().replace /^gpgsig /, ''
while !/^ -----END PGP SIGNATURE-----$/.test lines[0]
gpgsig.push lines.shift()
gpgsig.push lines.shift()
# not doing anything with this yet, but it's sometimes there
if /^encoding/.test lines.first
if /^encoding/.test lines[0]
encoding = _.last lines.shift().split(" ")
lines.shift()
@ -93,7 +96,7 @@ module.exports = class Commit
while lines[0]? && !lines[0].length
lines.shift()
commits.push new Commit(repo, id, parents, tree, author, authored_date, committer, committed_date, message_lines.join("\n"))
commits.push new Commit(repo, id, parents, tree, author, authored_date, committer, committed_date, gpgsig.join("\n"), message_lines.join("\n"))
return commits

View File

@ -5,6 +5,7 @@ dir = "#{__dirname}/fixtures"
module.exports =
branched: git("#{dir}/branched", true)
checkout: git("#{dir}/checkout", true)
gpgsigned: git("#{dir}/gpgsigned", true)
remotes: git("#{dir}/remotes", true)
simple: git("#{dir}/simple", true)
status: git("#{dir}/status", true)

1
test/fixtures/gpgsigned/HEAD vendored Normal file
View File

@ -0,0 +1 @@
ref: refs/heads/master

4
test/fixtures/gpgsigned/config vendored Normal file
View File

@ -0,0 +1,4 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true

1
test/fixtures/gpgsigned/description vendored Normal file
View File

@ -0,0 +1 @@
Fixture for testing gift with gpg signed commits

View File

@ -0,0 +1 @@
ec2c2e08e7dd8ce60d863c5bbd9563db03487d35

View File

@ -248,6 +248,35 @@ describe "Repo", ->
it "returns 2 commits", ->
commits[0].message.should.include "commit 4"
describe "with or without gpg signature", ->
repo = fixtures.gpgsigned
commits = null
before (done) ->
repo.commits "master", (err, _commits) ->
commits = _commits
done err
it "has no gpgsig", ->
commits[0].gpgsig.should.not.be.ok
it "has gpgsig", ->
commits[1].gpgsig.should.be.ok
it "contains the correct signature", ->
commits[1].gpgsig.should.equal """
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
iQEcBAABAgAGBQJTQw8qAAoJEL0/h9tqDFPiP3UH/RwxUS90+6DEkThcKMmV9H4K
dr+D0H0z2ViMq3AHSmCydv5dWr3bupl2XyaLWWuRCxAJ78xuf98qVRIBfT/FKGeP
fz+GtXkv3naCD12Ay6YiwfxSQhxFiJtRwP5rla2i7hlV3BLFPYCWTtL8OLF4CoRm
7aF5EuDr1x7emEDyu1rf5E59ttSIySuIw0J1mTjrPCkC6lsowzTJS/vaCxZ3e7fN
iZE6VEWWY/iOxd8foJH/VZ3cfNKjfi8+Fh8t7o9ztjYTQAOZUJTn2CHB7Wkyr0Ar
HNM3v26gPFpb7UkHw0Cq2HWNV/Z7cbQc/BQ4HmrmuBPB6SWNOaBN751BbQKnPcA=
=IusH
-----END PGP SIGNATURE-----
"""
describe "#tree", ->
repo = fixtures.branched
describe "master", ->