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
4 changes: 4 additions & 0 deletions buck2-test-authority.json
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@
"src/cli/store.integration.test.ts",
"src/cli/sync.integration.test.ts",
"src/core/git-memory.integration.test.ts",
"src/core/git-reflog.integration.test.ts",
"src/core/git-streaming-parsers.integration.test.ts",
"src/core/git-timeout.integration.test.ts",
"src/core/nix-lock/mod.integration.test.ts",
Expand Down Expand Up @@ -887,6 +888,7 @@
"src/cli/worktree-lease.integration.test.ts",
"src/core/config.unit.test.ts",
"src/core/git-memory.integration.test.ts",
"src/core/git-reflog.integration.test.ts",
"src/core/git-streaming-parsers.integration.test.ts",
"src/core/git-timeout.integration.test.ts",
"src/core/git.unit.test.ts",
Expand Down Expand Up @@ -963,6 +965,7 @@
"src/cli/worktree-lease.integration.test.ts",
"src/core/config.unit.test.ts",
"src/core/git-memory.integration.test.ts",
"src/core/git-reflog.integration.test.ts",
"src/core/git-streaming-parsers.integration.test.ts",
"src/core/git-timeout.integration.test.ts",
"src/core/git.unit.test.ts",
Expand Down Expand Up @@ -1029,6 +1032,7 @@
"src/cli/store.integration.test.ts",
"src/cli/sync.integration.test.ts",
"src/core/git-memory.integration.test.ts",
"src/core/git-reflog.integration.test.ts",
"src/core/git-streaming-parsers.integration.test.ts",
"src/core/git-timeout.integration.test.ts",
"src/core/nix-lock/mod.integration.test.ts",
Expand Down
8 changes: 7 additions & 1 deletion packages/@overeng/megarepo/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ load("//buck2/products:defs.bzl", "javascript_product")
# Projection source: packages/@overeng/megarepo/BUCK.genie.ts
# Projection schema version: 13
# Projection generator: effect-utils/genie/buck2-typescript-package-projection
# Semantic fingerprint: sha256:467bfb4a75d4f8ac21b6c3a623362f1ec8c7f974b9f11a87f86cfc838408ae10
# Semantic fingerprint: sha256:95381df02a78d0cec2e092ec731bc6e403601754d9e15c051d16431cb568d5ab
# Regenerate: devenv tasks run genie:run

load("//buck2:materialization.bzl", "export_materialization_inputs", "package_view")
Expand Down Expand Up @@ -193,6 +193,7 @@ export_materialization_inputs([
"src/core/config.ts",
"src/core/config.unit.test.ts",
"src/core/git-memory.integration.test.ts",
"src/core/git-reflog.integration.test.ts",
"src/core/git-streaming-parsers.integration.test.ts",
"src/core/git-timeout.integration.test.ts",
"src/core/git.ts",
Expand Down Expand Up @@ -519,6 +520,7 @@ package_view(
"src/core/config.ts": "src/core/config.ts",
"src/core/config.unit.test.ts": "src/core/config.unit.test.ts",
"src/core/git-memory.integration.test.ts": "src/core/git-memory.integration.test.ts",
"src/core/git-reflog.integration.test.ts": "src/core/git-reflog.integration.test.ts",
"src/core/git-streaming-parsers.integration.test.ts": "src/core/git-streaming-parsers.integration.test.ts",
"src/core/git-timeout.integration.test.ts": "src/core/git-timeout.integration.test.ts",
"src/core/git.ts": "src/core/git.ts",
Expand Down Expand Up @@ -847,6 +849,7 @@ package_view(
"src/core/config.ts": "src/core/config.ts",
"src/core/config.unit.test.ts": "src/core/config.unit.test.ts",
"src/core/git-memory.integration.test.ts": "src/core/git-memory.integration.test.ts",
"src/core/git-reflog.integration.test.ts": "src/core/git-reflog.integration.test.ts",
"src/core/git-streaming-parsers.integration.test.ts": "src/core/git-streaming-parsers.integration.test.ts",
"src/core/git-timeout.integration.test.ts": "src/core/git-timeout.integration.test.ts",
"src/core/git.ts": "src/core/git.ts",
Expand Down Expand Up @@ -1170,6 +1173,7 @@ package_view(
"src/core/config.ts": "src/core/config.ts",
"src/core/config.unit.test.ts": "src/core/config.unit.test.ts",
"src/core/git-memory.integration.test.ts": "src/core/git-memory.integration.test.ts",
"src/core/git-reflog.integration.test.ts": "src/core/git-reflog.integration.test.ts",
"src/core/git-streaming-parsers.integration.test.ts": "src/core/git-streaming-parsers.integration.test.ts",
"src/core/git-timeout.integration.test.ts": "src/core/git-timeout.integration.test.ts",
"src/core/git.ts": "src/core/git.ts",
Expand Down Expand Up @@ -1385,6 +1389,7 @@ vitest_test(
"src/cli/store.integration.test.ts",
"src/cli/sync.integration.test.ts",
"src/core/git-memory.integration.test.ts",
"src/core/git-reflog.integration.test.ts",
"src/core/git-streaming-parsers.integration.test.ts",
"src/core/git-timeout.integration.test.ts",
"src/core/nix-lock/mod.integration.test.ts",
Expand Down Expand Up @@ -1433,6 +1438,7 @@ vitest_collect(
"src/cli/store.integration.test.ts",
"src/cli/sync.integration.test.ts",
"src/core/git-memory.integration.test.ts",
"src/core/git-reflog.integration.test.ts",
"src/core/git-streaming-parsers.integration.test.ts",
"src/core/git-timeout.integration.test.ts",
"src/core/nix-lock/mod.integration.test.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/@overeng/megarepo/BUCK.genie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const buck2TypeScriptAdmission = {
'src/cli/store.integration.test.ts',
'src/cli/sync.integration.test.ts',
'src/core/git-memory.integration.test.ts',
'src/core/git-reflog.integration.test.ts',
'src/core/git-streaming-parsers.integration.test.ts',
'src/core/git-timeout.integration.test.ts',
'src/core/nix-lock/mod.integration.test.ts',
Expand Down
4 changes: 4 additions & 0 deletions packages/@overeng/megarepo/docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Global repository cache at `~/.megarepo/` (configurable via `MEGAREPO_STORE`).

The store uses **bare repos with worktrees per ref**:

New bare stores set local `core.logAllRefUpdates=true` so branch updates leave
reflogs for last-touch and recovery evidence. Fetching an existing store enables
this setting before updating refs, preserving an existing `always` value.

```
~/.megarepo/
github.com/
Expand Down
93 changes: 93 additions & 0 deletions packages/@overeng/megarepo/src/core/git-reflog.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { NodeServices } from '@effect/platform-node'
import { describe, it } from '@effect/vitest'
import { Effect } from 'effect'
import * as FileSystem from 'effect/FileSystem'
import { expect } from 'vitest'

import * as Git from './git.ts'

process.env.GIT_CONFIG_GLOBAL = '/dev/null'
process.env.GIT_CONFIG_SYSTEM = '/dev/null'

const makeFixture = Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem
const root = yield* fs.makeTempDirectoryScoped()
const source = `${root}/source`
const bare = `${root}/store.git`
yield* fs.makeDirectory(source)
yield* Git.runCommand({ cwd: source, args: ['init', '-b', 'main'] })
yield* Git.runCommand({
cwd: source,
args: [
'-c',
'user.name=Test User',
'-c',
'user.email=test@example.com',
'-c',
'commit.gpgsign=false',
'commit',
'--allow-empty',
'-m',
'initial',
],
})
yield* Git.cloneBare({ url: source, targetPath: bare })
return { source, bare }
})

const readLogging = (repoPath: string) =>
Git.runCommand({
cwd: repoPath,
args: ['config', '--local', '--get', 'core.logAllRefUpdates'],
})

const expectFetchedReflog = (repoPath: string) =>
Effect.gen(function* () {
const commit = yield* Git.runCommand({ cwd: repoPath, args: ['rev-parse', 'main'] })
const reflog = yield* Git.runCommand({
cwd: repoPath,
args: ['reflog', 'show', '--format=%H', 'refs/remotes/origin/main'],
})
expect(reflog.split('\n')).toContain(commit)
})

describe('bare store reflogs', () => {
it.effect('enables reflogs on clone and records a later branch update', () =>
Effect.gen(function* () {
const { bare } = yield* makeFixture
expect(yield* readLogging(bare)).toBe('true')
yield* Git.fetchBare({ repoPath: bare })
yield* expectFetchedReflog(bare)
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
)

it.effect('enables missing local reflog configuration before fetching existing stores', () =>
Effect.gen(function* () {
const { bare } = yield* makeFixture
yield* Git.runCommand({
cwd: bare,
args: ['config', '--local', '--unset-all', 'core.logAllRefUpdates'],
})
yield* Git.fetchBare({ repoPath: bare })
expect(yield* readLogging(bare)).toBe('true')
yield* expectFetchedReflog(bare)
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
)

for (const value of ['false', 'always', 'ALWAYS']) {
it.effect(
`fetch ${value === 'false' ? 'enables disabled reflogs' : `preserves ${value}`}`,
() =>
Effect.gen(function* () {
const { bare } = yield* makeFixture
yield* Git.runCommand({
cwd: bare,
args: ['config', '--local', 'core.logAllRefUpdates', value],
})
yield* Git.fetchBare({ repoPath: bare })
expect(yield* readLogging(bare)).toBe(value === 'false' ? 'true' : value)
yield* expectFetchedReflog(bare)
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
)
}
})
27 changes: 27 additions & 0 deletions packages/@overeng/megarepo/src/core/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,28 @@ export const repairBareOriginFetchRefspec = ({ repoPath }: { repoPath: string })
}),
)

/** Enable store reflogs without weakening an existing `always` policy. Caller holds the writer lock. */
export const ensureBareRefLogging = Effect.fn('git/ensure-bare-ref-logging')(function* ({
repoPath,
}: {
repoPath: string
}) {
const value = yield* runGitCommand({
args: ['config', '--local', '--get', 'core.logAllRefUpdates'],
cwd: repoPath,
}).pipe(
Effect.catchTag('GitCommandError', (error) =>
error.exitCode === 1 && error.stderr === '' ? Effect.succeed('') : Effect.fail(error),
),
)
const normalized = value.toLowerCase()
if (normalized === 'true' || normalized === 'always') return
yield* runGitCommand({
args: ['config', '--local', 'core.logAllRefUpdates', 'true'],
cwd: repoPath,
})
})

/**
* Clone a repository as a bare repo.
* Configures fetch refspec so remote tracking refs are created on fetch.
Expand Down Expand Up @@ -929,6 +951,10 @@ export const cloneBare = (args: { url: string; targetPath: string }) => {
args: ['config', 'remote.origin.fetch', bareOriginFetchRefspec],
cwd: args.targetPath,
})
yield* runGitCommand({
args: ['config', '--local', 'core.logAllRefUpdates', 'true'],
cwd: args.targetPath,
})
return exists === false
}).pipe(
withGitWriterLock({ path: args.targetPath, create: true }),
Expand Down Expand Up @@ -959,6 +985,7 @@ export const fetchBare = (args: {
refs?: ReadonlyArray<string>
}) =>
Effect.gen(function* () {
yield* ensureBareRefLogging({ repoPath: args.repoPath })
const remote = args.remote ?? 'origin'
yield* runGitCommandWithRetry({
args: ['fetch', '--no-tags', '--prune', remote, bareOriginFetchRefspec],
Expand Down
5 changes: 4 additions & 1 deletion packages/@overeng/tui-stories/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ load("//buck2/products:defs.bzl", "javascript_product")
# Projection source: packages/@overeng/tui-stories/BUCK.genie.ts
# Projection schema version: 13
# Projection generator: effect-utils/genie/buck2-typescript-package-projection
# Semantic fingerprint: sha256:b93d0006b8d5a54a23a32e8c4de47701ff523f71c088bc9b0e0552f48e8f04c7
# Semantic fingerprint: sha256:ce22cb54526b18bc11014f2c33324601fcee76b158c2d84c92e5d79f8fbe9bbb
# Regenerate: devenv tasks run genie:run

load("//buck2:materialization.bzl", "export_materialization_inputs", "package_view")
Expand Down Expand Up @@ -315,6 +315,7 @@ package_view(
"node_modules/@overeng/megarepo/src/core/config.ts": "//packages/@overeng/megarepo:src/core/config.ts",
"node_modules/@overeng/megarepo/src/core/config.unit.test.ts": "//packages/@overeng/megarepo:src/core/config.unit.test.ts",
"node_modules/@overeng/megarepo/src/core/git-memory.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-memory.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git-reflog.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-reflog.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git-streaming-parsers.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-streaming-parsers.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git-timeout.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-timeout.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git.ts": "//packages/@overeng/megarepo:src/core/git.ts",
Expand Down Expand Up @@ -716,6 +717,7 @@ package_view(
"node_modules/@overeng/megarepo/src/core/config.ts": "//packages/@overeng/megarepo:src/core/config.ts",
"node_modules/@overeng/megarepo/src/core/config.unit.test.ts": "//packages/@overeng/megarepo:src/core/config.unit.test.ts",
"node_modules/@overeng/megarepo/src/core/git-memory.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-memory.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git-reflog.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-reflog.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git-streaming-parsers.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-streaming-parsers.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git-timeout.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-timeout.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git.ts": "//packages/@overeng/megarepo:src/core/git.ts",
Expand Down Expand Up @@ -1117,6 +1119,7 @@ package_view(
"node_modules/@overeng/megarepo/src/core/config.ts": "//packages/@overeng/megarepo:src/core/config.ts",
"node_modules/@overeng/megarepo/src/core/config.unit.test.ts": "//packages/@overeng/megarepo:src/core/config.unit.test.ts",
"node_modules/@overeng/megarepo/src/core/git-memory.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-memory.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git-reflog.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-reflog.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git-streaming-parsers.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-streaming-parsers.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git-timeout.integration.test.ts": "//packages/@overeng/megarepo:src/core/git-timeout.integration.test.ts",
"node_modules/@overeng/megarepo/src/core/git.ts": "//packages/@overeng/megarepo:src/core/git.ts",
Expand Down
Loading