* Creates a hidden git repository in the project root. * The Git repository is used to support checkpointing.
()
| 52 | * The Git repository is used to support checkpointing. |
| 53 | */ |
| 54 | async setupShadowGitRepository() { |
| 55 | const repoDir = this.getHistoryDir(); |
| 56 | const gitConfigPath = path.join(repoDir, '.gitconfig'); |
| 57 | |
| 58 | await fs.mkdir(repoDir, { recursive: true }); |
| 59 | |
| 60 | // We don't want to inherit the user's name, email, or gpg signing |
| 61 | // preferences for the shadow repository, so we create a dedicated gitconfig. |
| 62 | const gitConfigContent = |
| 63 | '[user]\n name = ANUS\n email = anus-cli@google.com\n[commit]\n gpgsign = false\n'; |
| 64 | await fs.writeFile(gitConfigPath, gitConfigContent); |
| 65 | |
| 66 | const repo = simpleGit(repoDir); |
| 67 | const isRepoDefined = await repo.checkIsRepo(CheckRepoActions.IS_REPO_ROOT); |
| 68 | |
| 69 | if (!isRepoDefined) { |
| 70 | await repo.init(false, { |
| 71 | '--initial-branch': 'main', |
| 72 | }); |
| 73 | |
| 74 | await repo.commit('Initial commit', { '--allow-empty': null }); |
| 75 | } |
| 76 | |
| 77 | const userGitIgnorePath = path.join(this.projectRoot, '.gitignore'); |
| 78 | const shadowGitIgnorePath = path.join(repoDir, '.gitignore'); |
| 79 | |
| 80 | let userGitIgnoreContent = ''; |
| 81 | try { |
| 82 | userGitIgnoreContent = await fs.readFile(userGitIgnorePath, 'utf-8'); |
| 83 | } catch (error) { |
| 84 | if (isNodeError(error) && error.code !== 'ENOENT') { |
| 85 | throw error; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | await fs.writeFile(shadowGitIgnorePath, userGitIgnoreContent); |
| 90 | } |
| 91 | |
| 92 | private get shadowGitRepository(): SimpleGit { |
| 93 | const repoDir = this.getHistoryDir(); |
no test coverage detected