Skip to content

Commit 8531590

Browse files
authored
Fixes #1412. Allow spaces in paths (#1424)
1 parent e0c4108 commit 8531590

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

src/nimblepkg/download.nim

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ type
1717

1818
proc updateSubmodules(dir: string) =
1919
discard tryDoCmdEx(
20-
&"git -C {dir} submodule update --init --recursive --depth 1")
20+
&"git -C {dir.quoteShell} submodule update --init --recursive --depth 1")
2121

2222
proc doCheckout*(meth: DownloadMethod, downloadDir, branch: string, options: Options) =
2323
case meth
2424
of DownloadMethod.git:
2525
# Force is used here because local changes may appear straight after a clone
2626
# has happened. Like in the case of git on Windows where it messes up the
2727
# damn line endings.
28-
discard tryDoCmdEx(&"git -C {downloadDir} checkout --force {branch}")
28+
discard tryDoCmdEx(&"git -C {downloadDir.quoteShell} checkout --force {branch}")
2929
if not options.ignoreSubmodules:
3030
downloadDir.updateSubmodules
3131
of DownloadMethod.hg:
32-
discard tryDoCmdEx(&"hg --cwd {downloadDir} checkout {branch}")
32+
discard tryDoCmdEx(&"hg --cwd {downloadDir.quoteShell} checkout {branch}")
3333

3434
proc doClone(meth: DownloadMethod, url, downloadDir: string, branch = "",
3535
onlyTip = true, options: Options) =
@@ -41,14 +41,14 @@ proc doClone(meth: DownloadMethod, url, downloadDir: string, branch = "",
4141
branchArg = if branch == "": "" else: &"-b {branch}"
4242
discard tryDoCmdEx(
4343
"git clone --config core.autocrlf=false --config core.eol=lf " &
44-
&"{submoduleFlag} {depthArg} {branchArg} {url} {downloadDir}")
44+
&"{submoduleFlag} {depthArg} {branchArg} {url} {downloadDir.quoteShell}")
4545
if not options.ignoreSubmodules:
4646
downloadDir.updateSubmodules
4747
of DownloadMethod.hg:
4848
let
4949
tipArg = if onlyTip: "-r tip " else: ""
5050
branchArg = if branch == "": "" else: &"-b {branch}"
51-
discard tryDoCmdEx(&"hg clone {tipArg} {branchArg} {url} {downloadDir}")
51+
discard tryDoCmdEx(&"hg clone {tipArg} {branchArg} {url} {downloadDir.quoteShell}")
5252

5353
proc gitFetchTags*(repoDir: string, downloadMethod: DownloadMethod, options: Options) =
5454
case downloadMethod:
@@ -157,12 +157,12 @@ proc cloneSpecificRevision(downloadMethod: DownloadMethod,
157157
of DownloadMethod.git:
158158
let downloadDir = downloadDir.quoteShell
159159
createDir(downloadDir)
160-
discard tryDoCmdEx(&"git -C {downloadDir} init")
161-
discard tryDoCmdEx(&"git -C {downloadDir} config core.autocrlf false")
162-
discard tryDoCmdEx(&"git -C {downloadDir} remote add origin {url}")
160+
discard tryDoCmdEx(&"git -C {downloadDir.quoteShell} init")
161+
discard tryDoCmdEx(&"git -C {downloadDir.quoteShell} config core.autocrlf false")
162+
discard tryDoCmdEx(&"git -C {downloadDir.quoteShell} remote add origin {url}")
163163
discard tryDoCmdEx(
164-
&"git -C {downloadDir} fetch --depth 1 origin {vcsRevision}")
165-
discard tryDoCmdEx(&"git -C {downloadDir} reset --hard FETCH_HEAD")
164+
&"git -C {downloadDir.quoteShell} fetch --depth 1 origin {vcsRevision}")
165+
discard tryDoCmdEx(&"git -C {downloadDir.quoteShell} reset --hard FETCH_HEAD")
166166
if not options.ignoreSubmodules:
167167
downloadDir.updateSubmodules
168168
of DownloadMethod.hg:
@@ -296,10 +296,10 @@ proc getTarCmdLine(downloadDir, filePath: string): string =
296296
when defined(Windows):
297297
let downloadDir = downloadDir.replace('\\', '/')
298298
let filePath = filePath.replace('\\', '/')
299-
&"{getTarExePath()} -C {downloadDir} -xf {filePath} --strip-components 1 " &
299+
&"{getTarExePath()} -C {downloadDir.quoteShell} -xf {filePath} --strip-components 1 " &
300300
"--force-local"
301301
else:
302-
&"tar -C {downloadDir} -xf {filePath} --strip-components 1"
302+
&"tar -C {downloadDir.quoteShell} -xf {filePath} --strip-components 1"
303303

304304
proc doDownloadTarball(url, downloadDir, version: string, queryRevision: bool):
305305
Sha1Hash =

src/nimblepkg/publish.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ proc vcsFindCommits*(repoDir, nimbleFile: string, downloadMethod: DownloadMethod
252252
var output: string
253253
case downloadMethod:
254254
of DownloadMethod.git:
255-
output = tryDoCmdEx(&"git -C {repoDir} log --format=\"%H %s\" -- $2")
255+
output = tryDoCmdEx(&"git -C {repoDir.quoteShell} log --format=\"%H %s\" -- $2")
256256
of DownloadMethod.hg:
257257
assert false, "hg not supported"
258258

@@ -264,7 +264,7 @@ proc vcsFindCommits*(repoDir, nimbleFile: string, downloadMethod: DownloadMethod
264264
proc vcsDiff*(commit: Sha1Hash, repoDir, nimbleFile: string, downloadMethod: DownloadMethod): seq[string] =
265265
case downloadMethod:
266266
of DownloadMethod.git:
267-
let (output, exitCode) = doCmdEx(&"git -C {repoDir} diff {commit}~ {commit} {nimbleFile}")
267+
let (output, exitCode) = doCmdEx(&"git -C {repoDir.quoteShell} diff {commit}~ {commit} {nimbleFile}")
268268
if exitCode != QuitSuccess:
269269
return @[]
270270
else:
@@ -275,7 +275,7 @@ proc vcsDiff*(commit: Sha1Hash, repoDir, nimbleFile: string, downloadMethod: Dow
275275
proc createTag*(tag: string, commit: Sha1Hash, message, repoDir, nimbleFile: string, downloadMethod: DownloadMethod): bool =
276276
case downloadMethod:
277277
of DownloadMethod.git:
278-
let (output, code) = doCmdEx(&"git -C {repoDir} tag -a {tag.quoteShell()} {commit} -m {message.quoteShell()}")
278+
let (output, code) = doCmdEx(&"git -C {repoDir.quoteShell} tag -a {tag.quoteShell()} {commit} -m {message.quoteShell()}")
279279
result = code == QuitSuccess
280280
if not result:
281281
displayError(&"Failed to create tag {tag.quoteShell()} with error {output}")

tests/tissues.nim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,14 @@ suite "issues":
414414
check exitCode == QuitSuccess
415415
check output.contains(message)
416416
removeDir("testDir-1251")
417+
418+
test "issue #1412. Should be able to install packages in a nimbleDir with spaces in the path":
419+
cd "gitversions":
420+
when defined(windows):
421+
createDir("nimbledir spaces")
422+
let (_, exitCode) = execNimble("install", "results", "--nimbleDir:nimbledir spaces")
423+
check exitCode == QuitSuccess
424+
removeDir("nimbledir spaces")
425+
else:
426+
discard
417427

0 commit comments

Comments
 (0)