Repository navigation
fix(server): worktree threads start when a checkout hook already linked a nested clone #40419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6a12622
2112d77
b154509
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,6 +243,16 @@ const make = Effect.gen(function* () { | |
| const exists = (target: string) => | ||
| fileSystem.exists(target).pipe(Effect.orElseSucceed(() => false)); | ||
| const isRepository = (folder: string) => exists(path.join(folder, ".git")); | ||
| const occupied = Effect.fnUntraced(function* (target: string) { | ||
| if (!(yield* exists(target))) return false; | ||
| const isDirectory = (yield* fileSystem.stat(target).pipe(Effect.option)).pipe( | ||
| Option.exists((info) => info.type === "Directory"), | ||
| ); | ||
| if (!isDirectory) return true; | ||
| return ( | ||
| (yield* fileSystem.readDirectory(target).pipe(Effect.orElseSucceed(() => [""]))).length > 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail repository creation when the existing destination cannot be read.
Keep the skip for readable, nonempty occupied directories. For an unreadable existing destination,
|
||
| ); | ||
| }); | ||
| const trackedFolders = (project: { | ||
| readonly workspaceRoot: string; | ||
| readonly trackedFolders: ReadonlyArray<ProjectTrackedFolder>; | ||
|
|
@@ -855,6 +865,13 @@ const make = Effect.gen(function* () { | |
| baseBranch: string | undefined, | ||
| ) { | ||
| const worktreePath = mapped(taskFolder, repository.path); | ||
| // The project's own checkout (a post-checkout hook, say) already provided this repository. | ||
| // A link counts even to an empty folder: Git would write the worktree through it. | ||
| if ( | ||
| Option.isSome(yield* fileSystem.readLink(worktreePath).pipe(Effect.option)) || | ||
| (yield* occupied(worktreePath)) | ||
| ) | ||
| return null; | ||
| yield* fileSystem.makeDirectory(path.dirname(worktreePath), { recursive: true }); | ||
| const start = yield* repositoryStart(repository.path, startFromOrigin, baseBranch); | ||
| yield* git.createWorktree({ | ||
|
|
@@ -1006,6 +1023,9 @@ const make = Effect.gen(function* () { | |
| } else { | ||
| yield* linkFolder(taskPlan.projectRoot, empty.projectPath, taskPlan.trackedRepositories); | ||
| } | ||
| let finished = 0; | ||
| // Whatever the project put at a skipped path also stands for the repositories inside it. | ||
| const skipped: string[] = []; | ||
| // A repository inside another waits for the one that holds it. | ||
| const levels = Map.groupBy( | ||
| taskPlan.repositories, | ||
|
|
@@ -1021,21 +1041,28 @@ const make = Effect.gen(function* () { | |
| const exits = yield* Effect.forEach( | ||
| levels.get(level)!, | ||
| (repository) => | ||
| createRepositoryWorktree( | ||
| empty, | ||
| repository, | ||
| branch, | ||
| input.startFromOrigin, | ||
| input.baseBranch, | ||
| (skipped.some((outer) => isWithinRoot(path, repository.path, outer)) | ||
| ? Effect.succeed(null) | ||
| : createRepositoryWorktree( | ||
| empty, | ||
| repository, | ||
| branch, | ||
| input.startFromOrigin, | ||
| input.baseBranch, | ||
| ) | ||
| ).pipe( | ||
| Effect.tap((worktree) => | ||
| Effect.suspend(() => { | ||
| created.push(worktree.repository); | ||
| repositoriesStartedFromOrigin ||= worktree.fromOrigin; | ||
| finished += 1; | ||
| if (worktree === null) skipped.push(repository.path); | ||
| else { | ||
| created.push(worktree.repository); | ||
| repositoriesStartedFromOrigin ||= worktree.fromOrigin; | ||
| } | ||
| return ( | ||
| input.onRepository?.({ | ||
| name: repository.name, | ||
| done: created.length, | ||
| done: finished, | ||
| total: taskPlan.repositories.length, | ||
| }) ?? Effect.void | ||
| ); | ||
|
|
@@ -1189,15 +1216,7 @@ const make = Effect.gen(function* () { | |
| path.relative(taskFolder.projectRoot, repositoryPath), | ||
| ).pipe(Effect.mapError(fail("add-repository", "Could not prepare the folder"))) | ||
| : true; | ||
| const occupied = | ||
| !opened || | ||
| ((yield* exists(worktreePath)) && | ||
| ((yield* fileSystem.stat(worktreePath).pipe(Effect.option)).pipe( | ||
| Option.exists((info) => info.type !== "Directory"), | ||
| ) || | ||
| (yield* fileSystem.readDirectory(worktreePath).pipe(Effect.orElseSucceed(() => [""]))) | ||
| .length > 0)); | ||
| if (occupied) | ||
| if (!opened || (yield* occupied(worktreePath))) | ||
| return yield* refuse(`${worktreePath} already holds files, so no worktree can go there.`); | ||
| // The link the worktree took the place of comes back when the worktree does not stay. | ||
| const relink = wasLinked | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.