Methods
catFile(hash, gitDir)
Git 객체 내용을 출력합니다 (blob/tree/commit 지원).
Parameters:
| Name | Type | Description |
|---|---|---|
hash |
string | SHA-1 해시 |
gitDir |
string | .git 디렉토리 경로 |
- Source:
formatGitDate(isoString) → {string}
ISO 문자열을 Git 로그 형식의 날짜 문자열로 변환합니다.
실제 `git log` 명령어와 유사한 형식으로 표현됩니다.
Parameters:
| Name | Type | Description |
|---|---|---|
isoString |
string | ISO 형식의 날짜 문자열 (e.g. new Date().toISOString()) |
- Source:
Returns:
Git 로그 스타일로 포맷된 날짜 문자열
- Type
- string
Example
formatGitDate("2025-05-31T13:22:59.000Z"); // 'Sat May 31 22:22:59 2025 +0900'
getCurrentCommitHash(gitDir) → {string|null}
현재 HEAD가 가리키는 커밋 해시를 반환합니다.
브랜치 기반이면 ref 파일을 읽고, detached 상태면 바로 해시를 반환합니다.
Parameters:
| Name | Type | Description |
|---|---|---|
gitDir |
string | Git 디렉토리 경로 |
Returns:
현재 커밋 해시
- Type
- string | null
parseCommitObject(raw) → {Object}
Git 커밋 객체 내용을 파싱하여 구조화된 정보로 반환합니다.
이때, 커밋 객체는 다음 형식으로 구성됩니다.
```
tree
parent
author
committer
<커밋 메시지>
```
Parameters:
| Name | Type | Description |
|---|---|---|
raw |
Buffer | zlib 압축 해제된 커밋 객체의 원시 데이터 |
- Source:
Returns:
파싱된 커밋 객체
- Type
- Object
readHead(gitDir) → {object}
HEAD 파일을 읽고, 참조(ref) 또는 해시 정보를 파싱합니다.
브랜치 기반 HEAD라면 ref 경로를, detached 상태라면 해시 값을 반환합니다.
Parameters:
| Name | Type | Description |
|---|---|---|
gitDir |
string | Git 디렉토리 경로 |
- Source:
Returns:
HEAD 정보 객체 (type, ref/hash, fullPath)
- Type
- object
readObject(hash, gitDir) → {Buffer|null}
주어진 해시를 기반으로 Git 객체 파일을 읽고, 압축을 해제하여 원본 데이터를 반환합니다.
Parameters:
| Name | Type | Description |
|---|---|---|
hash |
string | Git 객체의 SHA-1 해시 |
gitDir |
string | Git 저장소 디렉토리(기본 값은 `.mini-git`, 테스트 시 외부에서 주입 가능) |
- Source:
Returns:
압축 해제된 Git 객체 데이터. 파일이 없을 경우 null 반환.
- Type
- Buffer | null
writeGitObject(type, content, gitDir) → {string}
Git 객체를 생성하고 저장합니다.
Parameters:
| Name | Type | Description |
|---|---|---|
type |
'blob' | 'tree' | 'commit' | |
content |
Buffer | string | |
gitDir |
string |
- Source:
Returns:
SHA-1 해시
- Type
- string