Skip to content

Commit 5e59e36

Browse files
nrjdalalclaude
andcommitted
fix: error on missing source with explicit target, preserve symlinks in copy
- gitpick -i missing-dir out now errors instead of silently rewriting - Individual symlink selection preserves the symlink instead of dereferencing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2a0fe7f commit 5e59e36

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

bin/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,14 @@ const main = async () => {
178178
!url.startsWith("git@"))
179179

180180
if (isLocalPath && options.interactive) {
181-
// If url doesn't look like a real path, it's the target (e.g. `gitpick -i hello`)
181+
// Single positional that doesn't exist — treat as target (e.g. `gitpick -i hello`)
182+
// Only when no explicit target is given; with two args, a missing source is an error
182183
if (
183184
!fs.existsSync(path.resolve(url.startsWith("~/") ? url.replace("~", os.homedir()) : url))
184185
) {
186+
if (target) {
187+
throw new Error(`Directory not found: ${url}`)
188+
}
185189
target = url
186190
url = "."
187191
}
@@ -347,15 +351,19 @@ const main = async () => {
347351
for (const sel of selected) {
348352
const src = path.join(resolvedSource, sel)
349353
const dest = path.join(targetDir, sel)
350-
const stat = await fs.promises.stat(src).catch(() => null)
351-
if (!stat) continue
354+
const lstat = await fs.promises.lstat(src).catch(() => null)
355+
if (!lstat) continue
352356

353-
if (stat.isDirectory()) {
357+
await fs.promises.mkdir(path.dirname(dest), { recursive: true })
358+
if (lstat.isSymbolicLink()) {
359+
const linkTarget = await fs.promises.readlink(src)
360+
await fs.promises.symlink(linkTarget, dest).catch(() => {})
361+
copiedFiles++
362+
} else if (lstat.isDirectory()) {
354363
await fs.promises.mkdir(dest, { recursive: true })
355364
const files = await copyDir(src, dest)
356365
copiedFiles += files.length
357366
} else {
358-
await fs.promises.mkdir(path.dirname(dest), { recursive: true })
359367
await fs.promises.copyFile(src, dest)
360368
copiedFiles++
361369
}

0 commit comments

Comments
 (0)