Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(scripts): git-fixture writes merge commits (#9923)

Christopher Chedeau22086978f01c
diff --git a/scripts/lib/git-fixture.mjs b/scripts/lib/git-fixture.mjs
index 279cbb9a5e..bdd985172b 100644
--- a/scripts/lib/git-fixture.mjs
+++ b/scripts/lib/git-fixture.mjs
@@ -24,6 +24,8 @@ const SIGNATURE = 'Fixture <[email protected]>';
* @property {string} [parent] A named commit of this fixture, or any
* commit-ish the repository held before this import. Without it, the commit
* follows the last one on its ref in this import, or starts a new history.
+ * @property {string[]} [merges] More parents, each named as `parent` is, for a
+ * merge commit. Its tree is the first parent's tree with `files` applied.
* @property {string} [message]
* @property {Record<string, string | null>} [files] Content by path; `null`
* deletes the path.
@@ -62,6 +64,12 @@ export function importCommits(root, commits, refs = {}) {
`from ${parent === undefined ? `${commit.parent}^0` : `:${parent}`}`,
);
}
+ for (const other of commit.merges ?? []) {
+ const merged = marks.get(other);
+ stream.push(
+ `merge ${merged === undefined ? `${other}^0` : `:${merged}`}`,
+ );
+ }
if (commit.snapshot) stream.push('deleteall');
for (const [file, content] of Object.entries(commit.files ?? {})) {
if (content === null) {
diff --git a/scripts/lib/git-fixture.test.mjs b/scripts/lib/git-fixture.test.mjs
index a81ed63260..5568e6887b 100644
--- a/scripts/lib/git-fixture.test.mjs
+++ b/scripts/lib/git-fixture.test.mjs
@@ -70,6 +70,34 @@ describe('fixture repositories', () => {
expect(git(root, 'log', '-1', '--format=%s', hashes.base)).toBe('base');
});
+ it("writes a merge commit from its first parent's tree and its other parents", () => {
+ const root = path.join(tempDir(), 'repo');
+ const hashes = createRepository(root, [
+ {ref: 'refs/heads/main', name: 'base', files: {'a.txt': 'a\n'}},
+ {
+ ref: 'refs/heads/topic',
+ name: 'topic',
+ parent: 'base',
+ files: {'t.txt': 't\n'},
+ },
+ {ref: 'refs/heads/main', name: 'main', files: {'m.txt': 'm\n'}},
+ {
+ ref: 'refs/pull/1/merge',
+ name: 'merge',
+ parent: 'main',
+ merges: ['topic'],
+ files: {'t.txt': 't\n'},
+ },
+ ]);
+
+ expect(
+ git(root, 'rev-parse', 'refs/pull/1/merge^1', 'refs/pull/1/merge^2'),
+ ).toBe([hashes.main, hashes.topic].join('\n'));
+ expect(git(root, 'ls-tree', '--name-only', hashes.merge)).toBe(
+ ['a.txt', 'm.txt', 't.txt'].join('\n'),
+ );
+ });
+
it('records a working tree exactly as a snapshot, and continues from a ref', () => {
const root = tempDir();
fs.mkdirSync(path.join(root, 'docs'));