From 98344b8fc25b2bd7857eb8e1456fe6272a53d1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Wed, 5 Feb 2025 11:22:11 +0100 Subject: [PATCH] [eas-cli] Support excluding `.git` via `.easignore` (#2879) # Why Currently it's not possible to exclude `.git` from being uploaded in project tarball. # How In `makeShallowCopyAsync()` we first clone the repository, then we delete files ignored by `.easignore` and then we copy working directory over. The "delete files ignored by `.easignore`" step is governed by `git ls-files --exclude-from=.easignore`. `git ls-files` is never going to consider `.git` directory to be excluded, even if specified in `.easignore`, so we need to special-case the `.git` directory and remove it manually if specified. # Test Plan Added `.git` to a test `.easignore`, ran `eas build:inspect` and confirmed the copied directory did _not_ contain `.git` folder. --- CHANGELOG.md | 1 + packages/eas-cli/src/vcs/clients/git.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d3df26bbc..1cc7e23011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This is the log of notable changes to EAS CLI and related packages. - Fixed `GitClient` not respecting `.easignore` file. ([#2873](https://github.com/expo/eas-cli/pull/2873) by [@sjchmiela](https://github.com/sjchmiela)) - Fix symlink support in `makeShallowCopyAsync`. ([#2874](https://github.com/expo/eas-cli/pull/2874) by [@sjchmiela](https://github.com/sjchmiela)) +- Allow excluding `.git` directory from project archive by adding it to `.easignore`. ([#2879](https://github.com/expo/eas-cli/pull/2879) by [@sjchmiela](https://github.com/sjchmiela)) ### 🧹 Chores diff --git a/packages/eas-cli/src/vcs/clients/git.ts b/packages/eas-cli/src/vcs/clients/git.ts index a1fd6a0e29..12ea2bf01b 100644 --- a/packages/eas-cli/src/vcs/clients/git.ts +++ b/packages/eas-cli/src/vcs/clients/git.ts @@ -212,6 +212,12 @@ export default class GitClient extends Client { await Promise.all( cachedFilesWeShouldHaveIgnored.map(file => fs.rm(path.join(destinationPath, file))) ); + + // Special-case `.git` which `git ls-files` will never consider ignored. + const ignore = await Ignore.createAsync(rootPath); + if (ignore.ignores('.git')) { + await fs.rm(path.join(destinationPath, '.git'), { recursive: true, force: true }); + } } } finally { await setGitCaseSensitivityAsync(isCaseSensitive, rootPath); @@ -284,6 +290,7 @@ export default class GitClient extends Client { ); } + /** NOTE: This method does not support checking whether `.git` is ignored by `.easignore` rules. */ public override async isFileIgnoredAsync(filePath: string): Promise { const rootPath = await this.getRootPathAsync(); @@ -309,6 +316,7 @@ export default class GitClient extends Client { { cwd: rootPath } ) ).stdout.trim() !== ''; + // File is considered ignored if: // - makeShallowCopyAsync() will not copy it to the clone // AND