Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6341,28 +6341,42 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
}),
);

it.effect("prepares selected files without staging and commits only those files", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
yield* initRepoWithCommit(cwd);
const driver = yield* GitVcsDriver.GitVcsDriver;

yield* writeTextFile(cwd, "a.txt", "a\n");
yield* writeTextFile(cwd, "b.txt", "b\n");

const context = yield* driver.prepareCommitContext(cwd, ["a.txt"]);
assert.include(context?.stagedSummary ?? "", "a.txt");
assert.notInclude(context?.stagedSummary ?? "", "b.txt");
assert.equal(yield* git(cwd, ["diff", "--cached", "--name-only"]), "");
it.effect.each(["root", "aliased-nested"] as const)(
"prepares selected files without staging and commits only those files from %s",
(location) =>
Effect.gen(function* () {
const sandbox = yield* makeTmpDir();
const path = yield* Path.Path;
const fileSystem = yield* FileSystem.FileSystem;
const repository = path.join(sandbox, "repo");
const nested = path.join(repository, "sub", "dir");
yield* fileSystem.makeDirectory(nested, { recursive: true });
yield* initRepoWithCommit(repository);
const cwd = location === "aliased-nested" ? path.join(sandbox, "link") : repository;
if (location === "aliased-nested") NodeFS.symlinkSync(nested, cwd, "junction");
const driver = yield* GitVcsDriver.GitVcsDriver;
const selected = "sub/dir/a.txt";
yield* writeTextFile(repository, selected, "a\n");
yield* writeTextFile(repository, "b.txt", "b\n");

const commit = yield* driver.commit(cwd, "Add a", "", { stage: { filePaths: ["a.txt"] } });
assert.match(commit.commitSha, /^[a-f0-9]{40}$/);
assert.equal(yield* git(cwd, ["log", "-1", "--pretty=%s"]), "Add a");
const context = yield* driver.prepareCommitContext(cwd, [selected]);
assert.include(context?.stagedSummary ?? "", "a.txt");
assert.notInclude(context?.stagedSummary ?? "", "b.txt");
assert.equal(yield* git(repository, ["diff", "--cached", "--name-only"]), "");

const status = yield* git(cwd, ["status", "--porcelain"]);
assert.include(status, "?? b.txt");
assert.notInclude(status, "a.txt");
}),
const commit = yield* driver.commit(cwd, "Add a", "", {
stage: { filePaths: [selected] },
});
assert.match(commit.commitSha, /^[a-f0-9]{40}$/);
assert.equal(yield* git(repository, ["log", "-1", "--pretty=%s"]), "Add a");
assert.equal(
yield* git(repository, ["diff-tree", "--no-commit-id", "--name-only", "-r", "HEAD"]),
selected,
);
const status = yield* git(repository, ["status", "--porcelain"]);
assert.include(status, "?? b.txt");
assert.notInclude(status, "a.txt");
}),
);

it.effect("stops a selected-file commit when another process holds the index lock", () =>
Expand Down
6 changes: 4 additions & 2 deletions apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2633,7 +2633,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
cwd,
["rev-parse", "--git-path", "index", "--git-path", "objects"],
)).split("\n");
const indexPath = path.resolve(cwd, indexValue.trim());
// Git's relative paths use the physical cwd, even when the project uses a symlink.
const physicalCwd = yield* fileSystem.realPath(cwd);
const indexPath = path.resolve(physicalCwd, indexValue.trim());
const directory = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3code-commit-index-",
});
Expand All @@ -2651,7 +2653,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
const quoted = (entry: string) =>
entry.startsWith('"') ? entry : `"${entry.replace(/[\\"]/g, "\\$&")}"`;
const alternates = [
path.resolve(cwd, objectsValue.trim()),
path.resolve(physicalCwd, objectsValue.trim()),
...objectDirectories
.split("\n")
.flatMap((line) =>
Expand Down
Loading