-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 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 |
---|---|---|
|
@@ -3,6 +3,24 @@ import fs from "fs"; | |
import path from "path"; | ||
import { cacheJoin } from "./cache.js"; | ||
|
||
async function ensureGitignore(dir) { | ||
const gitignorePath = path.join(dir, ".gitignore"); | ||
try { | ||
// Check if .gitignore exists | ||
await fs.promises.access(gitignorePath); | ||
const content = await fs.promises.readFile(gitignorePath, "utf8"); | ||
if (!content.includes("history/")) { | ||
await fs.promises.appendFile(gitignorePath, "\nhistory/\n"); | ||
return true; // indicates .gitignore was modified | ||
} | ||
return false; // indicates no changes were needed | ||
} catch (e) { | ||
// .gitignore doesn't exist, create it | ||
await fs.promises.writeFile(gitignorePath, "history/\n", "utf8"); | ||
return true; // indicates .gitignore was created | ||
} | ||
} | ||
|
||
export async function ensureGitRepoAndCommitBlocks( | ||
buildContextStatuses, | ||
buildPath, | ||
|
@@ -64,6 +82,24 @@ export async function ensureGitRepoAndCommitBlocks( | |
}); | ||
} | ||
|
||
const gitignoreModified = await ensureGitignore(cachePath); | ||
|
||
if (gitignoreModified) { | ||
// Add and commit .gitignore if it was created or modified | ||
await git.add({ fs, dir: cachePath, filepath: ".gitignore" }); | ||
await git.commit({ | ||
fs, | ||
dir: cachePath, | ||
message: isRepo | ||
? "chore: update .gitignore" | ||
: "chore: initial commit with .gitignore", | ||
author: { | ||
name: "Pipeline System", | ||
email: "[email protected]", | ||
}, | ||
}); | ||
} | ||
|
||
// 3. Check for changes | ||
const statusMatrix = await git.statusMatrix({ fs, dir: cachePath }); | ||
const hasChanges = statusMatrix.some( | ||
|