Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kucherenko committed Sep 17, 2023
1 parent 530d215 commit 0965877
Show file tree
Hide file tree
Showing 4 changed files with 311 additions and 103 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"cov": "run-s build test:unit cov:html && open-cli coverage/index.html",
"cov:html": "nyc report --reporter=lcov",
"cov:send": "nyc report --reporter=lcov && codecov",
"cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100",
"cov:check": "nyc report && nyc check-coverage --lines 90 --functions 100 --branches 80",
"version": "standard-version",
"reset": "git clean -dfx && git reset --hard && npm i",
"clean": "trash build test",
Expand All @@ -48,6 +48,7 @@
"devDependencies": {
"@bitjson/npm-scripts-info": "^1.0.0",
"@istanbuljs/nyc-config-typescript": "^0.1.3",
"@types/node": "^20.6.2",
"@types/sinon": "^7.5.2",
"@types/which": "^1.3.2",
"ava": "^3.5.0",
Expand Down
3 changes: 2 additions & 1 deletion src/vcs/git.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const stubExeca = {
const stubWhich = sinon.stub().returns(pathToGit);
const { git } = proxyquire('./git', {
execa: stubExeca,
which: stubWhich
which: stubWhich,
'node:fs': {existsSync: sinon.stub().returns(true)}
});

test('should parse git blame command output', async (t: ExecutionContext) => {
Expand Down
6 changes: 6 additions & 0 deletions src/vcs/git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import execa from 'execa';
import which from 'which';
import { BlamedLine, BlameResult } from '../blame-result.interface';
import { existsSync } from 'node:fs';

const convertStringToObject = (sourceLine: string): BlamedLine => {
const matches = sourceLine.match(
Expand All @@ -20,6 +21,11 @@ const convertStringToObject = (sourceLine: string): BlamedLine => {
export async function git(path: string): Promise<BlameResult> {
const blamedLines: { [line: string]: BlamedLine } = {};
const pathToGit: string = await which('git');

if (!existsSync(path)) {
throw new Error(`File ${path} does not exist`);
}

const result = execa.sync(pathToGit, ['blame', '-w', path]);
result.stdout.split('\n').forEach(line => {
if (line !== '') {
Expand Down
Loading

0 comments on commit 0965877

Please sign in to comment.