Skip to content

Commit 2ff60e7

Browse files
author
SPRINX0\prochazka
committed
fixed changes from merged repo
1 parent c8c413c commit 2ff60e7

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/diflow.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,24 @@ describe('Git Repository Tests', () => {
191191
// Verify changes
192192
expect(mergedExists).toBe(false);
193193
});
194+
195+
test('Adding file to merged', async () => {
196+
await createTestCommit(getTestRepoPath('merged'), 'outer.txt', 'outer', 'merged');
197+
await createTestCommit(getTestRepoPath('merged'), 'folder/inner.txt', 'inner', 'merged');
198+
199+
await beforeDiflow();
200+
201+
const processor = new Processor(getTestRepoPath('config'), path.join(__dirname, 'workrepos'), 'master');
202+
await processor.process();
203+
204+
await afterDiflow();
205+
206+
await checkStateInConfig();
207+
208+
expect(await fs.exists(path.join(getTestRepoPath('diff'), 'outer.txt'))).toBe(true);
209+
expect(await fs.exists(path.join(getTestRepoPath('base'), 'outer.txt'))).toBe(false);
210+
211+
expect(await fs.exists(path.join(getTestRepoPath('diff'), 'folder/inner.txt'))).toBe(false);
212+
expect(await fs.exists(path.join(getTestRepoPath('base'), 'folder/inner.txt'))).toBe(true);
213+
});
194214
});

src/processor.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,19 @@ class CommitProcessor {
246246
}
247247

248248
async processMergedFile(file: ChangeItem) {
249-
if (file.action === 'M' || file.action === 'A') {
250-
await copyRepoFile(this.processor.repoPaths.merged, this.processor.repoPaths.base, file.file);
251-
await copyRepoFile(this.processor.repoPaths.merged, this.processor.repoPaths.diff, file.file);
249+
if (file.action === 'A') {
250+
if (await fs.exists(path.join(this.processor.repoPaths.diff, path.dirname(file.file)))) {
251+
// if exists folder, copy to diff
252+
await copyRepoFile(this.processor.repoPaths.merged, this.processor.repoPaths.diff, file.file);
253+
} else {
254+
await copyRepoFile(this.processor.repoPaths.merged, this.processor.repoPaths.base, file.file);
255+
}
256+
} else if (file.action === 'M') {
257+
if (await repoFileExists(this.processor.repoPaths.diff, file.file)) {
258+
await copyRepoFile(this.processor.repoPaths.merged, this.processor.repoPaths.diff, file.file);
259+
} else {
260+
await copyRepoFile(this.processor.repoPaths.merged, this.processor.repoPaths.base, file.file);
261+
}
252262
} else if (file.action === 'D') {
253263
await removeRepoFile(this.processor.repoPaths.base, file.file);
254264
await removeRepoFile(this.processor.repoPaths.diff, file.file);

src/testrepo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export async function createTestCommit(
2828
message?: string
2929
) {
3030
console.log('Creating commit:', repoPath, 'file:', fileName, 'content:', content);
31+
await fs.ensureDir(path.join(repoPath, path.dirname(fileName)));
3132
await fs.writeFile(path.join(repoPath, fileName), content);
3233
await execAsync('git add .', { cwd: repoPath });
3334
if (message) {

0 commit comments

Comments
 (0)