lalph 0.2.12 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +807 -1398
- package/package.json +1 -1
- package/src/Worktree.ts +24 -51
package/package.json
CHANGED
package/src/Worktree.ts
CHANGED
|
@@ -60,7 +60,6 @@ export class Worktree extends ServiceMap.Service<Worktree>()("lalph/Worktree", {
|
|
|
60
60
|
yield* setupWorktree({
|
|
61
61
|
directory,
|
|
62
62
|
exec: execHelpers.exec,
|
|
63
|
-
pathService,
|
|
64
63
|
})
|
|
65
64
|
|
|
66
65
|
return {
|
|
@@ -97,12 +96,10 @@ const seedSetupScript = Effect.fnUntraced(function* (setupPath: string) {
|
|
|
97
96
|
return
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
const baseBranch = yield* discoverBaseBranch
|
|
101
|
-
|
|
102
99
|
yield* fs.makeDirectory(pathService.dirname(setupPath), {
|
|
103
100
|
recursive: true,
|
|
104
101
|
})
|
|
105
|
-
yield* fs.writeFileString(setupPath, setupScriptTemplate
|
|
102
|
+
yield* fs.writeFileString(setupPath, setupScriptTemplate)
|
|
106
103
|
yield* fs.chmod(setupPath, 0o755)
|
|
107
104
|
})
|
|
108
105
|
|
|
@@ -112,14 +109,14 @@ const setupWorktree = Effect.fnUntraced(function* (options: {
|
|
|
112
109
|
template: TemplateStringsArray,
|
|
113
110
|
...args: Array<string | number | boolean>
|
|
114
111
|
) => Effect.Effect<ChildProcessSpawner.ExitCode, PlatformError.PlatformError>
|
|
115
|
-
readonly pathService: Path.Path
|
|
116
112
|
}) {
|
|
117
113
|
const fs = yield* FileSystem.FileSystem
|
|
114
|
+
const pathService = yield* Path.Path
|
|
118
115
|
const targetBranch = yield* getTargetBranch
|
|
119
|
-
const shouldUseWorktree = Option.isSome(targetBranch)
|
|
120
116
|
|
|
121
|
-
if (
|
|
117
|
+
if (Option.isSome(targetBranch)) {
|
|
122
118
|
const parsed = parseBranch(targetBranch.value)
|
|
119
|
+
yield* options.exec`git fetch ${parsed.remote}`
|
|
123
120
|
const code = yield* options.exec`git checkout ${parsed.branchWithRemote}`
|
|
124
121
|
if (code !== 0) {
|
|
125
122
|
yield* options.exec`git checkout -b ${parsed.branch}`
|
|
@@ -127,23 +124,24 @@ const setupWorktree = Effect.fnUntraced(function* (options: {
|
|
|
127
124
|
}
|
|
128
125
|
}
|
|
129
126
|
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
yield* seedSetupScript(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
127
|
+
const cwdSetupPath = pathService.resolve(".lalph", "worktree-setup.sh")
|
|
128
|
+
const worktreeSetupPath = pathService.join(
|
|
129
|
+
options.directory,
|
|
130
|
+
".lalph",
|
|
131
|
+
"worktree-setup.sh",
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
yield* seedSetupScript(cwdSetupPath)
|
|
135
|
+
|
|
136
|
+
// worktree setup script takes precedence
|
|
137
|
+
const setupPath = (yield* fs.exists(worktreeSetupPath))
|
|
138
|
+
? worktreeSetupPath
|
|
139
|
+
: cwdSetupPath
|
|
140
|
+
|
|
141
|
+
yield* ChildProcess.make({
|
|
142
|
+
cwd: options.directory,
|
|
143
|
+
shell: process.env.SHELL ?? true,
|
|
144
|
+
})`${setupPath}`.pipe(ChildProcess.exitCode)
|
|
147
145
|
})
|
|
148
146
|
|
|
149
147
|
const getTargetBranch = Effect.gen(function* () {
|
|
@@ -155,35 +153,10 @@ const getTargetBranch = Effect.gen(function* () {
|
|
|
155
153
|
return project.value.targetBranch
|
|
156
154
|
})
|
|
157
155
|
|
|
158
|
-
const
|
|
159
|
-
const originHead =
|
|
160
|
-
yield* ChildProcess.make`git symbolic-ref --short refs/remotes/origin/HEAD`.pipe(
|
|
161
|
-
ChildProcess.string,
|
|
162
|
-
Effect.catch((_) => Effect.succeed("")),
|
|
163
|
-
Effect.map((output) => output.trim()),
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
if (originHead !== "") {
|
|
167
|
-
return originHead.startsWith("origin/")
|
|
168
|
-
? originHead.slice("origin/".length)
|
|
169
|
-
: originHead
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const currentBranch =
|
|
173
|
-
yield* ChildProcess.make`git branch --show-current`.pipe(
|
|
174
|
-
ChildProcess.string,
|
|
175
|
-
Effect.catch((_) => Effect.succeed("")),
|
|
176
|
-
Effect.map((output) => output.trim()),
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
return currentBranch === "" ? "main" : currentBranch
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
const setupScriptTemplate = (baseBranch: string) => `#!/usr/bin/env bash
|
|
156
|
+
const setupScriptTemplate = `#!/usr/bin/env bash
|
|
183
157
|
set -euo pipefail
|
|
184
158
|
|
|
185
|
-
|
|
186
|
-
git checkout origin/${baseBranch}
|
|
159
|
+
pnpm install
|
|
187
160
|
|
|
188
161
|
# Seeded by lalph. Customize this to prepare new worktrees.
|
|
189
162
|
`
|