diff --git a/__snapshots__/blame-spec.js b/__snapshots__/blame-spec.js new file mode 100644 index 0000000..315d845 --- /dev/null +++ b/__snapshots__/blame-spec.js @@ -0,0 +1,724 @@ +exports['blame mocks exec and parses output 1'] = { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock commit", + "filename": "spec/blame-spec.js", + "line": "this is mock line 10000" +} + +exports['blame can grab blame for entire file 1'] = [ + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\tconst la = require('lazy-ass')" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\tconst is = require('check-more-types')" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\tconst schemaShot = require('schema-shot')" + }, + { + "commit": "9a86d902bc83cadc69f27e012ad7e6c3203ac388", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "start work on commit message for any commit", + "filename": "spec/blame-spec.js", + "line": "\tconst snapshot = require('snap-shot-it')" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\tconst { stubExecOnce } = require('stub-spawn-once')" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\tconst { stripIndent } = require('common-tags')" + }, + { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "move blame test", + "filename": "spec/blame-spec.js", + "line": "\t" + }, + { + "commit": "ca3bf0d54fa3e0782e252e67cc14390a52f3f784", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "restore file system before loading snapshot", + "filename": "spec/blame-spec.js", + "line": "\t/* global describe, it, beforeEach */" + }, + { + "commit": "a24a1255531ea46f0b721661fac847a5fe6009f9", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "test blame entire file", + "filename": "spec/blame-spec.js", + "line": "\tdescribe('blame', () => {" + }, + { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "move blame test", + "filename": "spec/blame-spec.js", + "line": "\t const blame = require('..').blame" + }, + { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "move blame test", + "filename": "spec/blame-spec.js", + "line": "\t" + }, + { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "move blame test", + "filename": "spec/blame-spec.js", + "line": "\t it('is a function', () => {" + }, + { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "move blame test", + "filename": "spec/blame-spec.js", + "line": "\t la(is.fn(blame))" + }, + { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "move blame test", + "filename": "spec/blame-spec.js", + "line": "\t })" + }, + { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "move blame test", + "filename": "spec/blame-spec.js", + "line": "\t" + }, + { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "move blame test", + "filename": "spec/blame-spec.js", + "line": "\t it('gets blame for 1 line of this file', () => {" + }, + { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "move blame test", + "filename": "spec/blame-spec.js", + "line": "\t const line = 1" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t return schemaShot(blame(__filename, line))" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t })" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t it('mocks exec and parses output', () => {" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t // line 10000 does NOT exist in this file!" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t const line = 10000" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t const cmd = `git blame --porcelain -L ${line},${line} ${__filename}`" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t const output = stripIndent`" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t adfb30d5888bb1eb9bad1f482248edec2947dab6 ${line} ${line} 1" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t author Gleb Bahmutov" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t author-mail " + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t author-time 1499944626" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t author-tz -0400" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t committer Gleb Bahmutov" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t committer-mail " + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t committer-time 1499944626" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t committer-tz -0400" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t summary mock commit" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t filename spec/blame-spec.js" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t this is mock line ${line}" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t `" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t stubExecOnce(cmd, output)" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t // can use exact snapshot here, because the output will always be" + }, + { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\t // the same! See __snapshots__/blame-spec.js.snap-shot" + }, + { + "commit": "0000000000000000000000000000000000000000", + "author": "Not Committed Yet", + "committer": "Not Committed Yet", + "summary": "Version of spec/blame-spec.js from spec/blame-spec.js", + "filename": "spec/blame-spec.js", + "line": "\t return blame(__filename, line).then(snapshot)" + }, + { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "move blame test", + "filename": "spec/blame-spec.js", + "line": "\t })" + }, + { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "move blame test", + "filename": "spec/blame-spec.js", + "line": "\t" + }, + { + "commit": "a24a1255531ea46f0b721661fac847a5fe6009f9", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "test blame entire file", + "filename": "spec/blame-spec.js", + "line": "\t it('can grab blame for entire file', () => {" + }, + { + "commit": "0000000000000000000000000000000000000000", + "author": "Not Committed Yet", + "committer": "Not Committed Yet", + "summary": "Version of spec/blame-spec.js from spec/blame-spec.js", + "filename": "spec/blame-spec.js", + "line": "\t return blame(__filename).then(snapshot)" + }, + { + "commit": "a24a1255531ea46f0b721661fac847a5fe6009f9", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "test blame entire file", + "filename": "spec/blame-spec.js", + "line": "\t })" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t describe('non-existent file', () => {" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t const fs = require('fs')" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t const sinon = require('sinon')" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t const path = require('path')" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t const line = 42" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t const file = 'foo.txt'" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t const fullFilename = path.resolve(file)" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t beforeEach(() => {" + }, + { + "commit": "78bf5f3a009f0cab9a176e66e9d81e13feb25a40", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "upgrade deps", + "filename": "spec/blame-spec.js", + "line": "\t sinon" + }, + { + "commit": "78bf5f3a009f0cab9a176e66e9d81e13feb25a40", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "upgrade deps", + "filename": "spec/blame-spec.js", + "line": "\t .stub(fs, 'existsSync')" + }, + { + "commit": "78bf5f3a009f0cab9a176e66e9d81e13feb25a40", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "upgrade deps", + "filename": "spec/blame-spec.js", + "line": "\t .withArgs(file)" + }, + { + "commit": "78bf5f3a009f0cab9a176e66e9d81e13feb25a40", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "upgrade deps", + "filename": "spec/blame-spec.js", + "line": "\t .returns(true)" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t const cmd = `git blame --porcelain -L ${line},${line} ${fullFilename}`" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t const output = stripIndent`" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t adfb30d5888bb1eb9bad1f482248edec2947dab6 ${line} ${line} 1" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t author Gleb Bahmutov" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t author-mail " + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t author-time 1499944626" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t author-tz -0400" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t committer Gleb Bahmutov" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t committer-mail " + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t committer-time 1499944626" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t committer-tz -0400" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t summary mock commit" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t filename spec/blame-spec.js" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t this is mock line ${line}" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t `" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t stubExecOnce(cmd, output)" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t })" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t it('can mock blame for non-existent file', () => {" + }, + { + "commit": "ca3bf0d54fa3e0782e252e67cc14390a52f3f784", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "restore file system before loading snapshot", + "filename": "spec/blame-spec.js", + "line": "\t const result = blame(file, line)" + }, + { + "commit": "ca3bf0d54fa3e0782e252e67cc14390a52f3f784", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "restore file system before loading snapshot", + "filename": "spec/blame-spec.js", + "line": "\t // restore file system in order for snapshots to load" + }, + { + "commit": "ca3bf0d54fa3e0782e252e67cc14390a52f3f784", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "restore file system before loading snapshot", + "filename": "spec/blame-spec.js", + "line": "\t fs.existsSync.restore()" + }, + { + "commit": "ca3bf0d54fa3e0782e252e67cc14390a52f3f784", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "restore file system before loading snapshot", + "filename": "spec/blame-spec.js", + "line": "\t return snapshot(result)" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t })" + }, + { + "commit": "159c3764365be53f9894db6b55aa6dd4dbffd4de", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mocking blame", + "filename": "spec/blame-spec.js", + "line": "\t })" + }, + { + "commit": "a24a1255531ea46f0b721661fac847a5fe6009f9", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "test blame entire file", + "filename": "spec/blame-spec.js", + "line": "\t})" + } +] + +exports['blame non-existent file can mock blame for non-existent file 1'] = { + "commit": "adfb30d5888bb1eb9bad1f482248edec2947dab6", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock commit", + "filename": "spec/blame-spec.js", + "line": "this is mock line 42" +} diff --git a/__snapshots__/blame-spec.js.schema-shot b/__snapshots__/blame-spec.js.schema-shot new file mode 100644 index 0000000..5b9e370 --- /dev/null +++ b/__snapshots__/blame-spec.js.schema-shot @@ -0,0 +1,82 @@ +exports['gets blame for 1 line of this file 1'] = { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "commit": { + "type": "string", + "required": true + }, + "author": { + "type": "string", + "required": true + }, + "committer": { + "type": "string", + "required": true + }, + "summary": { + "type": "string", + "required": true + }, + "filename": { + "type": "string", + "required": true + }, + "line": { + "type": "string", + "required": true + } + }, + "additionalProperties": false, + "list": false, + "example": { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\tconst la = require('lazy-ass')" + } +} + +exports['can grab blame for entire file 1'] = { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "commit": { + "type": "string", + "required": true + }, + "author": { + "type": "string", + "required": true + }, + "committer": { + "type": "string", + "required": true + }, + "summary": { + "type": "string", + "required": true + }, + "filename": { + "type": "string", + "required": true + }, + "line": { + "type": "string", + "required": true + } + }, + "additionalProperties": false, + "list": true, + "example": { + "commit": "b2bf285c40b0c17743d84495b69c51d4c6367089", + "author": "Gleb Bahmutov", + "committer": "Gleb Bahmutov", + "summary": "mock test", + "filename": "spec/blame-spec.js", + "line": "\tconst la = require('lazy-ass')" + } +} + diff --git a/__snapshots__/commit-numstat-utils-spec.js b/__snapshots__/commit-numstat-utils-spec.js new file mode 100644 index 0000000..d565661 --- /dev/null +++ b/__snapshots__/commit-numstat-utils-spec.js @@ -0,0 +1,13 @@ +exports['parsing commit numstat regular commit 1'] = { + "commit": "0b3342816ac2db82d051233e884ff93ddb811b17", + "author": "Renovate Bot ", + "date": "Sat Dec 22 22:15:32 2018 +0000", + "message": "chore(deps): update dependency mocked-env to v1.2.4" +} + +exports['parsing commit numstat merged commit 1'] = { + "commit": "f2d8d7f2b2de0df9cfc14845d284521eb2513c0c", + "author": "Gleb Bahmutov ", + "date": "Fri Aug 9 10:59:17 2019 -0400", + "message": "fix: update lodash" +} diff --git a/__snapshots__/commits-spec.js b/__snapshots__/commits-spec.js new file mode 100644 index 0000000..a57ae7a --- /dev/null +++ b/__snapshots__/commits-spec.js @@ -0,0 +1,12 @@ +exports['commits all parses given output 1'] = [ + { + "id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "message": "first commit", + "body": "" + }, + { + "id": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "message": "second commit", + "body": "" + } +] diff --git a/__snapshots__/one-line-log-spec.js b/__snapshots__/one-line-log-spec.js new file mode 100644 index 0000000..488093c --- /dev/null +++ b/__snapshots__/one-line-log-spec.js @@ -0,0 +1,21 @@ +exports['one line log parses mock output 1'] = [ + { + "id": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "message": "commit B" + }, + { + "id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "message": "commit A" + } +] + +exports['one line log parses mock output with branch name 1'] = [ + { + "id": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "message": "commit B" + }, + { + "id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "message": "commit A" + } +] diff --git a/__snapshots__/one-line-log-spec.js.schema-shot b/__snapshots__/one-line-log-spec.js.schema-shot new file mode 100644 index 0000000..0d8b8e3 --- /dev/null +++ b/__snapshots__/one-line-log-spec.js.schema-shot @@ -0,0 +1,21 @@ +exports['grabs last 5 commits schema 1'] = { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "id": { + "type": "string", + "required": true + }, + "message": { + "type": "string", + "required": true + } + }, + "additionalProperties": false, + "list": true, + "example": { + "id": "f2d8d7f2b2de0df9cfc14845d284521eb2513c0c", + "message": "fix: update lodash" + } +} + diff --git a/package-lock.json b/package-lock.json index 0263c74..599014e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -526,6 +526,12 @@ "readable-stream": "^2.0.6" } }, + "arg": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.0.tgz", + "integrity": "sha512-ZWc51jO3qegGkVh8Hwpv636EkbesNV5ZNQPCtRa+0qytRYPEs9IYT9qITY9buezqUH5uqyzlWLcufrzU2rffdg==", + "dev": true + }, "argparse": { "version": "0.1.16", "resolved": "https://registry.npmjs.org/argparse/-/argparse-0.1.16.tgz", @@ -3579,9 +3585,9 @@ "dev": true }, "folktale": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/folktale/-/folktale-2.0.1.tgz", - "integrity": "sha512-3kDSWVkSlErHIt/dC73vu+5zRqbW1mlnL46s2QfYN7Ps0JcS9MVtuLCrDQOBa7sanA+d9Fd8F+bn0VcyNe68Jw==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/folktale/-/folktale-2.3.2.tgz", + "integrity": "sha512-+8GbtQBwEqutP0v3uajDDoN64K2ehmHd0cjlghhxh0WpcfPzAIjPA03e1VvHlxL02FVGR0A6lwXsNQKn3H1RNQ==", "dev": true }, "for-in": { @@ -5646,6 +5652,12 @@ "integrity": "sha1-JOwVr/pdADnog5aVohwsrh9Ftms=", "dev": true }, + "its-name": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/its-name/-/its-name-1.0.0.tgz", + "integrity": "sha1-IGXxiD7LVoxl9xEt2/EjQB+uSvA=", + "dev": true + }, "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", @@ -9096,32 +9108,48 @@ "dev": true }, "snap-shot-compare": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/snap-shot-compare/-/snap-shot-compare-2.7.1.tgz", - "integrity": "sha512-qJPyYskLyuOOON1rFjO5xHmeVduaNJGd6AgeWqq8F6rVE+n79Jr7wdML2qrODoAeb63zztd5JB9Cc8WSWV/rig==", + "version": "2.8.3", + "resolved": "https://registry.npmjs.org/snap-shot-compare/-/snap-shot-compare-2.8.3.tgz", + "integrity": "sha512-dznYMQAYMcQ4crFduIX5sST/Ex35l414hVCL6sXFi84OPuwG5eXgRBfBqbgz7mi3rC/r7VWDn2ADF8FTV/wbCw==", "dev": true, "requires": { "check-more-types": "2.24.0", + "debug": "4.1.1", "disparity": "2.0.0", - "folktale": "2.0.1", + "folktale": "2.3.2", "lazy-ass": "1.6.0", - "strip-ansi": "4.0.0", + "strip-ansi": "5.2.0", "variable-diff": "1.1.0" }, "dependencies": { "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", "dev": true, "requires": { - "ansi-regex": "^3.0.0" + "ansi-regex": "^4.1.0" } } } @@ -9169,25 +9197,28 @@ } }, "snap-shot-it": { - "version": "6.2.8", - "resolved": "https://registry.npmjs.org/snap-shot-it/-/snap-shot-it-6.2.8.tgz", - "integrity": "sha512-VJkubD1CiX7/M63zyD0cBj7EzdtM2/pMeV2t8pKfGtc8Nxm+fxYPPul0BXDrp+fLG8/7igpGe9Cnd0cs67FTgw==", + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/snap-shot-it/-/snap-shot-it-7.8.0.tgz", + "integrity": "sha512-d83qtfNdlYogDF/fti8ya12P1WT/iBRcbHl3IYpIoUtFg6LP+G/QphPwF0zRDpR36SgFVqLvj9XpWDceHiHkmw==", "dev": true, "requires": { "@bahmutov/data-driven": "1.0.0", "check-more-types": "2.24.0", + "common-tags": "1.8.0", "debug": "4.1.1", "has-only": "1.1.1", - "pluralize": "7.0.0", + "its-name": "1.0.0", + "lazy-ass": "1.6.0", + "pluralize": "8.0.0", "ramda": "0.26.1", - "snap-shot-compare": "2.7.1", - "snap-shot-core": "7.1.11" + "snap-shot-compare": "2.8.3", + "snap-shot-core": "10.1.1" }, "dependencies": { "ci-info": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-1.6.0.tgz", - "integrity": "sha512-vsGdkwSCDpWmP80ncATX7iea5DWQemg1UgCW5J8tqjU3lYw4FBYuj89J0CTVomA7BEfvSZd84GmHko+MxFQU2A==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", + "integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==", "dev": true }, "debug": { @@ -9199,19 +9230,13 @@ "ms": "^2.1.1" } }, - "folktale": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/folktale/-/folktale-2.3.1.tgz", - "integrity": "sha512-x16IvpoFrLxOYbAC4G/ban4eWOGoREcrfaVSiTsDknrRYHMe+W4XUekCYA6w4YyjQpcL8nsNt4A5EUUKjFSpRg==", - "dev": true - }, "is-ci": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.2.1.tgz", - "integrity": "sha512-s6tfsaQaQi3JNciBH6shVqEDvhGut0SUXr31ag8Pd8BBbVVlcGfWhpPmEOoM6RJ5TFhbypvf5yyRw/VXW1IiWg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz", + "integrity": "sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==", "dev": true, "requires": { - "ci-info": "^1.5.0" + "ci-info": "^2.0.0" } }, "jsesc": { @@ -9221,45 +9246,36 @@ "dev": true }, "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, - "ramda": { - "version": "0.26.1", - "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.26.1.tgz", - "integrity": "sha512-hLWjpy7EnsDBb0p+Z3B7rPi3GDeRG5ZtiI33kJhTt+ORCd38AbAIjB/9zRIUoeTbE/AVX5ZkU7m6bznsvrf8eQ==", + "pluralize": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz", + "integrity": "sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==", "dev": true }, "snap-shot-core": { - "version": "7.1.11", - "resolved": "https://registry.npmjs.org/snap-shot-core/-/snap-shot-core-7.1.11.tgz", - "integrity": "sha512-/USGJ0WKhMyOY6Z4FUs2wjEI01eAILcJ1bcIduZOP6l6jMu2nABvMzU/Bd2fRDrdyxXOpqhyzcZCdGJcQtDuYQ==", + "version": "10.1.1", + "resolved": "https://registry.npmjs.org/snap-shot-core/-/snap-shot-core-10.1.1.tgz", + "integrity": "sha512-xrltUg35pvs+d3VliYUJxe2sma45O4kenSf0i4XUoQtG6KZd/hJufu4OtlMDNCjA8cq12bgHZqy7ok/rRAwW+g==", "dev": true, "requires": { + "arg": "4.1.0", "check-more-types": "2.24.0", "common-tags": "1.8.0", - "debug": "3.2.6", + "debug": "4.1.1", "escape-quotes": "1.0.2", - "folktale": "2.3.1", - "is-ci": "1.2.1", + "folktale": "2.3.2", + "is-ci": "2.0.0", "jsesc": "2.5.2", "lazy-ass": "1.6.0", "mkdirp": "0.5.1", - "pluralize": "7.0.0", + "pluralize": "8.0.0", + "quote": "0.4.0", "ramda": "0.26.1" - }, - "dependencies": { - "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", - "dev": true, - "requires": { - "ms": "^2.1.1" - } - } } } } @@ -10224,7 +10240,7 @@ }, "text-encoding": { "version": "0.6.4", - "resolved": "http://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz", + "resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz", "integrity": "sha1-45mpgiV6J22uQou5KEXLcb3CbRk=", "dev": true }, diff --git a/package.json b/package.json index 4721a40..360921d 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "semantic-release": "8.2.3", "simple-commit-message": "4.0.3", "sinon": "6.3.5", - "snap-shot-it": "6.2.8", + "snap-shot-it": "7.8.0", "standard": "11.0.1", "stop-only": "2.2.1", "stub-spawn-once": "2.3.0", diff --git a/spec/blame-spec.js b/spec/blame-spec.js index e883c04..a4229f8 100644 --- a/spec/blame-spec.js +++ b/spec/blame-spec.js @@ -4,10 +4,12 @@ const schemaShot = require('schema-shot') const snapshot = require('snap-shot-it') const { stubExecOnce } = require('stub-spawn-once') const { stripIndent } = require('common-tags') +const path = require('path') /* global describe, it, beforeEach */ describe('blame', () => { const blame = require('..').blame + const testFilename = path.join(__dirname, 'test-file.txt') it('is a function', () => { la(is.fn(blame)) @@ -15,13 +17,13 @@ describe('blame', () => { it('gets blame for 1 line of this file', () => { const line = 1 - return schemaShot(blame(__filename, line)) + return schemaShot(blame(testFilename, line)) }) it('mocks exec and parses output', () => { // line 10000 does NOT exist in this file! const line = 10000 - const cmd = `git blame --porcelain -L ${line},${line} ${__filename}` + const cmd = `git blame --porcelain -L ${line},${line} ${testFilename}` const output = stripIndent` adfb30d5888bb1eb9bad1f482248edec2947dab6 ${line} ${line} 1 author Gleb Bahmutov @@ -39,11 +41,11 @@ describe('blame', () => { stubExecOnce(cmd, output) // can use exact snapshot here, because the output will always be // the same! See __snapshots__/blame-spec.js.snap-shot - return snapshot(blame(__filename, line)) + return blame(testFilename, line).then(snapshot) }) it('can grab blame for entire file', () => { - return schemaShot(blame(__filename)) + return blame(testFilename).then(snapshot) }) describe('non-existent file', () => { @@ -82,7 +84,7 @@ describe('blame', () => { const result = blame(file, line) // restore file system in order for snapshots to load fs.existsSync.restore() - return snapshot(result) + return result.then(snapshot) }) }) }) diff --git a/spec/commits-spec.js b/spec/commits-spec.js index 0028bd8..9b5e8c4 100644 --- a/spec/commits-spec.js +++ b/spec/commits-spec.js @@ -40,7 +40,7 @@ describe('commits', () => { second commit ` ) - return snapshot(commits.all()) + return commits.all().then(snapshot) }) }) diff --git a/spec/test-file.txt b/spec/test-file.txt new file mode 100644 index 0000000..3cff583 --- /dev/null +++ b/spec/test-file.txt @@ -0,0 +1,4 @@ +This is a file to test getting blame for entire file or individual lines +line 1 +line 2 +line 3 diff --git a/spec/utils-spec.js b/spec/utils-spec.js index 3f48123..014852b 100644 --- a/spec/utils-spec.js +++ b/spec/utils-spec.js @@ -3,7 +3,7 @@ const is = require('check-more-types') const R = require('ramda') /* eslint-env mocha */ -describe.only('utils', () => { +describe('utils', () => { describe('buildInfo', () => { const buildInfo = require('../src/utils').buildInfo const options = { diff --git a/src/blame.js b/src/blame.js index 0100be8..19d41c0 100644 --- a/src/blame.js +++ b/src/blame.js @@ -152,7 +152,7 @@ function blameOneLine (filename, lineNumber) { lineNumber + ' ' + fullFilename - return exec(cmd).then(toBlameInfo) + return exec.exec(cmd).then(toBlameInfo) } function blame (filename, lineNumber) { @@ -174,7 +174,7 @@ function blame (filename, lineNumber) { console.log('who to blame for', fullFilename) // http://git-scm.com/docs/git-blame var cmd = 'git blame --porcelain --line-porcelain ' + fullFilename - return exec(cmd).then(toBlameInfoFile) + return exec.exec(cmd).then(toBlameInfoFile) } module.exports = blame diff --git a/src/branch-name.js b/src/branch-name.js index d8cd76d..e51d504 100644 --- a/src/branch-name.js +++ b/src/branch-name.js @@ -7,7 +7,7 @@ var exec = require('./exec') */ function branchName () { var cmd = 'git rev-parse --abbrev-ref HEAD' - return exec(cmd).then(function cleanOutput (str) { + return exec.exec(cmd).then(function cleanOutput (str) { la(check.unemptyString(str), 'expected branch name string', str) return str.trim() }) diff --git a/src/changed-files.js b/src/changed-files.js index 3871a61..46f373d 100644 --- a/src/changed-files.js +++ b/src/changed-files.js @@ -110,7 +110,7 @@ function changedFiles (needContents) { // another command that gives status especially for added files var secondCommand = 'git status --porcelain' - return Q.all([exec(cmd), exec(secondCommand)]) + return Q.all([exec.exec(cmd), exec.exec(secondCommand)]) .spread(function (firstOutput, secondOutput) { log('first output') log(firstOutput) diff --git a/src/clone-repo-spec.js b/src/clone-repo-spec.js index 634f5bf..399cec5 100644 --- a/src/clone-repo-spec.js +++ b/src/clone-repo-spec.js @@ -11,7 +11,7 @@ describe('clone-repo', () => { function removeTempFolder () { if (fs.existsSync(destFolder)) { console.log('removing folder', destFolder) - return exec('rm -rf ' + destFolder) + return exec.exec('rm -rf ' + destFolder) } } diff --git a/src/clone-repo.js b/src/clone-repo.js index 0ee873b..6ee59ad 100644 --- a/src/clone-repo.js +++ b/src/clone-repo.js @@ -10,7 +10,7 @@ function cloneRepo (opts) { throw new Error('Destination folder ' + opts.folder + ' already exists') } var cmd = 'git clone --depth 1 ' + opts.url + ' ' + opts.folder - return exec(cmd) + return exec.exec(cmd) } module.exports = cloneRepo diff --git a/src/commit-message.js b/src/commit-message.js index 057b2c1..c86ba36 100644 --- a/src/commit-message.js +++ b/src/commit-message.js @@ -57,7 +57,7 @@ function commitMessageFor (sha) { la(is.unemptyString(sha), 'expected commit sha', sha) debug('getting commit message for', sha) const cmd = 'git show --format="%ae%n%s%n%b" --no-patch ' + sha - return exec(cmd).then(parseCommitMessage) + return exec.exec(cmd).then(parseCommitMessage) } function commitMessage (sha) { diff --git a/src/commit-numstat-utils-spec.js b/src/commit-numstat-utils-spec.js new file mode 100644 index 0000000..23f03f7 --- /dev/null +++ b/src/commit-numstat-utils-spec.js @@ -0,0 +1,49 @@ +/* eslint-env mocha */ +const { stripIndent } = require('common-tags') +const debug = require('debug')('test') +const snapshot = require('snap-shot-it') +const la = require('lazy-ass') + +describe('parsing commit numstat', () => { + const { commitMeta } = require('./commit-numstat-utils') + + it('regular commit', function () { + // output from "git show --numstat " command + const stdout = stripIndent` + commit 0b3342816ac2db82d051233e884ff93ddb811b17 + Author: Renovate Bot + Date: Sat Dec 22 22:15:32 2018 +0000 + + chore(deps): update dependency mocked-env to v1.2.4 + + 5 22 package-lock.json + 1 1 package.json + ` + const meta = commitMeta(stdout.split('\n')) + debug('meta is %o', meta) + la(meta.message, 'has parsed message text', meta) + snapshot(meta) + }) + + it('merged commit', function () { + // output from "git show --numstat " command + // for a merge commit + const stdout = stripIndent` + commit f2d8d7f2b2de0df9cfc14845d284521eb2513c0c (HEAD -> master, origin/master, origin/HEAD) + Merge: 4fe1eaf 884c7bd + Author: Gleb Bahmutov + Date: Fri Aug 9 10:59:17 2019 -0400 + + fix: update lodash + + Update lodash + + 3 3 package-lock.json + 1 1 package.json + ` + const meta = commitMeta(stdout.split('\n')) + debug('meta is %o', meta) + la(meta.message, 'has parsed message text', meta) + snapshot(meta) + }) +}) diff --git a/src/commit-numstat-utils.js b/src/commit-numstat-utils.js new file mode 100644 index 0000000..15d1e95 --- /dev/null +++ b/src/commit-numstat-utils.js @@ -0,0 +1,104 @@ +var la = require('lazy-ass') +var check = require('check-more-types') +var debug = require('debug')('ggit') + +/** + * parses date, author, message from a merge commit. + */ +function commitMergeMeta (lines) { + la(lines.length > 3, 'expected more lines', lines) + + var commit = lines[0].split(' ')[1].trim() + var author = lines[2].split(':')[1].trim() + // remove Date: + var date = lines[3].substr(5).trim() + var message = lines[5].trim() + + return { + commit: commit, + author: author, + date: date, + message: message + } +} + +/** + * parses date, author, message from a regular or merge commit. + */ +function commitMeta (lines) { + la(lines.length > 3, 'expected more lines', lines) + if (lines[1].indexOf('Merge:') !== -1) { + return commitMergeMeta(lines) + } + + var commit = lines[0].split(' ')[1].trim() + var author = lines[1].split(':')[1].trim() + // remove Date: + var date = lines[2].substr(5).trim() + var message = lines[4].trim() + + return { + commit: commit, + author: author, + date: date, + message: message + } +} + +/* +parses git show --numstat output, which is something like this + +$ git show --numstat 46350c2 +commit 46350c2c9980551d338ce1ad0d8eff7bea9713ec +Author: Gleb Bahmutov +Date: Mon Jan 13 19:04:06 2014 -0500 + + better gruntfile + +1 1 .jshintrc +54 25 Gruntfile.js +9 0 complexity.json +2 1 package.json +*/ +function isValidLine (line) { + var rex = /^\s*\d+\s+\d+[\w\W]+$/ + return line && rex.test(line) +} +la(isValidLine('1 1 time-method-call.js')) +la(isValidLine(' 1 0 README.md')) + +function parseNumstat (stdout) { + la(check.unemptyString(stdout), 'missing numstat output', stdout) + var lines = stdout.split('\n') + la(lines.length > 3, 'expected more lines', stdout) + + var info = commitMeta(lines) + debug('commit meta %o', info) + + var k = 6 + var fileChanges = {} + for (; k < lines.length; k += 1) { + if (isValidLine(lines[k])) { + var parts = lines[k].split('\t') + var added = Number(parts[0].trim()) + var deleted = Number(parts[1].trim()) + var filename = parts[2].trim() + fileChanges[filename] = { + filename: filename, + added: added, + deleted: deleted + } + } + } + + debug('parsed numstat %o', fileChanges) + + info.changes = fileChanges + return info +} + +module.exports = { + commitMeta, + isValidLine, + parseNumstat +} diff --git a/src/commit-numstat.js b/src/commit-numstat.js index 8d58f78..404027e 100644 --- a/src/commit-numstat.js +++ b/src/commit-numstat.js @@ -1,79 +1,13 @@ var la = require('lazy-ass') var check = require('check-more-types') var exec = require('./exec') - -// parses date, author, message -function commitMeta (lines) { - la(lines.length > 3, 'expected more lines', lines) - - var commit = lines[0].split(' ')[1].trim() - var author = lines[1].split(':')[1].trim() - // remove Date: - var date = lines[2].substr(5).trim() - var message = lines[4].trim() - - return { - commit: commit, - author: author, - date: date, - message: message - } -} - -/* -parses git show --numstat output, which is something like this - -$ git show --numstat 46350c2 -commit 46350c2c9980551d338ce1ad0d8eff7bea9713ec -Author: Gleb Bahmutov -Date: Mon Jan 13 19:04:06 2014 -0500 - - better gruntfile - -1 1 .jshintrc -54 25 Gruntfile.js -9 0 complexity.json -2 1 package.json -*/ -function isValidLine (line) { - var rex = /^\s*\d+\s+\d+[\w\W]+$/ - return line && rex.test(line) -} -la(isValidLine('1 1 time-method-call.js')) -la(isValidLine(' 1 0 README.md')) - -function parseNumstat (stdout) { - la(check.unemptyString(stdout), 'missing numstat output', stdout) - var lines = stdout.split('\n') - la(lines.length > 3, 'expected more lines', stdout) - - var info = commitMeta(lines) - - var k = 6 - var fileChanges = {} - for (; k < lines.length; k += 1) { - if (isValidLine(lines[k])) { - var parts = lines[k].split('\t') - var added = Number(parts[0].trim()) - var deleted = Number(parts[1].trim()) - var filename = parts[2].trim() - fileChanges[filename] = { - filename: filename, - added: added, - deleted: deleted - } - } - } - - info.changes = fileChanges - return info -} +var { parseNumstat } = require('./commit-numstat-utils') function commitNumstat (hash) { la(check.unemptyString(hash), 'missing commit hash', hash) var cmd = 'git show --numstat ' + hash - return exec(cmd).then(parseNumstat) + return exec.exec(cmd).then(parseNumstat) } module.exports = commitNumstat diff --git a/src/commit.js b/src/commit.js index 97aaa64..3fd06b1 100644 --- a/src/commit.js +++ b/src/commit.js @@ -17,7 +17,7 @@ function commit (msg, longMessage) { } var cmd = 'git commit -am ' + quote(text) - return exec(cmd) + return exec.exec(cmd) } module.exports = commit diff --git a/src/exec.js b/src/exec.js index 51dca0d..b2c3181 100644 --- a/src/exec.js +++ b/src/exec.js @@ -28,4 +28,4 @@ function execPromise (cmd, verbose) { return deferred.promise } -module.exports = execPromise +module.exports = { exec: execPromise } diff --git a/src/fetch-tags.js b/src/fetch-tags.js index d586dcd..04735f7 100644 --- a/src/fetch-tags.js +++ b/src/fetch-tags.js @@ -7,7 +7,7 @@ function fetchTags (branch) { branch = branch || 'master' debug('fetching remote tags for branch', branch) var cmd = 'git pull origin ' + branch + ' --tags' - return exec(cmd) + return exec.exec(cmd) } module.exports = fetchTags diff --git a/src/file-contents.js b/src/file-contents.js index 20e0b4f..40e5e1f 100644 --- a/src/file-contents.js +++ b/src/file-contents.js @@ -13,7 +13,7 @@ function fileContents (filename, at) { }) log('file contents command', cmd) - return exec(cmd).then(function (data) { + return exec.exec(cmd).then(function (data) { return data.trim() }) } diff --git a/src/file-status.js b/src/file-status.js index a17a518..dc1b329 100644 --- a/src/file-status.js +++ b/src/file-status.js @@ -5,7 +5,8 @@ var R = require('ramda') var cmd = 'git status --porcelain' function fileStatus () { - return exec(cmd) + return exec + .exec(cmd) .then(R.tap(log)) .then(stdoutToGroup) .then(R.tap(log)) diff --git a/src/get-one-line-log.js b/src/get-one-line-log.js index d94137d..f93956d 100644 --- a/src/get-one-line-log.js +++ b/src/get-one-line-log.js @@ -27,7 +27,7 @@ function getLog (opts) { } debug('using log cmd "%s"', cmd) - return exec(cmd).then(logParser) + return exec.exec(cmd).then(logParser) } module.exports = getLog diff --git a/src/git-folder.js b/src/git-folder.js index ad21f70..98a1cd6 100644 --- a/src/git-folder.js +++ b/src/git-folder.js @@ -68,7 +68,8 @@ function stripSeparator (folder) { function getGitFolder () { const cmd = 'git rev-parse --show-toplevel' const verbose = /ggit/.test(process.env.DEBUG) - return exec(cmd, verbose) + return exec + .exec(cmd, verbose) .then(checkFolder, tryDotGit) .catch(searchUpForGitFolder) .then(folder => folder.trim()) diff --git a/src/has-changes.js b/src/has-changes.js index 25c0263..0c8a1f2 100644 --- a/src/has-changes.js +++ b/src/has-changes.js @@ -8,7 +8,7 @@ function hasChanges () { var cmd = 'git diff --exit-code HEAD' // returns exit code 1 if there are changes // thus we reverse the true / false order - return exec(cmd).then(d3h.no, d3h.yes) + return exec.exec(cmd).then(d3h.no, d3h.yes) } module.exports = hasChanges diff --git a/src/is-file-tracked.js b/src/is-file-tracked.js index 6353b70..699c510 100644 --- a/src/is-file-tracked.js +++ b/src/is-file-tracked.js @@ -8,7 +8,7 @@ function isFileTracked (filename) { la(check.unemptyString(filename), 'missing filename') var fullPath = path.resolve(filename) var cmd = 'git ls-files --error-unmatch ' + fullPath - return exec(cmd).then(d3h.yes, d3h.no) + return exec.exec(cmd).then(d3h.yes, d3h.no) } module.exports = check.defend( diff --git a/src/last-commit-id.js b/src/last-commit-id.js index e59c3f1..645b664 100644 --- a/src/last-commit-id.js +++ b/src/last-commit-id.js @@ -35,7 +35,7 @@ function saveIntoFile (filename, build) { function getGitCommit () { var cmd = 'git log --format="%H" -n 1' - return exec(cmd) + return exec.exec(cmd) } function findCommit () { diff --git a/src/push.js b/src/push.js index 752a28c..6c65f38 100644 --- a/src/push.js +++ b/src/push.js @@ -2,7 +2,7 @@ var exec = require('./exec') function push (verbose) { var cmd = 'git push origin master --tags' - return exec(cmd, Boolean(verbose)) + return exec.exec(cmd, Boolean(verbose)) } module.exports = push diff --git a/src/repo-root.js b/src/repo-root.js index ec6190a..4da746d 100644 --- a/src/repo-root.js +++ b/src/repo-root.js @@ -1,7 +1,7 @@ var exec = require('./exec') function getGitRootFolder (cb) { - return exec('git rev-parse --show-toplevel').then( + return exec.exec('git rev-parse --show-toplevel').then( function (path) { path = path.trim() if (cb) { diff --git a/src/tags.js b/src/tags.js index 5d30be3..e922949 100644 --- a/src/tags.js +++ b/src/tags.js @@ -31,7 +31,7 @@ function getTagCommit (tag) { debug('getting commit for tag "%s"', tag) debug('using command "%s"', cmd) - return exec(cmd).then(function (commit) { + return exec.exec(cmd).then(function (commit) { return { commit: commit.trim(), tag: tag @@ -59,7 +59,8 @@ function getBranchTags (vTagsOnly) { // only tags accessible from the current branch are returned var cmd = 'git tag --sort version:refname --merged' var parseSomeTags = parseTags.bind(null, vTagsOnly) - return exec(cmd) + return exec + .exec(cmd) .then(parseSomeTags) .then(getCommitIds) } @@ -67,7 +68,8 @@ function getBranchTags (vTagsOnly) { function getTagsSortByVersion () { const cmd = 'git tag' // return single string so other pieces work as expected - return exec(cmd) + return exec + .exec(cmd) .then(sortTagsByVersion) .then(tags => tags.join('\n')) } @@ -77,7 +79,8 @@ function getTags (vTagsOnly) { // oldest tags first, latest tags last var cmd = 'git tag --sort version:refname' var parseSomeTags = parseTags.bind(null, vTagsOnly) - return exec(cmd) + return exec + .exec(cmd) .catch(getTagsSortByVersion) .then(parseSomeTags) .then(getCommitIds) diff --git a/src/untracked-files.js b/src/untracked-files.js index 9ce51cf..4ad3366 100644 --- a/src/untracked-files.js +++ b/src/untracked-files.js @@ -11,7 +11,7 @@ function cleanList (list) { function untrackedFiles () { var cmd = 'git ls-files --others --exclude-standard' - return exec(cmd).then(cleanList) + return exec.exec(cmd).then(cleanList) } module.exports = untrackedFiles diff --git a/src/utils.js b/src/utils.js index 72a129d..94dacda 100644 --- a/src/utils.js +++ b/src/utils.js @@ -84,7 +84,7 @@ function getCircleCiCommit () { function getGitCommit () { var cmd = 'git log --format="%H" -n 1' - return exec(cmd) + return exec.exec(cmd) } function findCommit () { @@ -104,9 +104,13 @@ function buildInfo (options) { options = options || {} function getMessage (id) { - return options.message - ? numstat(id).then(R.prop('message')) - : Promise.resolve() + if (!options.message) { + debug('no need to get commit message for %s', id) + return Promise.resolve() + } + + debug('getMessage for commit %s', id) + return numstat(id).then(R.prop('message')) } var commitId