Skip to content
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

fix(cli): Configure and enable a git-annex remote when downloading datasets #3283

Merged
merged 1 commit into from
Jan 16, 2025
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
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 @@

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 @@
})
}

/**
* 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 @@
{ 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 @@
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 @@
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
Loading