MCPcopy Create free account
hub / github.com/dailydotdev/apps / copyWorktreeFiles

Function copyWorktreeFiles

scripts/copy-worktree-files.js:22–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20process.exit(0);
21
22function copyWorktreeFiles() {
23 const gitDir = tryGit(['rev-parse', '--path-format=absolute', '--git-dir']);
24 const commonDir = tryGit([
25 'rev-parse',
26 '--path-format=absolute',
27 '--git-common-dir',
28 ]);
29
30 if (!gitDir || !commonDir || gitDir === commonDir) {
31 return;
32 }
33
34 const worktreeRoot = tryGit(['rev-parse', '--show-toplevel']);
35 const mainRoot = getMainCheckoutRoot();
36
37 if (!worktreeRoot || !mainRoot || worktreeRoot === mainRoot) {
38 return;
39 }
40
41 // Falls back to the list beside this script when it runs by path against an
42 // older worktree that predates .worktreeinclude.
43 const includeFile = [worktreeRoot, path.resolve(__dirname, '..')]
44 .map((dir) => path.join(dir, '.worktreeinclude'))
45 .find((file) => fs.existsSync(file));
46
47 if (!includeFile) {
48 return;
49 }
50
51 fs.readFileSync(includeFile, 'utf8')
52 .split('\n')
53 .map((line) => line.trim())
54 .filter((line) => line && !line.startsWith('#'))
55 .forEach((entry) => {
56 const relativePath = entry.replace(/\/+$/, '');
57 const source = path.join(mainRoot, relativePath);
58 const destination = path.join(worktreeRoot, relativePath);
59
60 if (
61 !fs.existsSync(source) ||
62 fs.existsSync(destination) ||
63 !isIgnored(entry, mainRoot)
64 ) {
65 return;
66 }
67
68 fs.mkdirSync(path.dirname(destination), { recursive: true });
69 fs.cpSync(source, destination, { recursive: true });
70 console.log(
71 `copy-worktree-files: copied ${entry} from the main checkout`,
72 );
73 });
74}
75
76function getMainCheckoutRoot() {
77 const mainWorktree = tryGit(['worktree', 'list', '--porcelain'])

Callers 1

Calls 4

tryGitFunction · 0.85
getMainCheckoutRootFunction · 0.85
replaceMethod · 0.80
isIgnoredFunction · 0.70

Tested by

no test coverage detected