Skip to content

Commit

Permalink
fix(cli): Configure and enable a git-annex remote when downloading da…
Browse files Browse the repository at this point in the history
…tasets
  • Loading branch information
nellh committed Jan 15, 2025
1 parent 794f576 commit 8ce2032
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
6 changes: 6 additions & 0 deletions cli/src/commands/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ export async function downloadAction(

console.log("Downloading...")

// Clone main/master and git-annex branches

Check warning on line 47 in cli/src/commands/download.ts

View check run for this annotation

Codecov / codecov/patch

cli/src/commands/download.ts#L47

Added line #L47 was not covered by tests
worker.postMessage({
"command": "clone",
})

// Setup any git-annex remotes required for downloads
worker.postMessage({
"command": "remote-setup",
})

Check warning on line 56 in cli/src/commands/download.ts

View check run for this annotation

Codecov / codecov/patch

cli/src/commands/download.ts#L52-L56

Added lines #L52 - L56 were not covered by tests
// Close after all tasks are queued
worker.postMessage({ command: "done" })

Expand Down
37 changes: 31 additions & 6 deletions cli/src/worker/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ async function createAnnexBranch() {
})
}

/**
* Generate a commit for remote.log updates if needed
*/
async function remoteSetup() {
const noAnnexKeys: Record<string, string> = {}
await commitAnnexBranch(noAnnexKeys)
}

Check warning on line 191 in cli/src/worker/git.ts

View check run for this annotation

Codecov / codecov/patch

cli/src/worker/git.ts#L184-L191

Added lines #L184 - L191 were not covered by tests
/**
* Generate one commit for all pending git-annex branch changes
*/
Expand Down Expand Up @@ -225,7 +233,10 @@ async function commitAnnexBranch(annexKeys: Record<string, string>) {
{ encoding: "utf8" },
)
} catch (_err) {
if (_err instanceof Error && _err.name !== "NotFound") {
// Continue if the error is remote.log is not found, otherwise throw it here
if (
!(_err instanceof Error && "code" in _err && _err.code === "ENOENT")
) {

Check warning on line 239 in cli/src/worker/git.ts

View check run for this annotation

Codecov / codecov/patch

cli/src/worker/git.ts#L236-L239

Added lines #L236 - L239 were not covered by tests
throw _err
}
} finally {
Expand Down Expand Up @@ -269,11 +280,23 @@ async function commitAnnexBranch(annexKeys: Record<string, string>) {
await git.add({ ...context.config(), filepath: annexBranchPath })
}
}
await git.commit({
...context.config(),
message: "[OpenNeuro CLI] Added annexed objects",
author: context.author,
})
// Show a better commit message for when only the remote is updated
if (Object.keys(annexKeys).length === 0) {
// Only generate a commit if needed
if (!remoteLog.includes(uuid)) {
await git.commit({
...context.config(),
message: "[OpenNeuro CLI] Configured remote",
author: context.author,
})
}
} else {
await git.commit({
...context.config(),
message: "[OpenNeuro CLI] Added annexed objects",
author: context.author,
})
}

Check warning on line 299 in cli/src/worker/git.ts

View check run for this annotation

Codecov / codecov/patch

cli/src/worker/git.ts#L283-L299

Added lines #L283 - L299 were not covered by tests
}
} finally {
try {
Expand Down Expand Up @@ -437,6 +460,8 @@ self.onmessage = (event: GitWorkerEvent) => {
workQueue.enqueue(commit)
} else if (event.data.command === "push") {
workQueue.enqueue(push)
} else if (event.data.command === "remote-setup") {
workQueue.enqueue(remoteSetup)

Check warning on line 464 in cli/src/worker/git.ts

View check run for this annotation

Codecov / codecov/patch

cli/src/worker/git.ts#L463-L464

Added lines #L463 - L464 were not covered by tests
} else if (event.data.command === "done") {
workQueue.enqueue(done)
}
Expand Down

0 comments on commit 8ce2032

Please sign in to comment.