.gitignoreが無視されていた

This commit is contained in:
nrslib 2026-01-26 11:47:45 +09:00
parent 6d72c95876
commit f3422e21d1
2 changed files with 54 additions and 2 deletions

View File

@ -367,3 +367,53 @@ describe('loadInputHistory - edge cases', () => {
expect(history).toEqual([]); expect(history).toEqual([]);
}); });
}); });
describe('saveProjectConfig - gitignore copy', () => {
let testDir: string;
beforeEach(() => {
testDir = join(tmpdir(), `takt-test-${randomUUID()}`);
mkdirSync(testDir, { recursive: true });
});
afterEach(() => {
if (existsSync(testDir)) {
rmSync(testDir, { recursive: true, force: true });
}
});
it('should copy .gitignore when creating new config', () => {
setCurrentWorkflow(testDir, 'test');
const configDir = getProjectConfigDir(testDir);
const gitignorePath = join(configDir, '.gitignore');
expect(existsSync(gitignorePath)).toBe(true);
});
it('should copy .gitignore to existing config directory without one', () => {
// Create config directory without .gitignore
const configDir = getProjectConfigDir(testDir);
mkdirSync(configDir, { recursive: true });
writeFileSync(join(configDir, 'config.yaml'), 'workflow: existing\n');
// Save config should still copy .gitignore
setCurrentWorkflow(testDir, 'updated');
const gitignorePath = join(configDir, '.gitignore');
expect(existsSync(gitignorePath)).toBe(true);
});
it('should not overwrite existing .gitignore', () => {
const configDir = getProjectConfigDir(testDir);
mkdirSync(configDir, { recursive: true });
const customContent = '# Custom gitignore\nmy-custom-file';
writeFileSync(join(configDir, '.gitignore'), customContent);
setCurrentWorkflow(testDir, 'test');
const gitignorePath = join(configDir, '.gitignore');
const content = readFileSync(gitignorePath, 'utf-8');
expect(content).toBe(customContent);
});
});

View File

@ -82,12 +82,14 @@ export function saveProjectConfig(projectDir: string, config: ProjectLocalConfig
const configDir = getConfigDir(projectDir); const configDir = getConfigDir(projectDir);
const configPath = getConfigPath(projectDir); const configPath = getConfigPath(projectDir);
// Ensure directory exists and copy project resources on first creation // Ensure directory exists
if (!existsSync(configDir)) { if (!existsSync(configDir)) {
mkdirSync(configDir, { recursive: true }); mkdirSync(configDir, { recursive: true });
copyProjectResourcesToDir(configDir);
} }
// Copy project resources (only copies files that don't exist)
copyProjectResourcesToDir(configDir);
const content = stringify(config, { indent: 2 }); const content = stringify(config, { indent: 2 });
writeFileSync(configPath, content, 'utf-8'); writeFileSync(configPath, content, 'utf-8');
} }