diff --git a/src/commands/add.ts b/src/commands/add.ts index e2546d0..eadcac0 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -2,6 +2,7 @@ import { readFile } from "node:fs/promises"; import { GIT_INDEX } from "../constants.js"; import { coloredLog } from "../functions/colored-log.js"; +import { exists } from "../functions/exists.js"; import { BlobObject } from "../models/blob-object.js"; import { GitIndex } from "../models/git-index.js"; @@ -18,6 +19,15 @@ export const add = async (options: Array): Promise => { return; } + //ファイルが存在しなかった場合の処理 + if (!(await exists(filePath))) { + coloredLog({ + text: `fatal: pathspec '${filePath}' did not match any files`, + color: "red", + }); + return; + } + // TODO: ディレクトリを指定した際などに複数回pushEntryする const content = await readFile(filePath);