Skip to content

Commit 50d3c19

Browse files
author
SPRINX0\prochazka
committed
correctly solved merge commits
1 parent 3be1b1a commit 50d3c19

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

src/diflow.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from './testrepo';
1212
import { Processor } from './processor';
1313
import { execAsync, sleep } from './tools';
14+
import { rimraf } from 'rimraf';
1415

1516
describe('Git Repository Tests', () => {
1617
beforeEach(async () => {
@@ -245,4 +246,44 @@ describe('Git Repository Tests', () => {
245246
expect(await fs.exists(path.join(getTestRepoPath('merged'), 'only-base.txt'))).toBe(false);
246247
expect(await fs.exists(path.join(getTestRepoPath('base'), 'only-base.txt'))).toBe(false);
247248
});
249+
250+
test('Git merge', async () => {
251+
await execAsync('git checkout -b feature', { cwd: getTestRepoPath('base') });
252+
await createTestCommit(getTestRepoPath('base'), 'feature1.txt', 'feature1', 'base', 'feature1');
253+
254+
await sleep(1100);
255+
await execAsync('git checkout master', { cwd: getTestRepoPath('base') });
256+
await createTestCommit(getTestRepoPath('base'), 'master1.txt', 'master1', 'base', 'master1');
257+
258+
await sleep(1100);
259+
await execAsync('git checkout feature', { cwd: getTestRepoPath('base') });
260+
await createTestCommit(getTestRepoPath('base'), 'feature2.txt', 'feature2', 'base', 'feature2');
261+
262+
await beforeDiflow();
263+
264+
const processor1 = new Processor(getTestRepoPath('config'), path.join(__dirname, 'workrepos'), 'master');
265+
await processor1.process();
266+
267+
await afterDiflow();
268+
269+
await checkStateInConfig();
270+
271+
await sleep(1100);
272+
await execAsync('git checkout master', { cwd: getTestRepoPath('base') });
273+
await execAsync('git merge feature', { cwd: getTestRepoPath('base') });
274+
275+
await beforeDiflow('tmp2');
276+
277+
await rimraf(path.join(__dirname, 'workrepos'));
278+
const processor2 = new Processor(getTestRepoPath('config'), path.join(__dirname, 'workrepos'), 'master');
279+
await processor2.process();
280+
281+
await afterDiflow();
282+
283+
await checkStateInConfig();
284+
285+
expect(await fs.exists(path.join(getTestRepoPath('merged'), 'feature1.txt'))).toBe(true);
286+
expect(await fs.exists(path.join(getTestRepoPath('merged'), 'feature2.txt'))).toBe(true);
287+
expect(await fs.exists(path.join(getTestRepoPath('merged'), 'master1.txt'))).toBe(true);
288+
});
248289
});

src/testrepo.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ export async function initTestRepos() {
112112
await createTestCommit(getTestRepoPath('config'), 'state.json', stateContent, 'config');
113113
}
114114

115-
export async function beforeDiflow() {
115+
export async function beforeDiflow(tmpBranchName = 'tmp') {
116116
console.log('Checking out new tmp branch');
117-
await execAsync('git checkout -b tmp', { cwd: getTestRepoPath('merged') });
118-
await execAsync('git checkout -b tmp', { cwd: getTestRepoPath('base') });
119-
await execAsync('git checkout -b tmp', { cwd: getTestRepoPath('diff') });
120-
await execAsync('git checkout -b tmp', { cwd: getTestRepoPath('config') });
121-
console.log('Checked out new tmp branch');
117+
await execAsync(`git checkout -b ${tmpBranchName}`, { cwd: getTestRepoPath('merged') });
118+
await execAsync(`git checkout -b ${tmpBranchName}`, { cwd: getTestRepoPath('base') });
119+
await execAsync(`git checkout -b ${tmpBranchName}`, { cwd: getTestRepoPath('diff') });
120+
await execAsync(`git checkout -b ${tmpBranchName}`, { cwd: getTestRepoPath('config') });
121+
console.log(`Checked out new ${tmpBranchName} branch`);
122122
}
123123

124124
export async function afterDiflow() {

src/tools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function runGitCommand(repoPath: string, cmd: string): Promise<stri
2121
export async function getCommits(repoPath: string, branch: string): Promise<Commit[]> {
2222
const log = await runGitCommand(
2323
repoPath,
24-
`log ${branch} --reverse --pretty=format:"%H@|@%ct@|@%aN@|@%aE@|@%s@|@%ad"`
24+
`log ${branch} --reverse --first-parent --pretty=format:"%H@|@%ct@|@%aN@|@%aE@|@%s@|@%ad"`
2525
);
2626
const res = log
2727
.split('\n')
@@ -64,7 +64,7 @@ export function filterCommitsToProcess(
6464
}
6565

6666
export async function getDiffForCommit(repoPath: string, commitHash: string): Promise<ChangeItem[]> {
67-
const diff = await runGitCommand(repoPath, `show --name-status ${commitHash}`);
67+
const diff = await runGitCommand(repoPath, `show --name-status --diff-merges=first-parent ${commitHash}`);
6868
return diff
6969
.split('\n')
7070
.filter(x => x.match(/^(A|M|D|R\d\d\d)\t/))

0 commit comments

Comments
 (0)