Skip to content

Commit

Permalink
[eas-cli] Support excluding .git via .easignore (#2879)
Browse files Browse the repository at this point in the history
<!-- If this PR requires a changelog entry, add it by commenting the PR with the command `/changelog-entry [breaking-change|new-feature|bug-fix|chore] [message]`. -->
<!-- You can skip the changelog check by labeling the PR with "no changelog". -->

# 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.
  • Loading branch information
sjchmiela authored Feb 5, 2025
1 parent f5480b4 commit 98344b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions packages/eas-cli/src/vcs/clients/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<boolean> {
const rootPath = await this.getRootPathAsync();

Expand All @@ -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
Expand Down

0 comments on commit 98344b8

Please sign in to comment.