Skip to content

Commit

Permalink
Add missing null check
Browse files Browse the repository at this point in the history
Add missing null check if a line isn't present in a chunk due to it being empty (i.e. having no lines in the conflict).
  • Loading branch information
martincostello committed Aug 15, 2023
1 parent eca0678 commit 27ee8f4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function tryResolveByChunk(theirs: string[], ours: string[]): string[] | null {
result.push(line.value);
resolved = true;
}
} else if (line.value === theirChunk.lines[line.index].value) {
} else if (line.value === theirChunk.lines[line.index]?.value) {
result.push(line.value);
resolved = true;
}
Expand Down
28 changes: 27 additions & 1 deletion tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

import * as core from '@actions/core';
import { afterAll, beforeAll, describe, expect, test } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, test, xdescribe } from '@jest/globals';
import { ActionFixture } from './ActionFixture';

describe('rebaser', () => {
Expand Down Expand Up @@ -349,4 +349,30 @@ describe('rebaser', () => {
expect(await fixture.getFileContent('Directory.Packages.props')).toMatchSnapshot();
});
});

xdescribe.each([['', '', '']])(
'when an existing repository is rebased',
(repository: string, baseBranch: string, targetBranch: string) => {
let fixture: ActionFixture;

beforeAll(async () => {
fixture = new ActionFixture(baseBranch, targetBranch);
await fixture.initialize(repository);
await fixture.run();
}, rebaseTimeout);

afterAll(async () => {
await fixture?.destroy();
});

test('generates no errors', () => {
expect(core.error).toHaveBeenCalledTimes(0);
expect(core.setFailed).toHaveBeenCalledTimes(0);
});

test('outputs the correct result', () => {
expect(fixture.getOutput('result')).toBe('success');
});
}
);
});

0 comments on commit 27ee8f4

Please sign in to comment.