-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add file copying functionality when creating worktree (#16)
- Implement file copying feature for new worktree - Add configuration options for copyFiles and ignoreFiles - Update createWorktreeFromInfo function to include file copying - Create copyIgnoredFiles utility function
- Loading branch information
Showing
8 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as vscode from 'vscode'; | ||
import path from 'path'; | ||
import fs from 'fs/promises'; | ||
import { pipeline } from 'stream/promises'; | ||
import { createReadStream, createWriteStream } from 'fs'; | ||
import { Config } from '@/core/config/setting'; | ||
|
||
export async function copyWorktreeFiles(sourceRepo: string, targetWorktree: string) { | ||
try { | ||
const patterns = Config.get('worktreeCopyPatterns', []); | ||
const ignorePatterns = Config.get('worktreeCopyIgnores', []); | ||
|
||
if (patterns.length === 0) return; | ||
|
||
// Find matching files | ||
const files = await vscode.workspace.findFiles( | ||
new vscode.RelativePattern(sourceRepo, `{${patterns.join(',')}}`), | ||
`{${ignorePatterns.join(',')}}`, | ||
); | ||
|
||
// Copy the found files | ||
for (const file of files) { | ||
const relativePath = path.relative(sourceRepo, file.fsPath); | ||
const targetPath = path.join(targetWorktree, relativePath); | ||
const targetDir = path.dirname(targetPath); | ||
|
||
// Ensure target directory exists | ||
await fs.mkdir(targetDir, { recursive: true }); | ||
|
||
// Copy single file | ||
await pipeline( | ||
createReadStream(file.fsPath), | ||
createWriteStream(targetPath) | ||
); | ||
} | ||
} catch (error: any) { | ||
vscode.window.showErrorMessage(vscode.l10n.t('Failed to copy files: {error}', { error })); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters