-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Russell Laboe <[email protected]>
- Loading branch information
Showing
10 changed files
with
250 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
{ | ||
"*.js": [ | ||
"eslint", | ||
"eslint --fix", | ||
"prettier --write" | ||
] | ||
"*.ts": ["eslint", "eslint --fix", "prettier --write"], | ||
"*.js": ["eslint", "eslint --fix", "prettier --write"], | ||
"*.md": ["prettier --write"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict' | ||
import { expect, describe, it } from '@jest/globals' | ||
import { | ||
isLFS, | ||
getLFSObjectContentPath, | ||
} from '../../../../src/utils/gitLfsHelper' | ||
|
||
describe('isLFS', () => { | ||
it('returns true when called with LFS file', async () => { | ||
// Arrange | ||
const lfsFileContent = | ||
Buffer.from(`version https://git-lfs.github.com/spec/v1 | ||
oid sha256:0a4ca7e5eca75024197fff96ef7e5de1b2ca35d6c058ce76e7e0d84bee1c8b14 | ||
size 72`) | ||
|
||
// Act | ||
const result = isLFS(lfsFileContent) | ||
|
||
// Assert | ||
expect(result).toBe(true) | ||
}) | ||
it('returns false when called with normal file', async () => { | ||
// Arrange | ||
const lfsFileContent = Buffer.from(`not lfs file`) | ||
|
||
// Act | ||
const result = isLFS(lfsFileContent) | ||
|
||
// Assert | ||
expect(result).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('getLFSObjectContentPath', () => { | ||
it('with LFS content, it creates LFS file path', async () => { | ||
// Arrange | ||
const lfsFileContent = | ||
Buffer.from(`version https://git-lfs.github.com/spec/v1 | ||
oid sha256:0a4ca7e5eca75024197fff96ef7e5de1b2ca35d6c058ce76e7e0d84bee1c8b14 | ||
size 72`) | ||
|
||
// Act | ||
const lfsFilePath = await getLFSObjectContentPath(lfsFileContent) | ||
|
||
// Assert | ||
expect(lfsFilePath).toBe( | ||
'.git/lfs/objects/0a/4c/0a4ca7e5eca75024197fff96ef7e5de1b2ca35d6c058ce76e7e0d84bee1c8b14' | ||
) | ||
}) | ||
|
||
it('without LFS content, it creates LFS file path', async () => { | ||
// Arrange | ||
expect.assertions(1) | ||
const lfsFileContent = Buffer.from(`not lfs file`) | ||
|
||
// Act | ||
try { | ||
await getLFSObjectContentPath(lfsFileContent) | ||
} catch (e) { | ||
// Assert | ||
expect(e).toBeDefined() | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
import { sep } from 'path' | ||
import { GIT_FOLDER, UTF8_ENCODING } from './gitConstants' | ||
import { EOLRegex } from './childProcessUtils' | ||
|
||
const LFS_HEADER = Buffer.from('version https://git-lfs') | ||
|
||
export const isLFS = (content: Buffer): boolean => | ||
content.subarray(0, LFS_HEADER.length).equals(LFS_HEADER) | ||
|
||
export const getLFSObjectContentPath = (bufferContent: Buffer): string => { | ||
const content = bufferContent.toString(UTF8_ENCODING) | ||
const oid = content.split(EOLRegex)[1].split(':')[1] | ||
return [ | ||
GIT_FOLDER, | ||
'lfs', | ||
'objects', | ||
oid.slice(0, 2), | ||
oid.slice(2, 4), | ||
oid, | ||
].join(sep) | ||
} |
Oops, something went wrong.