Fix copy
Fix the copy command so that from-repository and from-repository-file works like they work with restic alone. That means
version: 2
profile:
repository: r1
...
copy:
from-repository: r2
...
copies from repository r2 to r1 and not in the opposite direction, like it does now. That means the repository mentioned directly below profile (r1) is the destination similar to backup. The special case without the "from"-prefix mention in the docs works like before.
As a bonus the retention section now allows to specify before-copy and after-copy analog to before-backup and after-backup.
Walkthrough
The CopySection struct in the configuration is refactored to explicitly separate source and destination repository fields, introducing From* and To* prefixes. Associated methods and flag-generation logic are updated to support this distinction and maintain compatibility with different restic versions. Corresponding tests are updated and extended to validate the new structure and logic.
Changes
| Cohort / File(s) | Change Summary |
|---|---|
CopySection Refactor and Logic Updateconfig/profile.go |
Refactored CopySection to use explicit From* (source) and To* (destination) fields. Updated methods (resolve, setRootPath, getInitFlags, getCommandFlags) to handle the new structure and restic version differences. Added IsCopyTo() method. |
Test Updates for CopySectionconfig/profile_test.go |
Updated tests to use new From* and To* fields. Rewrote and extended tests to validate flag generation for both source and destination configurations and for different restic versions. Added TestGetCopyToStructFields. |
Wrapper Test Field Name Updateswrapper_test.go |
Updated test struct field names in CopySection to match new To* destination naming in test setup. No changes to test logic or public interfaces. |
Estimated code review effort
๐ฏ 3 (Moderate) | โฑ๏ธ ~15โ20 minutes
Suggested labels
enhancement
[!NOTE]
โก๏ธ Unit Test Generation is now available in beta!
Learn more here, or try it out under "Finishing Touches" below.
๐ Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
๐ฅ Commits
Reviewing files that changed from the base of the PR and between c05217ba1089511c01e15d1526366e7e8aefa120 and dbd7da5a254c32aa03d68ca96acc9f2bc1917907.
๐ Files selected for processing (1)
-
config/profile.go(1 hunks)
๐งฐ Additional context used
๐งฌ Code Graph Analysis (1)
config/profile.go (5)
util/maybe/bool.go (1)
Bool(11-13)config/confidential.go (1)
ConfidentialValue(14-16)shell/args.go (1)
Args(11-14)constants/parameter.go (5)
ParameterRepository(23-23)ParameterRepositoryFile(24-24)ParameterPasswordFile(25-25)ParameterPasswordCommand(26-26)ParameterKeyHint(27-27)shell/arg.go (2)
NewArg(40-51)ArgConfigEscape(21-21)
โฐ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Build and test (1.24, ubuntu-latest)
- GitHub Check: Build and test (1.24, windows-latest)
- GitHub Check: Analyze (go)
๐ Additional comments (6)
config/profile.go (6)
347-363: Excellent refactoring of repository parameter separation.The explicit separation of source (
From*) and destination (To*) repository parameters provides clear semantic distinction and addresses the core issue mentioned in the PR objectives. The field descriptions are now accurate and consistent with their intended purpose.
367-367: Well-designed direction detection method.The
IsCopyTo()method provides a clear way to determine copy direction based on destination repository configuration, enabling proper branching logic in other methods.
369-377: Proper path normalization for both copy directions.The conditional logic correctly normalizes the appropriate repository path based on copy direction, addressing the previous issue where
FromRepositorywas not being normalized.
379-389: Consistent path handling across copy directions.The conditional path normalization follows the same logical pattern as the
resolvemethod, ensuring both copy directions properly handle file path resolution.
391-438: Complex but correct initialization logic for both copy directions.The method properly handles repository initialization for both copy directions. When copying to a destination, it initializes the destination repository and uses the profile's source repository for chunker parameters. When copying from a source, it uses the source repository from the copy section. The logic correctly respects the
InitializeCopyChunkerParamssetting.
440-503: Comprehensive flag generation supporting multiple restic versions and copy directions.The method correctly handles the complex requirements:
- Proper branching for copy-to vs copy-from scenarios
- Version-specific flag handling for restic < 0.14 (using
repo2style) vs >= 0.14 (usingfrom-prefixes)- Appropriate confidential repository handling for both directions
- Consistent flag building logic that aligns with the repository separation
The implementation addresses the core PR objective of ensuring consistent behavior with restic's native copy operations.
โจ Finishing Touches
- [ ] ๐ Generate Docstrings
๐งช Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
๐ชง Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Explain this complex logic. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai explain this code block. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and explain its main purpose. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai generate unit teststo generate unit tests for this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Codecov Report
:x: Patch coverage is 94.00000% with 6 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 79.39%. Comparing base (63dee21) to head (dbd7da5).
:warning: Report is 8 commits behind head on master.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| config/profile.go | 94.00% | 4 Missing and 2 partials :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #486 +/- ##
==========================================
+ Coverage 79.29% 79.39% +0.10%
==========================================
Files 136 137 +1
Lines 13264 13390 +126
==========================================
+ Hits 10517 10630 +113
- Misses 2326 2340 +14
+ Partials 421 420 -1
| Flag | Coverage ฮ | |
|---|---|---|
| unittests | 79.39% <94.00%> (+0.10%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Hey! how is it going with this PR?
Tell me if you need any help ๐๐ป
It's the part of before-copy and after-copy that's missing (The same for check-before and check-after). I have made already two tries I never pushed, because I don't like the resulting code.
copy with from-repository is already working. Maybe I shall make it ready for release and leave the before-copy/after-copy part for another PR.
If the first part of the PR is ready, you can definitely split it in two. Smaller PR always makes the code quicker to review ๐๐ป
Thanks for the change ๐๐ป
Actually I found something during testing: when the initialise: true flag is set, we're trying to initialise the target repository if it's not existing yet. Which makes sense in a way that it's going to be a copy of the current one.
While leaving the initialise: true flag using a from-repository it doesn't try to initialise the source repository. And it kind of make sense as well since we should be copying from an existing repository.
2025/07/30 18:17:59 profile 'self': initializing repository (if not existing)
2025/07/30 18:17:59 starting command: /usr/local/bin/restic init --password-file=examples/key --repo=/Volumes/RAMDisk/self --verbose=1
2025/07/30 18:17:59 profile 'self': initializing secondary repository (if not existing)
2025/07/30 18:17:59 starting command: /usr/local/bin/restic init --copy-chunker-params --from-password-file=examples/key --from-repo=/Volumes/RAMDisk/copy-from --password-file=examples/key --repo=/Volumes/RAMDisk/self --verbose=1
So we have two choices:
- we can disable trying to initialise the secondary (source) repository
- we can be sending the source repository to the secondary init to fix the initialisation step: it makes things consistent (but not very useful)
Any preference?
... which I realise is also opening yet another a can of worms ๐
In the order of initialisation, the source should be done first, then the target with the --copy-chunker-params flag so we'd need to change the order: right now the repository is done first, like any other step, then the one from the copy section ๐คฆ๐ป
It is important to initialize the target repository to be consistent with the backup section. This is useful for making copies to external drives and initialize them on first use. Nor forgetting to use --copy-chunker-params is important here.
I wouldn't bother with initializing a source drive. This is really an edge case. Possibly forgetting --copy-chunker-params doesn't count here, because there is no source repo for this, which makes sense.
Makes sense ๐ Right, I'll merge this first PR for now, thanks for the great work! ๐๐ป