Skip to content

Commit

Permalink
[eas-cli] Do not include files deleted in working directory (#2900)
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

When we `git clone` the source repository and then copy worktree changes over, we add and modify files. However, we do not _delete_ files that have been deleted in worktree.

# How

When we operate in `requireCommit: false` mode, we add `--no-checkout` to the `git clone` command. This way the destination directory only has `.git` directory when we start copying files over. Thus, files deleted from worktree will not suddenly appear in tarball.

In `requireCommit: true` mode we don't add `--no-checkout`, because we don't copy files.

# Test Plan

Added test. Tested manually.

Side effect of this is that `git status` reports that all files have been deleted and there's a bunch of untracked files (which, `git add`-ed, make the repository appear as the source repo). I don't know how to copy the Git index 1-1…
  • Loading branch information
sjchmiela authored Feb 11, 2025
1 parent 78837a4 commit 574bde9
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

notify-slack:
runs-on: ubuntu-latest
needs: test
needs: [test]
name: Notify Slack
if: ${{ github.ref == 'refs/heads/main' && always() }}
steps:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This is the log of notable changes to EAS CLI and related packages.

### 🐛 Bug fixes

- Fix files deleted in working directory not being removed from the project archive when `requireCommit` is false. ([#2900](https://github.com/expo/eas-cli/pull/2900) by [@sjchmiela](https://github.com/sjchmiela))

### 🧹 Chores

## [15.0.9](https://github.com/expo/eas-cli/releases/tag/v15.0.9) - 2025-02-09
Expand Down
79 changes: 63 additions & 16 deletions packages/eas-cli/src/vcs/clients/__tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,78 @@ describe('git', () => {
);
});
});

it('is able to delete a submodule ignored by .easignore', async () => {
const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
await spawnAsync('git', ['init'], { cwd: repoRoot });
const vcs = new GitClient({
requireCommit: false,
maybeCwdOverride: repoRoot,
});

await spawnAsync(
'git',
['submodule', 'add', 'https://github.com/expo/results.git', 'results'],
{ cwd: repoRoot }
);
await spawnAsync('git', ['add', 'results'], { cwd: repoRoot });
await spawnAsync('git', ['commit', '-m', 'add submodule'], { cwd: repoRoot });

const repoCloneNonIgnored = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
await expect(vcs.makeShallowCopyAsync(repoCloneNonIgnored)).resolves.not.toThrow();
await expect(fs.stat(path.join(repoCloneNonIgnored, 'results'))).resolves.not.toThrow();

await fs.writeFile(`${repoRoot}/.easignore`, 'results');
const repoCloneIgnored = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
await expect(vcs.makeShallowCopyAsync(repoCloneIgnored)).resolves.not.toThrow();
await expect(fs.stat(path.join(repoCloneIgnored, 'results'))).rejects.toThrow('ENOENT');
});
});

it('is able to delete a submodule ignored by .easignore', async () => {
it('does not include files that have been removed in the working directory', async () => {
const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
await spawnAsync('git', ['init'], { cwd: repoRoot });
const vcs = new GitClient({
requireCommit: false,
maybeCwdOverride: repoRoot,
});

await spawnAsync(
'git',
['submodule', 'add', 'https://github.com/expo/results.git', 'results'],
{ cwd: repoRoot }
await fs.writeFile(`${repoRoot}/committed-file.txt`, 'file');
await fs.writeFile(`${repoRoot}/file-to-remove.txt`, 'file');
await spawnAsync('git', ['add', 'committed-file.txt', 'file-to-remove.txt'], {
cwd: repoRoot,
});
await spawnAsync('git', ['commit', '-m', 'add files'], { cwd: repoRoot });

await fs.rm(`${repoRoot}/file-to-remove.txt`);
await spawnAsync('git', ['add', 'file-to-remove.txt'], { cwd: repoRoot });
await spawnAsync('git', ['commit', '-m', 'remove file'], { cwd: repoRoot });

await fs.writeFile(`${repoRoot}/new-file.txt`, 'file');
await fs.writeFile(`${repoRoot}/new-tracked-file.txt`, 'file');

const repoClone = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
await expect(vcs.makeShallowCopyAsync(repoClone)).resolves.not.toThrow();
await expect(fs.stat(path.join(repoClone, 'file-to-remove.txt'))).rejects.toThrow('ENOENT');
await expect(fs.stat(path.join(repoClone, 'committed-file.txt'))).resolves.not.toThrow();
await expect(fs.stat(path.join(repoClone, 'new-file.txt'))).resolves.not.toThrow();
await expect(fs.stat(path.join(repoClone, 'new-tracked-file.txt'))).resolves.not.toThrow();

vcs.requireCommit = true;
await spawnAsync('git', ['add', '.'], { cwd: repoRoot });
await spawnAsync('git', ['commit', '-m', 'tmp commit'], { cwd: repoRoot });

const requireCommitClone = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
await expect(vcs.makeShallowCopyAsync(requireCommitClone)).resolves.not.toThrow();
await expect(fs.stat(path.join(requireCommitClone, 'file-to-remove.txt'))).rejects.toThrow(
'ENOENT'
);
await spawnAsync('git', ['add', 'results'], { cwd: repoRoot });
await spawnAsync('git', ['commit', '-m', 'add submodule'], { cwd: repoRoot });

const repoCloneNonIgnored = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
await expect(vcs.makeShallowCopyAsync(repoCloneNonIgnored)).resolves.not.toThrow();
await expect(fs.stat(path.join(repoCloneNonIgnored, 'results'))).resolves.not.toThrow();

await fs.writeFile(`${repoRoot}/.easignore`, 'results');
const repoCloneIgnored = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
await expect(vcs.makeShallowCopyAsync(repoCloneIgnored)).resolves.not.toThrow();
await expect(fs.stat(path.join(repoCloneIgnored, 'results'))).rejects.toThrow('ENOENT');
await expect(
fs.stat(path.join(requireCommitClone, 'committed-file.txt'))
).resolves.not.toThrow();
await expect(fs.stat(path.join(requireCommitClone, 'new-file.txt'))).resolves.not.toThrow();
await expect(
fs.stat(path.join(requireCommitClone, 'new-tracked-file.txt'))
).resolves.not.toThrow();
});
});
14 changes: 13 additions & 1 deletion packages/eas-cli/src/vcs/clients/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,19 @@ export default class GitClient extends Client {
await setGitCaseSensitivityAsync(true, rootPath);
await spawnAsync(
'git',
['clone', '--no-hardlinks', '--depth', '1', gitRepoUri, destinationPath],
[
'clone',
// If we do not require a commit, we are going to later
// copy the working directory into the destination path,
// so we can skip the checkout step (which also adds files
// that have been removed in the working directory).
this.requireCommit ? null : '--no-checkout',
'--no-hardlinks',
'--depth',
'1',
gitRepoUri,
destinationPath,
].flatMap(e => e ?? []),
{ cwd: rootPath }
);

Expand Down

0 comments on commit 574bde9

Please sign in to comment.