Skip to content

Commit 8ce2032

Browse files
committed
fix(cli): Configure and enable a git-annex remote when downloading datasets
1 parent 794f576 commit 8ce2032

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

cli/src/commands/download.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ export async function downloadAction(
4444

4545
console.log("Downloading...")
4646

47+
// Clone main/master and git-annex branches
4748
worker.postMessage({
4849
"command": "clone",
4950
})
5051

52+
// Setup any git-annex remotes required for downloads
53+
worker.postMessage({
54+
"command": "remote-setup",
55+
})
56+
5157
// Close after all tasks are queued
5258
worker.postMessage({ command: "done" })
5359

cli/src/worker/git.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ async function createAnnexBranch() {
181181
})
182182
}
183183

184+
/**
185+
* Generate a commit for remote.log updates if needed
186+
*/
187+
async function remoteSetup() {
188+
const noAnnexKeys: Record<string, string> = {}
189+
await commitAnnexBranch(noAnnexKeys)
190+
}
191+
184192
/**
185193
* Generate one commit for all pending git-annex branch changes
186194
*/
@@ -225,7 +233,10 @@ async function commitAnnexBranch(annexKeys: Record<string, string>) {
225233
{ encoding: "utf8" },
226234
)
227235
} catch (_err) {
228-
if (_err instanceof Error && _err.name !== "NotFound") {
236+
// Continue if the error is remote.log is not found, otherwise throw it here
237+
if (
238+
!(_err instanceof Error && "code" in _err && _err.code === "ENOENT")
239+
) {
229240
throw _err
230241
}
231242
} finally {
@@ -269,11 +280,23 @@ async function commitAnnexBranch(annexKeys: Record<string, string>) {
269280
await git.add({ ...context.config(), filepath: annexBranchPath })
270281
}
271282
}
272-
await git.commit({
273-
...context.config(),
274-
message: "[OpenNeuro CLI] Added annexed objects",
275-
author: context.author,
276-
})
283+
// Show a better commit message for when only the remote is updated
284+
if (Object.keys(annexKeys).length === 0) {
285+
// Only generate a commit if needed
286+
if (!remoteLog.includes(uuid)) {
287+
await git.commit({
288+
...context.config(),
289+
message: "[OpenNeuro CLI] Configured remote",
290+
author: context.author,
291+
})
292+
}
293+
} else {
294+
await git.commit({
295+
...context.config(),
296+
message: "[OpenNeuro CLI] Added annexed objects",
297+
author: context.author,
298+
})
299+
}
277300
}
278301
} finally {
279302
try {
@@ -437,6 +460,8 @@ self.onmessage = (event: GitWorkerEvent) => {
437460
workQueue.enqueue(commit)
438461
} else if (event.data.command === "push") {
439462
workQueue.enqueue(push)
463+
} else if (event.data.command === "remote-setup") {
464+
workQueue.enqueue(remoteSetup)
440465
} else if (event.data.command === "done") {
441466
workQueue.enqueue(done)
442467
}

0 commit comments

Comments
 (0)