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
5 changes: 5 additions & 0 deletions .changeset/just-git-110.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sql-fs-api": patch
---

Upgrade just-git to 1.10.0 for mode-only status, diff, checkout, and merge fixes, ls-tree support, and summary output.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"ioredis": "^5.4.0",
"jose": "^6.2.12",
"just-bash": "^3.6.0",
"just-git": "^1.9.1",
"just-git": "^1.10.0",
"lru-cache": "^11.0.0",
"postgres": "^3.4.0",
"zod": "^3.24.0"
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/api/commands/git-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* is the path just-git actually resolved. A script may background several clones, so each
* invocation gets its own scope via AsyncLocalStorage.
*
* just-git's checkout also never sets the executable bit (blindmansion/just-git#10), so every
* file git writes is given the mode its index entry records until upstream fixes that.
* just-git 1.10 handles mode-only changes. The wrapper also reapplies index modes for files
* written by checkout and merge, including explicitly selected unmerged stages.
*/

import { AsyncLocalStorage } from "node:async_hooks";
Expand Down Expand Up @@ -217,8 +217,7 @@ async function indexModes(
/**
* Give each regular file git wrote its index mode, merging unmerged stages as Git does.
* Only those files change, as with real git, so a caller's own uncommitted chmod on any other file
* stays. A branch switch where a file differs only in mode is not covered: just-git neither
* rewrites that file nor updates its index entry, so there is no correct mode to read.
* stays. just-git handles branch switches where a file differs only in mode.
*/
async function applyIndexModes(
fs: IFileSystem,
Expand Down
105 changes: 105 additions & 0 deletions src/api/tests/unit/git-command.regressions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { beforeEach, describe, expect, it } from "vitest";
import { type BashOverSqlFs, bashOverSqlFs } from "../../../sql-fs/tests/fixtures/bash-over-sqlfs.js";
import { createGitCommand } from "../../commands/git-command.js";

const IDENTITY = {
GIT_AUTHOR_NAME: "a",
GIT_AUTHOR_EMAIL: "a@b.c",
GIT_COMMITTER_NAME: "a",
GIT_COMMITTER_EMAIL: "a@b.c",
};

const SEED = [
"mkdir repo && cd repo && git init -q",
"printf 'echo ran\\n' > run.sh && chmod 755 run.sh",
"git add -A && git commit -q -m init",
"git checkout -q -b plain && chmod 644 run.sh && git commit -q -am plain && git checkout -q main",
].join(" && ");

describe("git wrapper with just-git 1.10 regressions", () => {
let env: BashOverSqlFs;

async function sh(script: string): Promise<{ stdout: string; stderr: string; exitCode: number }> {
const r = await env.bash.exec(script);
return { stdout: r.stdout, stderr: r.stderr, exitCode: r.exitCode };
}

beforeEach(async () => {
env = await bashOverSqlFs({ env: IDENTITY, customCommands: [createGitCommand({ network: false })] });
expect((await sh(SEED)).exitCode).toBe(0);
});

it("reports a chmod-only change in status and diff", async () => {
const r = await sh("cd repo && chmod 644 run.sh && git status --short && git diff");
expect(r).toEqual({
stdout: " M run.sh\ndiff --git a/run.sh b/run.sh\nold mode 100755\nnew mode 100644\n",
stderr: "",
exitCode: 0,
});
});

it("applies the mode when switching to a branch where only the mode differs", async () => {
expect((await sh("cd repo && stat -c %a run.sh")).stdout).toBe("755\n");
await sh("cd repo && git checkout -q plain");
expect((await sh("cd repo && stat -c %a run.sh && git status --short")).stdout).toBe("644\n");
await sh("cd repo && git checkout -q main");
expect((await sh("cd repo && stat -c %a run.sh && git status --short")).stdout).toBe("755\n");
});

it("refuses to switch over a local chmod-only change", async () => {
const r = await sh("cd repo && chmod 644 run.sh && git checkout plain");
expect(r.exitCode).toBe(1);
expect(r.stderr).toContain("Your local changes to the following files would be overwritten by checkout:");
expect((await sh("cd repo && git branch --show-current")).stdout).toBe("main\n");
});

it("lists a tree with git ls-tree", async () => {
expect(await sh("cd repo && git ls-tree --name-only plain && git ls-tree HEAD | cut -d' ' -f1-2")).toEqual({
stdout: "run.sh\n100755 blob\n",
stderr: "",
exitCode: 0,
});
});

it("recurses, filters by path and resolves <rev>:<path> in git ls-tree", async () => {
await sh(
"cd repo && mkdir -p src/lib && echo a > src/a && echo b > src/lib/b && git add src && git commit -q -m src",
);
const r = await sh(
"cd repo && git ls-tree --name-only HEAD && git ls-tree -r --name-only HEAD && " +
"git ls-tree --name-only HEAD src/lib && git ls-tree -r --name-only HEAD:src",
);
expect(r).toEqual({
stdout: "run.sh\nsrc\n" + "run.sh\nsrc/a\nsrc/lib/b\n" + "src/lib\n" + "a\nlib/b\n",
stderr: "",
exitCode: 0,
});
});

it("keeps a mode-only change from the merged branch", async () => {
await sh("cd repo && git checkout -q -b side plain && chmod 755 run.sh && git commit -q -am exec");
await sh("cd repo && git checkout -q plain && echo n > n && git add n && git commit -q -m n");
const r = await sh("cd repo && git merge -q -m mg side && git ls-files -s run.sh | cut -c1-6 && stat -c %a run.sh");
expect(r).toEqual({ stdout: "100755\n755\n", stderr: "", exitCode: 0 });
});

it("gives a conflicted file the merged mode", async () => {
await sh(
"cd repo && git checkout -q -b side plain && echo theirs > run.sh && chmod 755 run.sh && git commit -q -am t",
);
await sh("cd repo && git checkout -q plain && echo ours > run.sh && git commit -q -am o");
const r = await sh(
"cd repo && git merge -q side; echo rc=$?; git ls-files -s run.sh | cut -c1-6 && stat -c %a run.sh",
);
expect(r.stdout.split("\n").slice(-6)).toEqual(["rc=1", "100644", "100644", "100755", "755", ""]);
});

it("prints git show --summary", async () => {
await sh("cd repo && git mv run.sh go.sh && echo n > n && git add n && git commit -q -m sum");
expect(await sh("cd repo && git show --summary --format=%s HEAD")).toEqual({
stdout: "sum\n\n rename run.sh => go.sh (100%)\n create mode 100644 n\n",
stderr: "",
exitCode: 0,
});
});
});
Loading