({ fs, gitdir, object, format, oid })
| 1 | import { InternalError } from '../errors/InternalError.js' |
| 2 | |
| 3 | export async function writeObjectLoose({ fs, gitdir, object, format, oid }) { |
| 4 | if (format !== 'deflated') { |
| 5 | throw new InternalError( |
| 6 | 'GitObjectStoreLoose expects objects to write to be in deflated format' |
| 7 | ) |
| 8 | } |
| 9 | const source = `objects/${oid.slice(0, 2)}/${oid.slice(2)}` |
| 10 | const filepath = `${gitdir}/${source}` |
| 11 | // Don't overwrite existing git objects - this helps avoid EPERM errors. |
| 12 | // Although I don't know how we'd fix corrupted objects then. Perhaps delete them |
| 13 | // on read? |
| 14 | if (!(await fs.exists(filepath))) await fs.write(filepath, object) |
| 15 | } |
no test coverage detected
searching dependent graphs…