Update to 4.4
This commit is contained in:
@@ -52,3 +52,69 @@ test('GitService reads changes and commits/pushes selected files to a real bare
|
||||
const remoteLog = await git(['--git-dir', remote, 'log', '-1', '--pretty=%s', 'refs/heads/main'], root);
|
||||
assert.equal(remoteLog.stdout.trim(), 'Add desktop cockpit copy');
|
||||
});
|
||||
|
||||
test('stages and pushes deleted and renamed files selected from the working tree', async (t) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'forgeflow-git-delete-rename-'));
|
||||
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
|
||||
const remote = path.join(root, 'remote.git');
|
||||
const working = path.join(root, 'working');
|
||||
await git(['init', '--bare', remote], root);
|
||||
await git(['clone', remote, working], root);
|
||||
await git(['config', 'user.name', 'ForgeFlow Test'], working);
|
||||
await git(['config', 'user.email', 'forgeflow@example.invalid'], working);
|
||||
await fs.writeFile(path.join(working, 'silent-zebra-glow.zip'), 'obsolete archive\n');
|
||||
await fs.writeFile(path.join(working, 'old-name.txt'), 'rename me\n');
|
||||
await git(['add', '.'], working);
|
||||
await git(['commit', '-m', 'Initial files'], working);
|
||||
await git(['branch', '-M', 'main'], working);
|
||||
await git(['push', '-u', 'origin', 'main'], working);
|
||||
|
||||
await fs.rm(path.join(working, 'silent-zebra-glow.zip'));
|
||||
await fs.rename(path.join(working, 'old-name.txt'), path.join(working, 'new-name.txt'));
|
||||
|
||||
const service = new GitService();
|
||||
const before = await service.status(working);
|
||||
assert.ok(before.files.some((file) => file.path === 'silent-zebra-glow.zip' && file.status === 'deleted'));
|
||||
|
||||
const selected = before.files.map((file) => file.path);
|
||||
const result = await service.commitAndPush(working, 'Remove obsolete archive and rename file', selected);
|
||||
assert.equal(result.status.clean, true);
|
||||
assert.equal(result.status.branch.ahead, 0);
|
||||
|
||||
const tree = await git(['--git-dir', remote, 'ls-tree', '-r', '--name-only', 'refs/heads/main'], root);
|
||||
const names = tree.stdout.trim().split(/\r?\n/).filter(Boolean);
|
||||
assert.deepEqual(names, ['new-name.txt']);
|
||||
});
|
||||
|
||||
test('keeps a successful local commit visible as ahead when the following push fails', async (t) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'forgeflow-git-push-failure-'));
|
||||
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
|
||||
const remote = path.join(root, 'remote.git');
|
||||
const working = path.join(root, 'working');
|
||||
await git(['init', '--bare', remote], root);
|
||||
await git(['clone', remote, working], root);
|
||||
await git(['config', 'user.name', 'ForgeFlow Test'], working);
|
||||
await git(['config', 'user.email', 'forgeflow@example.invalid'], working);
|
||||
await fs.writeFile(path.join(working, 'README.md'), '# Portfolio\n');
|
||||
await git(['add', '.'], working);
|
||||
await git(['commit', '-m', 'Initial'], working);
|
||||
await git(['branch', '-M', 'main'], working);
|
||||
await git(['push', '-u', 'origin', 'main'], working);
|
||||
|
||||
await fs.appendFile(path.join(working, 'README.md'), '\nUpdated locally.\n');
|
||||
await git(['remote', 'set-url', 'origin', path.join(root, 'missing-remote.git')], working);
|
||||
|
||||
const service = new GitService();
|
||||
await assert.rejects(
|
||||
service.commitAndPush(working, 'Update portfolio', ['README.md']),
|
||||
(error) => Boolean(error.code === 'PUSH_AFTER_COMMIT_FAILED' && error.commitSha)
|
||||
);
|
||||
|
||||
const status = await service.status(working);
|
||||
assert.equal(status.clean, true);
|
||||
assert.equal(status.branch.ahead, 1);
|
||||
const subject = await git(['log', '-1', '--pretty=%s'], working);
|
||||
assert.equal(subject.stdout.trim(), 'Update portfolio');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user