Skip to content

Comments

fix: print warning to stderr when file copy fails during worktree creation#142

Merged
k1LoW merged 1 commit intomainfrom
copy-warn
Feb 15, 2026
Merged

fix: print warning to stderr when file copy fails during worktree creation#142
k1LoW merged 1 commit intomainfrom
copy-warn

Conversation

@k1LoW
Copy link
Owner

@k1LoW k1LoW commented Feb 15, 2026

This pull request enhances the file copying process when creating new Git worktrees by adding support for reporting warnings about files that fail to copy. The main change is the addition of a warn parameter to the CopyFilesToWorktree function, allowing warnings to be written to a specified writer (such as os.Stderr). The tests and worktree creation logic are updated to accommodate this new parameter.

Enhancements to file copying and error reporting:

  • Added an optional warn io.Writer parameter to the CopyFilesToWorktree function in internal/git/copy.go, enabling warnings about failed file copies to be written to the provided writer.
  • Updated the file copying loop in CopyFilesToWorktree to print a warning message when a file fails to copy, if warn is non-nil.

Integration with worktree creation:

  • Modified AddWorktree and AddWorktreeWithNewBranch in internal/git/worktree.go to pass os.Stderr as the warning writer, so warnings are shown to users during worktree creation. [1] [2]

@github-actions
Copy link
Contributor

Code Metrics Report

main (325aac1) #142 (c55bf23) +/-
Coverage 35.9% 35.9% -0.1%
Code to Test Ratio 1:2.1 1:2.1 -0.1
Test Execution Time 15s 15s 0s
Details
  |                     | main (325aac1) | #142 (c55bf23) |  +/-  |
  |---------------------|----------------|----------------|-------|
- | Coverage            |          35.9% |          35.9% | -0.1% |
  |   Files             |             13 |             13 |     0 |
  |   Lines             |           1039 |           1041 |    +2 |
  |   Covered           |            374 |            374 |     0 |
- | Code to Test Ratio  |          1:2.1 |          1:2.1 |  -0.1 |
  |   Code              |           2260 |           2265 |    +5 |
  |   Test              |           4941 |           4941 |     0 |
  | Test Execution Time |            15s |            15s |    0s |

Code coverage of files in pull request scope (66.9% → 66.4%)

Files Coverage +/- Status
internal/git/copy.go 84.3% -1.7% modified
internal/git/worktree.go 54.5% 0.0% modified

Reported by octocov

@k1LoW k1LoW marked this pull request as ready for review February 15, 2026 12:54
@k1LoW k1LoW merged commit 84b5758 into main Feb 15, 2026
7 checks passed
@k1LoW k1LoW deleted the copy-warn branch February 15, 2026 12:55
@github-actions github-actions bot mentioned this pull request Feb 15, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds warning functionality to the file copying process during Git worktree creation. When a file fails to copy (e.g., due to permission issues), a warning message is now written to stderr instead of silently skipping the file. The implementation adds an optional io.Writer parameter to CopyFilesToWorktree that allows callers to specify where warnings should be written.

Changes:

  • Added warn io.Writer parameter to CopyFilesToWorktree function to enable warning output when file copies fail
  • Updated AddWorktree and AddWorktreeWithNewBranch to pass os.Stderr as the warning writer
  • Updated all test calls to pass nil as the warning writer parameter

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
internal/git/copy.go Added warn io.Writer parameter to CopyFilesToWorktree and implemented warning output when file copy fails
internal/git/worktree.go Updated AddWorktree and AddWorktreeWithNewBranch to pass os.Stderr for warning output
internal/git/copy_test.go Updated all test calls to CopyFilesToWorktree to include the new warn parameter (set to nil in tests)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// CopyFilesToWorktree copies files to the new worktree based on options.
func CopyFilesToWorktree(ctx context.Context, srcRoot, dstRoot string, opts CopyOptions) error {
// If w is non-nil, warnings about files that fail to copy are written to it.
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation comment refers to the parameter as "w", but the actual parameter name is "warn". The documentation should be updated to match the parameter name for consistency and clarity.

Suggested change
// If w is non-nil, warnings about files that fail to copy are written to it.
// If warn is non-nil, warnings about files that fail to copy are written to it.

Copilot uses AI. Check for mistakes.
Comment on lines +108 to +110
if warn != nil {
fmt.Fprintf(warn, "warning: failed to copy %s: %v\n", file, err)
}
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new warning functionality introduced by the warn parameter lacks test coverage. Consider adding a test that verifies warnings are correctly written when file copy operations fail. This would help ensure the feature works as intended and prevent regressions.

Copilot uses AI. Check for mistakes.
// CopyFilesToWorktree copies files to the new worktree based on options.
func CopyFilesToWorktree(ctx context.Context, srcRoot, dstRoot string, opts CopyOptions) error {
// If w is non-nil, warnings about files that fail to copy are written to it.
func CopyFilesToWorktree(ctx context.Context, srcRoot, dstRoot string, opts CopyOptions, warn io.Writer) error {
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name 'warn' is inconsistent with the established convention in this codebase. In hook.go:14, the io.Writer parameter is named 'w', which is also a common Go idiom. Consider renaming this parameter from 'warn' to 'w' for consistency with the existing codebase conventions.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant